diff --git a/packages/@aws-cdk/aws-ecr-assets/README.md b/packages/@aws-cdk/aws-ecr-assets/README.md index 544c81720987d..e6f8fa7c5f43a 100644 --- a/packages/@aws-cdk/aws-ecr-assets/README.md +++ b/packages/@aws-cdk/aws-ecr-assets/README.md @@ -106,6 +106,18 @@ const asset = new DockerImageAsset(this, 'MyBuildImage', { }) ``` +You can optionally pass an array of outputs to the `docker build` command by specifying +the `outputs` property: + +```ts +import { DockerImageAsset, Platform } from '@aws-cdk/aws-ecr-assets'; + +const asset = new DockerImageAsset(this, 'MyBuildImage', { + directory: path.join(__dirname, 'my-image'), + outputs: ['type=local,dest=out'], +}) +``` + ## Images from Tarball Images are loaded from a local tarball, uploaded to ECR by the CDK toolkit and/or your app's CI-CD pipeline, and can be diff --git a/packages/@aws-cdk/aws-ecr-assets/lib/image-asset.ts b/packages/@aws-cdk/aws-ecr-assets/lib/image-asset.ts index 2c8c71879e113..a0269f1f495f3 100644 --- a/packages/@aws-cdk/aws-ecr-assets/lib/image-asset.ts +++ b/packages/@aws-cdk/aws-ecr-assets/lib/image-asset.ts @@ -47,7 +47,7 @@ export class NetworkMode { /** * @param mode The networking mode to use for docker build */ - private constructor(public readonly mode: string) {} + private constructor(public readonly mode: string) { } } /** @@ -77,7 +77,7 @@ export class Platform { /** * @param platform The platform to use for docker build */ - private constructor(public readonly platform: string) {} + private constructor(public readonly platform: string) { } } /** @@ -132,6 +132,13 @@ export interface DockerImageAssetInvalidationOptions { * @default true */ readonly platform?: boolean; + + /** + * Use `outputs` while calculating the asset hash + * + * @default true + */ + readonly outputs?: boolean; } /** @@ -197,6 +204,14 @@ export interface DockerImageAssetOptions extends FingerprintOptions, FileFingerp * @default - hash all parameters */ readonly invalidation?: DockerImageAssetInvalidationOptions; + + /** + * Outputs to pass to the `docker build` command. + * + * @default - no outputs are passed to the build command (default outputs are used) + * @see https://docs.docker.com/engine/reference/commandline/build/#custom-build-outputs + */ + readonly outputs?: string[]; } /** @@ -267,6 +282,11 @@ export class DockerImageAsset extends Construct implements IAsset { */ private readonly dockerBuildArgs?: { [key: string]: string }; + /** + * Outputs to pass to the `docker build` command. + */ + private readonly dockerOutputs?: string[]; + /** * Docker target to build to */ @@ -330,6 +350,7 @@ export class DockerImageAsset extends Construct implements IAsset { if (props.invalidation?.repositoryName !== false && props.repositoryName) { extraHash.repositoryName = props.repositoryName; } if (props.invalidation?.networkMode !== false && props.networkMode) { extraHash.networkMode = props.networkMode; } if (props.invalidation?.platform !== false && props.platform) { extraHash.platform = props.platform; } + if (props.invalidation?.outputs !== false && props.outputs) { extraHash.outputs = props.outputs; } // add "salt" to the hash in order to invalidate the image in the upgrade to // 1.21.0 which removes the AdoptedRepository resource (and will cause the @@ -354,6 +375,7 @@ export class DockerImageAsset extends Construct implements IAsset { this.assetPath = staging.relativeStagedPath(stack); this.dockerBuildArgs = props.buildArgs; this.dockerBuildTarget = props.target; + this.dockerOutputs = props.outputs; const location = stack.synthesizer.addDockerImageAsset({ directoryName: this.assetPath, @@ -363,6 +385,7 @@ export class DockerImageAsset extends Construct implements IAsset { sourceHash: staging.assetHash, networkMode: props.networkMode?.mode, platform: props.platform?.platform, + dockerOutputs: this.dockerOutputs, }); this.repository = ecr.Repository.fromRepositoryName(this, 'Repository', location.repositoryName); @@ -393,12 +416,13 @@ export class DockerImageAsset extends Construct implements IAsset { // tell tools such as SAM CLI that the resourceProperty of this resource // points to a local path and include the path to de dockerfile, docker build args, and target, // in order to enable local invocation of this function. - resource.cfnOptions.metadata = resource.cfnOptions.metadata || { }; + resource.cfnOptions.metadata = resource.cfnOptions.metadata || {}; resource.cfnOptions.metadata[cxapi.ASSET_RESOURCE_METADATA_PATH_KEY] = this.assetPath; resource.cfnOptions.metadata[cxapi.ASSET_RESOURCE_METADATA_DOCKERFILE_PATH_KEY] = this.dockerfilePath; resource.cfnOptions.metadata[cxapi.ASSET_RESOURCE_METADATA_DOCKER_BUILD_ARGS_KEY] = this.dockerBuildArgs; resource.cfnOptions.metadata[cxapi.ASSET_RESOURCE_METADATA_DOCKER_BUILD_TARGET_KEY] = this.dockerBuildTarget; resource.cfnOptions.metadata[cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY] = resourceProperty; + resource.cfnOptions.metadata[cxapi.ASSET_RESOURCE_METADATA_DOCKER_OUTPUTS_KEY] = this.dockerOutputs; } } diff --git a/packages/@aws-cdk/aws-ecr-assets/test/image-asset.test.ts b/packages/@aws-cdk/aws-ecr-assets/test/image-asset.test.ts index 775345b10d3e8..db926dedb562f 100644 --- a/packages/@aws-cdk/aws-ecr-assets/test/image-asset.test.ts +++ b/packages/@aws-cdk/aws-ecr-assets/test/image-asset.test.ts @@ -149,6 +149,7 @@ describe('image asset', () => { const asset4 = new DockerImageAsset(stack, 'Asset4', { directory, buildArgs: { opt1: '123', opt2: 'boom' } }); const asset5 = new DockerImageAsset(stack, 'Asset5', { directory, file: 'Dockerfile.Custom', target: 'NonDefaultTarget' }); const asset6 = new DockerImageAsset(stack, 'Asset6', { directory, extraHash: 'random-extra' }); + const asset7 = new DockerImageAsset(stack, 'Asset7', { directory, outputs: ['123'] }); expect(asset1.assetHash).toEqual('13248c55633f3b198a628bb2ea4663cb5226f8b2801051bd0c725950266fd590'); expect(asset2.assetHash).toEqual('36bf205fb9adc5e45ba1c8d534158a0aed96d190eff433af1d90f3b94f96e751'); @@ -156,6 +157,7 @@ describe('image asset', () => { expect(asset4.assetHash).toEqual('8a91219a7bb0f58b3282dd84acbf4c03c49c765be54ffb7b125be6a50b6c5645'); expect(asset5.assetHash).toEqual('c02bfba13b2e7e1ff5c778a76e10296b9e8d17f7f8252d097f4170ae04ce0eb4'); expect(asset6.assetHash).toEqual('3528d6838647a5e9011b0f35aec514d03ad11af05a94653cdcf4dacdbb070a06'); + expect(asset7.assetHash).toEqual('ced0a3076efe217f9cbdff0943e543f36ecf77f70b9a6fe28b8633deb728a462'); }); diff --git a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/asset.fa08370824fa0a7eab2c59a4f371fe7631019044d6c906b4268193120dc213b4/Dockerfile b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/asset.fa08370824fa0a7eab2c59a4f371fe7631019044d6c906b4268193120dc213b4/Dockerfile new file mode 100644 index 0000000000000..235b30e9661ed --- /dev/null +++ b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/asset.fa08370824fa0a7eab2c59a4f371fe7631019044d6c906b4268193120dc213b4/Dockerfile @@ -0,0 +1,5 @@ +FROM public.ecr.aws/lambda/python:3.6 +EXPOSE 8000 +WORKDIR /src +ADD . /src +CMD python3 index.py diff --git a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/asset.fa08370824fa0a7eab2c59a4f371fe7631019044d6c906b4268193120dc213b4/index.py b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/asset.fa08370824fa0a7eab2c59a4f371fe7631019044d6c906b4268193120dc213b4/index.py new file mode 100644 index 0000000000000..2ccedfce3ab76 --- /dev/null +++ b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/asset.fa08370824fa0a7eab2c59a4f371fe7631019044d6c906b4268193120dc213b4/index.py @@ -0,0 +1,33 @@ +#!/usr/bin/python +import sys +import textwrap +import http.server +import socketserver + +PORT = 8000 + + +class Handler(http.server.SimpleHTTPRequestHandler): + def do_GET(self): + self.send_response(200) + self.send_header('Content-Type', 'text/html') + self.end_headers() + self.wfile.write(textwrap.dedent('''\ + +
This container got built and started as part of the integ test.
+ + + ''').encode('utf-8')) + + +def main(): + httpd = http.server.HTTPServer(("", PORT), Handler) + print("serving at port", PORT) + httpd.serve_forever() + + +if __name__ == '__main__': + main() diff --git a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/cdk.out b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/cdk.out index 588d7b269d34f..e425c25d285ad 100644 --- a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"20.0.0"} \ No newline at end of file +{"version":"24.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ-assets-docker.assets.json b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ-assets-docker.assets.json index f313e184ea125..4630499e9d3a3 100644 --- a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ-assets-docker.assets.json +++ b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ-assets-docker.assets.json @@ -1,7 +1,7 @@ { - "version": "20.0.0", + "version": "24.0.0", "files": { - "129ed50df2725896720f8593072e2ac18c7c116a97374bea1f973ba8871c68e5": { + "3ef2c8ebbbb128e6fbd2f26a8c80b8154d5fe5157a29846585cb36feac29318e": { "source": { "path": "integ-assets-docker.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "129ed50df2725896720f8593072e2ac18c7c116a97374bea1f973ba8871c68e5.json", + "objectKey": "3ef2c8ebbbb128e6fbd2f26a8c80b8154d5fe5157a29846585cb36feac29318e.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } @@ -40,6 +40,21 @@ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-image-publishing-role-${AWS::AccountId}-${AWS::Region}" } } + }, + "fa08370824fa0a7eab2c59a4f371fe7631019044d6c906b4268193120dc213b4": { + "source": { + "directory": "asset.fa08370824fa0a7eab2c59a4f371fe7631019044d6c906b4268193120dc213b4", + "dockerOutputs": [ + "type=docker" + ] + }, + "destinations": { + "current_account-current_region": { + "repositoryName": "cdk-hnb659fds-container-assets-${AWS::AccountId}-${AWS::Region}", + "imageTag": "fa08370824fa0a7eab2c59a4f371fe7631019044d6c906b4268193120dc213b4", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-image-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ-assets-docker.template.json b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ-assets-docker.template.json index 6824c36b9e856..56e3637207a43 100644 --- a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ-assets-docker.template.json +++ b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ-assets-docker.template.json @@ -71,6 +71,11 @@ "Value": { "Fn::Sub": "${AWS::AccountId}.dkr.ecr.${AWS::Region}.${AWS::URLSuffix}/cdk-hnb659fds-container-assets-${AWS::AccountId}-${AWS::Region}:394b24fcdc153a83b1fc400bf2e812ee67e3a5ffafdf977d531cfe2187d95f38" } + }, + "ImageUri4": { + "Value": { + "Fn::Sub": "${AWS::AccountId}.dkr.ecr.${AWS::Region}.${AWS::URLSuffix}/cdk-hnb659fds-container-assets-${AWS::AccountId}-${AWS::Region}:fa08370824fa0a7eab2c59a4f371fe7631019044d6c906b4268193120dc213b4" + } } }, "Parameters": { diff --git a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ.json b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ.json index 5792f49559a4d..4848cd7f244e2 100644 --- a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ.json +++ b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "20.0.0", + "version": "24.0.0", "testCases": { "integ.assets-docker": { "stacks": [ diff --git a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/manifest.json b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/manifest.json index 31cbfe3fe4d55..48be2750bd076 100644 --- a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/manifest.json @@ -1,12 +1,6 @@ { - "version": "20.0.0", + "version": "24.0.0", "artifacts": { - "Tree": { - "type": "cdk:tree", - "properties": { - "file": "tree.json" - } - }, "integ-assets-docker.assets": { "type": "cdk:asset-manifest", "properties": { @@ -23,7 +17,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/129ed50df2725896720f8593072e2ac18c7c116a97374bea1f973ba8871c68e5.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/3ef2c8ebbbb128e6fbd2f26a8c80b8154d5fe5157a29846585cb36feac29318e.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -69,6 +63,12 @@ "data": "ImageUri3" } ], + "/integ-assets-docker/ImageUri4": [ + { + "type": "aws:cdk:logicalId", + "data": "ImageUri4" + } + ], "/integ-assets-docker/BootstrapVersion": [ { "type": "aws:cdk:logicalId", @@ -83,6 +83,12 @@ ] }, "displayName": "integ-assets-docker" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/tree.json b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/tree.json index 4ac3cf9f4c4db..c013950bfa133 100644 --- a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.js.snapshot/tree.json @@ -4,14 +4,6 @@ "id": "App", "path": "", "children": { - "Tree": { - "id": "Tree", - "path": "Tree", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" - } - }, "integ-assets-docker": { "id": "integ-assets-docker", "path": "integ-assets-docker", @@ -24,8 +16,8 @@ "id": "Staging", "path": "integ-assets-docker/DockerImage/Staging", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.AssetStaging", + "version": "0.0.0" } }, "Repository": { @@ -50,8 +42,8 @@ "id": "Staging", "path": "integ-assets-docker/DockerImage2/Staging", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.AssetStaging", + "version": "0.0.0" } }, "Repository": { @@ -76,8 +68,8 @@ "id": "Staging", "path": "integ-assets-docker/DockerImage3/Staging", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.AssetStaging", + "version": "0.0.0" } }, "Repository": { @@ -94,6 +86,32 @@ "version": "0.0.0" } }, + "DockerImage4": { + "id": "DockerImage4", + "path": "integ-assets-docker/DockerImage4", + "children": { + "Staging": { + "id": "Staging", + "path": "integ-assets-docker/DockerImage4/Staging", + "constructInfo": { + "fqn": "@aws-cdk/core.AssetStaging", + "version": "0.0.0" + } + }, + "Repository": { + "id": "Repository", + "path": "integ-assets-docker/DockerImage4/Repository", + "constructInfo": { + "fqn": "@aws-cdk/aws-ecr.RepositoryBase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ecr-assets.DockerImageAsset", + "version": "0.0.0" + } + }, "MyUser": { "id": "MyUser", "path": "integ-assets-docker/MyUser", @@ -190,36 +208,68 @@ "id": "ImageUri", "path": "integ-assets-docker/ImageUri", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.CfnOutput", + "version": "0.0.0" } }, "ImageUri2": { "id": "ImageUri2", "path": "integ-assets-docker/ImageUri2", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.CfnOutput", + "version": "0.0.0" } }, "ImageUri3": { "id": "ImageUri3", "path": "integ-assets-docker/ImageUri3", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.CfnOutput", + "version": "0.0.0" + } + }, + "ImageUri4": { + "id": "ImageUri4", + "path": "integ-assets-docker/ImageUri4", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnOutput", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "integ-assets-docker/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "integ-assets-docker/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" } } }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.1.85" + "version": "10.1.182" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.ts b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.ts index f71b41e7b09a3..1aa9fa392af0a 100644 --- a/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.ts +++ b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.ts @@ -19,13 +19,20 @@ const asset3 = new assets.DockerImageAsset(stack, 'DockerImage3', { platform: assets.Platform.LINUX_ARM64, }); +const asset4 = new assets.DockerImageAsset(stack, 'DockerImage4', { + directory: path.join(__dirname, 'demo-image'), + outputs: ['type=docker'], +}); + const user = new iam.User(stack, 'MyUser'); asset.repository.grantPull(user); asset2.repository.grantPull(user); asset3.repository.grantPull(user); +asset4.repository.grantPull(user); new cdk.CfnOutput(stack, 'ImageUri', { value: asset.imageUri }); new cdk.CfnOutput(stack, 'ImageUri2', { value: asset2.imageUri }); new cdk.CfnOutput(stack, 'ImageUri3', { value: asset3.imageUri }); +new cdk.CfnOutput(stack, 'ImageUri4', { value: asset4.imageUri }); app.synth(); diff --git a/packages/@aws-cdk/cloud-assembly-schema/lib/assets/docker-image-asset.ts b/packages/@aws-cdk/cloud-assembly-schema/lib/assets/docker-image-asset.ts index ed39ad833b9ce..5fa99faf9a687 100644 --- a/packages/@aws-cdk/cloud-assembly-schema/lib/assets/docker-image-asset.ts +++ b/packages/@aws-cdk/cloud-assembly-schema/lib/assets/docker-image-asset.ts @@ -80,6 +80,14 @@ export interface DockerImageSource { * @default - current machine platform */ readonly platform?: string; + + /** + * Outputs + * + * @default - no outputs are passed to the build command (default outputs are used) + * @see https://docs.docker.com/engine/reference/commandline/build/#custom-build-outputs + */ + readonly dockerOutputs?: string[]; } /** diff --git a/packages/@aws-cdk/cloud-assembly-schema/lib/cloud-assembly/metadata-schema.ts b/packages/@aws-cdk/cloud-assembly-schema/lib/cloud-assembly/metadata-schema.ts index 3ed8bfe42cf50..93f6f6a85e2f9 100644 --- a/packages/@aws-cdk/cloud-assembly-schema/lib/cloud-assembly/metadata-schema.ts +++ b/packages/@aws-cdk/cloud-assembly-schema/lib/cloud-assembly/metadata-schema.ts @@ -145,6 +145,14 @@ export interface ContainerImageAssetMetadataEntry extends BaseAssetMetadataEntry * @default - current machine platform */ readonly platform?: string; + + /** + * Outputs to pass to the `docker build` command. + * + * @default - no outputs are passed to the build command (default outputs are used) + * @see https://docs.docker.com/engine/reference/commandline/build/#custom-build-outputs + */ + readonly outputs?: string[]; } /** diff --git a/packages/@aws-cdk/cloud-assembly-schema/schema/assets.schema.json b/packages/@aws-cdk/cloud-assembly-schema/schema/assets.schema.json index e2b5aa8780c04..c861e5f3819db 100644 --- a/packages/@aws-cdk/cloud-assembly-schema/schema/assets.schema.json +++ b/packages/@aws-cdk/cloud-assembly-schema/schema/assets.schema.json @@ -162,6 +162,13 @@ "platform": { "description": "Platform to build for. _Requires Docker Buildx_.\n\nSpecify this property to build images on a specific platform/architecture. (Default - current machine platform)", "type": "string" + }, + "dockerOutputs": { + "description": "Outputs (Default - no outputs are passed to the build command (default outputs are used))", + "type": "array", + "items": { + "type": "string" + } } } }, diff --git a/packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.schema.json b/packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.schema.json index 3bb6b3b231413..ae253314c97c0 100644 --- a/packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.schema.json +++ b/packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.schema.json @@ -234,6 +234,13 @@ "description": "Platform to build for. _Requires Docker Buildx_. (Default - current machine platform)", "type": "string" }, + "outputs": { + "description": "Outputs to pass to the `docker build` command. (Default - no outputs are passed to the build command (default outputs are used))", + "type": "array", + "items": { + "type": "string" + } + }, "id": { "description": "Logical identifier for the asset", "type": "string" @@ -881,4 +888,4 @@ } }, "$schema": "http://json-schema.org/draft-07/schema#" -} +} \ No newline at end of file diff --git a/packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.version.json b/packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.version.json index 145739f539580..d8b441d447f8a 100644 --- a/packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.version.json +++ b/packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.version.json @@ -1 +1 @@ -{"version":"22.0.0"} \ No newline at end of file +{"version":"29.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/core/lib/assets.ts b/packages/@aws-cdk/core/lib/assets.ts index 8c37d8e9ed2c2..ea7903f7f23c2 100644 --- a/packages/@aws-cdk/core/lib/assets.ts +++ b/packages/@aws-cdk/core/lib/assets.ts @@ -221,6 +221,14 @@ export interface DockerImageAssetSource { * @default - no platform specified (the current machine architecture will be used) */ readonly platform?: string; + + /** + * Outputs to pass to the `docker build` command. + * + * @default - no build args are passed + */ + readonly dockerOutputs?: string[]; + } /** diff --git a/packages/@aws-cdk/core/lib/stack-synthesizers/asset-manifest-builder.ts b/packages/@aws-cdk/core/lib/stack-synthesizers/asset-manifest-builder.ts index 73e23c330c9b1..92497aacb27fc 100644 --- a/packages/@aws-cdk/core/lib/stack-synthesizers/asset-manifest-builder.ts +++ b/packages/@aws-cdk/core/lib/stack-synthesizers/asset-manifest-builder.ts @@ -69,6 +69,7 @@ export class AssetManifestBuilder { dockerFile: asset.dockerFile, networkMode: asset.networkMode, platform: asset.platform, + dockerOutputs: asset.dockerOutputs, }, { repositoryName: target.repositoryName, imageTag, @@ -241,6 +242,7 @@ function validateDockerImageAssetSource(asset: DockerImageAssetSource) { check('dockerBuildArgs'); check('dockerBuildTarget'); + check('dockerOutputs'); check('dockerFile'); function check