Skip to content

Commit ba20e66

Browse files
authored
feat(container-image-build): enable scanOnPush of the default ECR repository (#68)
We enable [ScanOnPush](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ecr-repository.html#cfn-ecr-repository-imagescanningconfiguration) property of the default repository that is automatically created.
1 parent 412b94b commit ba20e66

File tree

7 files changed

+20
-13
lines changed

7 files changed

+20
-13
lines changed

src/container-image-build.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class ContainerImageBuild extends Construct implements IGrantable {
9393
const handler = new SingletonFunction(this, 'CustomResourceHandler', {
9494
// Use raw string to avoid from tightening CDK version requirement
9595
runtime: new Runtime('nodejs22.x', RuntimeFamily.NODEJS),
96-
code: Code.fromAsset(join(__dirname, '../lambda/trigger-codebuild/dist')),
96+
code: Code.fromAsset(join(__dirname, '..', 'lambda', 'trigger-codebuild', 'dist')),
9797
handler: 'index.handler',
9898
uuid: 'db740fd5-5436-4a84-8a09-e6dfcd01f4f3', // generated for this construct
9999
lambdaPurpose: 'DeployTimeBuildCustomResourceHandler',
@@ -111,6 +111,7 @@ export class ContainerImageBuild extends Construct implements IGrantable {
111111
if (repository === undefined) {
112112
repository = new Repository(this, 'Repository', { removalPolicy: RemovalPolicy.DESTROY });
113113
(repository.node.defaultChild as CfnResource).addPropertyOverride('EmptyOnDelete', true);
114+
(repository.node.defaultChild as CfnResource).addPropertyOverride('ImageScanningConfiguration.ScanOnPush', true);
114115
}
115116
const repositoryUri = repository.repositoryUri;
116117
const imageArtifactName = 'artifact:$imageTag';
@@ -187,7 +188,7 @@ curl -i -X PUT -H 'Content-Type:' -d "@payload.json" "$responseURL"
187188
new PolicyStatement({
188189
actions: ['codebuild:StartBuild'],
189190
resources: [project.projectArn],
190-
}),
191+
})
191192
);
192193

193194
this.grantPrincipal = project.grantPrincipal;
@@ -245,13 +246,13 @@ curl -i -X PUT -H 'Content-Type:' -d "@payload.json" "$responseURL"
245246
if (this.props.zstdCompression) {
246247
throw new Error('You cannot enable zstdCompression for a Lambda image.');
247248
}
248-
return DockerImageCode.fromEcr(this.repository, {
249+
return DockerImageCode.fromEcr(this.repository, {
249250
tagOrDigest: this.imageTag,
250251
...(options && {
251252
cmd: options.cmd,
252253
entrypoint: options.entrypoint,
253254
workingDirectory: options.workingDirectory,
254-
})
255+
}),
255256
});
256257
}
257258

src/nodejs-build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class NodejsBuild extends Construct implements IGrantable {
9494
const handler = new SingletonFunction(this, 'CustomResourceHandler', {
9595
// Use raw string to avoid from tightening CDK version requirement
9696
runtime: new Runtime('nodejs22.x', RuntimeFamily.NODEJS),
97-
code: Code.fromAsset(join(__dirname, '../lambda/trigger-codebuild/dist')),
97+
code: Code.fromAsset(join(__dirname, '..', 'lambda', 'trigger-codebuild', 'dist')),
9898
handler: 'index.handler',
9999
uuid: '25648b21-2c40-4f09-aa65-b6bbb0c44659', // generated for this construct
100100
lambdaPurpose: 'NodejsBuildCustomResourceHandler',

src/soci-index-build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class SociIndexBuild extends Construct {
5353
const handler = new SingletonFunction(this, 'CustomResourceHandler', {
5454
// Use raw string to avoid from tightening CDK version requirement
5555
runtime: new Runtime('nodejs22.x', RuntimeFamily.NODEJS),
56-
code: Code.fromAsset(join(__dirname, '../lambda/trigger-codebuild/dist')),
56+
code: Code.fromAsset(join(__dirname, '..', 'lambda', 'trigger-codebuild', 'dist')),
5757
handler: 'index.handler',
5858
uuid: 'db740fd5-5436-4a84-8a09-e6dfcd01f4f3', // generated for this construct
5959
lambdaPurpose: 'DeployTimeBuildCustomResourceHandler',

src/soci-index-v2-build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class SociIndexV2Build extends Construct {
6161
const handler = new SingletonFunction(this, 'CustomResourceHandler', {
6262
// Use raw string to avoid from tightening CDK version requirement
6363
runtime: new Runtime('nodejs22.x', RuntimeFamily.NODEJS),
64-
code: Code.fromAsset(join(__dirname, '../lambda/trigger-codebuild/dist')),
64+
code: Code.fromAsset(join(__dirname, '..', 'lambda', 'trigger-codebuild', 'dist')),
6565
handler: 'index.handler',
6666
uuid: 'db740fd5-5436-4a84-8a09-e6dfcd01f4f3', // generated for this construct
6767
lambdaPurpose: 'DeployTimeBuildCustomResourceHandler',
@@ -128,7 +128,7 @@ curl -i -X PUT -H 'Content-Type:' -d "@payload.json" "$responseURL"
128128
new PolicyStatement({
129129
actions: ['codebuild:StartBuild'],
130130
resources: [project.projectArn],
131-
}),
131+
})
132132
);
133133

134134
props.repository.grantPullPush(project);

test/integ.container-image-build.js.snapshot/ContainerImageBuildIntegTest.assets.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@
4343
}
4444
}
4545
},
46-
"16d150644872ea88464ea8f88cee4092306cd22327ecb92864797e18c711a96f": {
46+
"77807388cb9565a638520f4f29ffad683dc734aa115bbd7f4459055e84d0d746": {
4747
"displayName": "ContainerImageBuildIntegTest Template",
4848
"source": {
4949
"path": "ContainerImageBuildIntegTest.template.json",
5050
"packaging": "file"
5151
},
5252
"destinations": {
53-
"current_account-current_region-18271ba7": {
53+
"current_account-current_region-723e0682": {
5454
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
55-
"objectKey": "16d150644872ea88464ea8f88cee4092306cd22327ecb92864797e18c711a96f.json",
55+
"objectKey": "77807388cb9565a638520f4f29ffad683dc734aa115bbd7f4459055e84d0d746.json",
5656
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
5757
}
5858
}

test/integ.container-image-build.js.snapshot/ContainerImageBuildIntegTest.template.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,9 @@
475475
"Type": "AWS::ECR::Repository",
476476
"Properties": {
477477
"EmptyOnDelete": true,
478+
"ImageScanningConfiguration": {
479+
"ScanOnPush": true
480+
},
478481
"RepositoryPolicyText": {
479482
"Statement": [
480483
{
@@ -1562,7 +1565,10 @@
15621565
"UpdateReplacePolicy": "Delete",
15631566
"DeletionPolicy": "Delete",
15641567
"Properties": {
1565-
"EmptyOnDelete": true
1568+
"EmptyOnDelete": true,
1569+
"ImageScanningConfiguration": {
1570+
"ScanOnPush": true
1571+
}
15661572
}
15671573
},
15681574
"BuildVpc1895B133": {

test/integ.container-image-build.js.snapshot/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"validateOnSynth": false,
1919
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
2020
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
21-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/16d150644872ea88464ea8f88cee4092306cd22327ecb92864797e18c711a96f.json",
21+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/77807388cb9565a638520f4f29ffad683dc734aa115bbd7f4459055e84d0d746.json",
2222
"requiresBootstrapStackVersion": 6,
2323
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2424
"additionalDependencies": [

0 commit comments

Comments
 (0)