Skip to content

Commit

Permalink
Merge branch 'master' into pr/api-integ-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jan 22, 2021
2 parents c403017 + f9b6750 commit f669f85
Show file tree
Hide file tree
Showing 41 changed files with 585 additions and 133 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/app-delivery/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@aws-cdk/app-delivery",
"description": "Continuous Integration / Continuous Delivery for CDK Applications",
"deprecated": "Use the @aws-cdk/pipelines module instead",
"version": "0.0.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront-origins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
"aws-sdk": "^2.828.0",
"aws-sdk": "^2.830.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"pkglint": "0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"aws-sdk": "^2.828.0",
"aws-sdk": "^2.830.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudtrail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"aws-sdk": "^2.828.0",
"aws-sdk": "^2.830.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codebuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@aws-cdk/aws-sns": "0.0.0",
"@aws-cdk/aws-sqs": "0.0.0",
"@types/nodeunit": "^0.0.31",
"aws-sdk": "^2.828.0",
"aws-sdk": "^2.830.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codecommit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-sns": "0.0.0",
"@types/nodeunit": "^0.0.31",
"aws-sdk": "^2.828.0",
"aws-sdk": "^2.830.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-codepipeline-actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ const sourceAction = new codepipeline_actions.CodeCommitSourceAction({
});
```

If you want to clone the entire CodeCommit repository (only available for CodeBuild actions),
you can set the `codeBuildCloneOutput` property to `true`:

```ts
const sourceOutput = new codepipeline.Artifact();
const sourceAction = new codepipeline_actions.CodeCommitSourceAction({
actionName: 'CodeCommit',
repository: repo,
output: sourceOutput,
codeBuildCloneOutput: true,
});

const buildAction = new codepipeline_actions.CodeBuildAction({
actionName: 'CodeBuild',
project,
input: sourceOutput, // The build action must use the CodeCommitSourceAction output as input.
outputs: [new codepipeline.Artifact()], // optional
});
```

The CodeCommit source action emits variables:

```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as iam from '@aws-cdk/aws-iam';
import * as cdk from '@aws-cdk/core';
import { BitBucketSourceAction } from '..';
import { Action } from '../action';
import { CodeCommitSourceAction } from '../codecommit/source-action';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
Expand Down Expand Up @@ -176,17 +177,28 @@ export class CodeBuildAction extends Action {
});
}

// if any of the inputs come from the BitBucketSourceAction
// with codeBuildCloneOutput=true,
// grant the Project's Role to use the connection
for (const inputArtifact of this.actionProperties.inputs || []) {
// if any of the inputs come from the BitBucketSourceAction
// with codeBuildCloneOutput=true,
// grant the Project's Role to use the connection
const connectionArn = inputArtifact.getMetadata(BitBucketSourceAction._CONNECTION_ARN_PROPERTY);
if (connectionArn) {
this.props.project.addToRolePolicy(new iam.PolicyStatement({
actions: ['codestar-connections:UseConnection'],
resources: [connectionArn],
}));
}

// if any of the inputs come from the CodeCommitSourceAction
// with codeBuildCloneOutput=true,
// grant the Project's Role git pull access to the repository
const codecommitRepositoryArn = inputArtifact.getMetadata(CodeCommitSourceAction._FULL_CLONE_ARN_PROPERTY);
if (codecommitRepositoryArn) {
this.props.project.addToRolePolicy(new iam.PolicyStatement({
actions: ['codecommit:GitPull'],
resources: [codecommitRepositoryArn],
}));
}
}

const configuration: any = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,33 @@ export interface CodeCommitSourceActionProps extends codepipeline.CommonAwsActio
* @default a new role will be created.
*/
readonly eventRole?: iam.IRole;

/**
* Whether the output should be the contents of the repository
* (which is the default),
* or a link that allows CodeBuild to clone the repository before building.
*
* **Note**: if this option is true,
* then only CodeBuild actions can use the resulting {@link output}.
*
* @default false
* @see https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-CodeCommit.html
*/
readonly codeBuildCloneOutput?: boolean;
}

/**
* CodePipeline Source that is provided by an AWS CodeCommit repository.
*/
export class CodeCommitSourceAction extends Action {
/**
* The name of the property that holds the ARN of the CodeCommit Repository
* inside of the CodePipeline Artifact's metadata.
*
* @internal
*/
public static readonly _FULL_CLONE_ARN_PROPERTY = 'CodeCommitCloneRepositoryArn';

private readonly branch: string;
private readonly props: CodeCommitSourceActionProps;

Expand All @@ -100,6 +121,10 @@ export class CodeCommitSourceAction extends Action {
throw new Error("'branch' parameter cannot be an empty string");
}

if (props.codeBuildCloneOutput === true) {
props.output.setMetadata(CodeCommitSourceAction._FULL_CLONE_ARN_PROPERTY, props.repository.repositoryArn);
}

super({
...props,
resource: props.repository,
Expand Down Expand Up @@ -144,14 +169,15 @@ export class CodeCommitSourceAction extends Action {
options.bucket.grantReadWrite(options.role);

// https://docs.aws.amazon.com/codecommit/latest/userguide/auth-and-access-control-permissions-reference.html#aa-acp
options.role.addToPolicy(new iam.PolicyStatement({
options.role.addToPrincipalPolicy(new iam.PolicyStatement({
resources: [this.props.repository.repositoryArn],
actions: [
'codecommit:GetBranch',
'codecommit:GetCommit',
'codecommit:UploadArchive',
'codecommit:GetUploadArchiveStatus',
'codecommit:CancelUploadArchive',
...(this.props.codeBuildCloneOutput === true ? ['codecommit:GetRepository'] : []),
],
}));

Expand All @@ -160,6 +186,9 @@ export class CodeCommitSourceAction extends Action {
RepositoryName: this.props.repository.repositoryName,
BranchName: this.branch,
PollForSourceChanges: this.props.trigger === CodeCommitTrigger.POLL,
OutputArtifactFormat: this.props.codeBuildCloneOutput === true
? 'CODEBUILD_CLONE_REF'
: undefined,
},
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { countResources, expect, haveResourceLike, not } from '@aws-cdk/assert';
import { arrayWith, countResources, expect, haveResourceLike, not, objectLike } from '@aws-cdk/assert';
import * as codebuild from '@aws-cdk/aws-codebuild';
import * as codecommit from '@aws-cdk/aws-codecommit';
import * as codepipeline from '@aws-cdk/aws-codepipeline';
Expand Down Expand Up @@ -269,6 +269,111 @@ export = {
test.done();
},

'allows to enable full clone'(test: Test) {
const stack = new Stack();

const sourceOutput = new codepipeline.Artifact();
new codepipeline.Pipeline(stack, 'P', {
stages: [
{
stageName: 'Source',
actions: [
new cpactions.CodeCommitSourceAction({
actionName: 'CodeCommit',
repository: new codecommit.Repository(stack, 'R', {
repositoryName: 'repository',
}),
branch: Lazy.string({ produce: () => 'my-branch' }),
output: sourceOutput,
codeBuildCloneOutput: true,
}),
],
},
{
stageName: 'Build',
actions: [
new cpactions.CodeBuildAction({
actionName: 'Build',
project: new codebuild.PipelineProject(stack, 'CodeBuild'),
input: sourceOutput,
}),
],
},
],
});

expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', {
'Stages': [
{
'Name': 'Source',
'Actions': [{
'Configuration': {
'OutputArtifactFormat': 'CODEBUILD_CLONE_REF',
},
}],
},
{
'Name': 'Build',
'Actions': [
{
'Name': 'Build',
},
],
},
],
}));

expect(stack).to(haveResourceLike('AWS::IAM::Policy', {
'PolicyDocument': {
'Statement': arrayWith(
objectLike({
'Action': [
'logs:CreateLogGroup',
'logs:CreateLogStream',
'logs:PutLogEvents',
],
}),
objectLike({
'Action': 'codecommit:GitPull',
'Effect': 'Allow',
'Resource': {
'Fn::GetAtt': [
'RC21A1702',
'Arn',
],
},
}),
),
},
}));

expect(stack).to(haveResourceLike('AWS::IAM::Policy', {
'PolicyDocument': {
'Statement': arrayWith(
objectLike({
'Action': [
'codecommit:GetBranch',
'codecommit:GetCommit',
'codecommit:UploadArchive',
'codecommit:GetUploadArchiveStatus',
'codecommit:CancelUploadArchive',
'codecommit:GetRepository',
],
'Effect': 'Allow',
'Resource': {
'Fn::GetAtt': [
'RC21A1702',
'Arn',
],
},
}),
),
},
}));

test.done();
},

'uses the role when passed'(test: Test) {
const stack = new Stack();

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-dynamodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/jest": "^26.0.15",
"aws-sdk": "^2.828.0",
"aws-sdk": "^2.830.0",
"aws-sdk-mock": "^5.1.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class Ec2Service extends BaseService implements IEc2Service {
}

/**
* Adds one or more placement strategies to use for tasks in the service. For more information, see
* Adds one or more placement contstraints to use for tasks in the service. For more information, see
* [Amazon ECS Task Placement Constraints](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-placement-constraints.html).
*/
public addPlacementConstraints(...constraints: PlacementConstraint[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@
"Properties": {
"Code": {
"S3Bucket": {
"Ref": "AssetParameters8bda025b845a88fbeb54ef75e52048aa9f3378463116cb413f12f6014673a59aS3BucketFD1BBE00"
"Ref": "AssetParametersc24b999656e4fe6c609c31bae56a1cf4717a405619c3aa6ba1bc686b8c2c86cfS3Bucket55EFA30C"
},
"S3Key": {
"Fn::Join": [
Expand All @@ -1232,7 +1232,7 @@
"Fn::Split": [
"||",
{
"Ref": "AssetParameters8bda025b845a88fbeb54ef75e52048aa9f3378463116cb413f12f6014673a59aS3VersionKey6E54DC76"
"Ref": "AssetParametersc24b999656e4fe6c609c31bae56a1cf4717a405619c3aa6ba1bc686b8c2c86cfS3VersionKey60329B70"
}
]
}
Expand All @@ -1245,7 +1245,7 @@
"Fn::Split": [
"||",
{
"Ref": "AssetParameters8bda025b845a88fbeb54ef75e52048aa9f3378463116cb413f12f6014673a59aS3VersionKey6E54DC76"
"Ref": "AssetParametersc24b999656e4fe6c609c31bae56a1cf4717a405619c3aa6ba1bc686b8c2c86cfS3VersionKey60329B70"
}
]
}
Expand Down Expand Up @@ -1348,17 +1348,17 @@
"Type": "String",
"Description": "Artifact hash for asset \"e9882ab123687399f934da0d45effe675ecc8ce13b40cb946f3e1d6141fe8d68\""
},
"AssetParameters8bda025b845a88fbeb54ef75e52048aa9f3378463116cb413f12f6014673a59aS3BucketFD1BBE00": {
"AssetParametersc24b999656e4fe6c609c31bae56a1cf4717a405619c3aa6ba1bc686b8c2c86cfS3Bucket55EFA30C": {
"Type": "String",
"Description": "S3 bucket for asset \"8bda025b845a88fbeb54ef75e52048aa9f3378463116cb413f12f6014673a59a\""
"Description": "S3 bucket for asset \"c24b999656e4fe6c609c31bae56a1cf4717a405619c3aa6ba1bc686b8c2c86cf\""
},
"AssetParameters8bda025b845a88fbeb54ef75e52048aa9f3378463116cb413f12f6014673a59aS3VersionKey6E54DC76": {
"AssetParametersc24b999656e4fe6c609c31bae56a1cf4717a405619c3aa6ba1bc686b8c2c86cfS3VersionKey60329B70": {
"Type": "String",
"Description": "S3 key for asset version \"8bda025b845a88fbeb54ef75e52048aa9f3378463116cb413f12f6014673a59a\""
"Description": "S3 key for asset version \"c24b999656e4fe6c609c31bae56a1cf4717a405619c3aa6ba1bc686b8c2c86cf\""
},
"AssetParameters8bda025b845a88fbeb54ef75e52048aa9f3378463116cb413f12f6014673a59aArtifactHash595EC1E7": {
"AssetParametersc24b999656e4fe6c609c31bae56a1cf4717a405619c3aa6ba1bc686b8c2c86cfArtifactHash85F58E48": {
"Type": "String",
"Description": "Artifact hash for asset \"8bda025b845a88fbeb54ef75e52048aa9f3378463116cb413f12f6014673a59a\""
"Description": "Artifact hash for asset \"c24b999656e4fe6c609c31bae56a1cf4717a405619c3aa6ba1bc686b8c2c86cf\""
},
"AssetParameters972240f9dd6e036a93d5f081af9a24315b2053828ac049b3b19b2fa12d7ae64aS3Bucket1F1A8472": {
"Type": "String",
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-eks-legacy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@aws-cdk/aws-eks-legacy",
"version": "0.0.0",
"deprecated": "Use the @aws-cdk/aws-eks module instead",
"description": "The CDK Construct Library for AWS::EKS (Legacy)",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-eks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.31",
"@types/yaml": "1.9.6",
"aws-sdk": "^2.828.0",
"aws-sdk": "^2.830.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
Loading

0 comments on commit f669f85

Please sign in to comment.