Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auto-build): Support Artifacts for AutoBuild #1456

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/__tests__/auto-build.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { App, Stack } from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
import { Artifacts } from 'aws-cdk-lib/aws-codebuild';
import { Bucket } from 'aws-cdk-lib/aws-s3';
import { AutoBuild, GitHubRepo } from '../../lib';

let app: App;
Expand Down Expand Up @@ -127,3 +129,27 @@ test('can disable webhooks', () => {
},
});
});

test('can enable artifacts', () => {
new AutoBuild(stack, 'AutoBuild', {
repo: new GitHubRepo({
repository: 'some-repo',
tokenSecretArn: 'arn:aws:secretsmanager:someregion:someaccount:secret:sometoken',
}),
artifacts: Artifacts.s3({
bucket: new Bucket(stack, 'artifactBucket'),
name: 'artifact-name',
}),
});
const template = Template.fromStack(stack);

template.hasResourceProperties('AWS::CodeBuild::Project', {
Artifacts: {
Location: { Ref: 'artifactBucket27548F83' },
Name: 'artifact-name',
NamespaceType: 'BUILD_ID',
Packaging: 'ZIP',
Type: 'S3',
},
});
});
6 changes: 6 additions & 0 deletions lib/auto-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export interface AutoBuildOptions {
*/
readonly buildSpec?: codebuild.BuildSpec;
/* tslint:enable:max-line-length */

/**
* ARTIFACTS
*/
readonly artifacts?: codebuild.IArtifacts;
}

export interface AutoBuildProps extends AutoBuildOptions {
Expand Down Expand Up @@ -112,6 +117,7 @@ export class AutoBuild extends Construct {
environment: createBuildEnvironment(props.environment ?? {}),
badge: props.repo.allowsBadge,
buildSpec: props.buildSpec,
artifacts: props.artifacts,
ssmSessionPermissions: true,
});
this.project.role!.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonElasticContainerRegistryPublicReadOnly'));
Expand Down