File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed
packages/aws-cdk-lib/aws-ecr-assets Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,10 @@ This will instruct the toolkit to add the tarball as a file asset. During deploy
163163from ` local-image.tar ` , push it to an Amazon ECR repository and wire the name of the repository as CloudFormation parameters
164164to your stack.
165165
166+ Similar to ` DockerImageAsset ` , you can set the ` CDK_DOCKER ` environment variable to provide a custom Docker executable
167+ command or path. This may be needed when building in environments where the standard docker cannot be executed or when
168+ using alternative container runtimes like Finch.
169+
166170## Publishing images to ECR repositories
167171
168172` DockerImageAsset ` is designed for seamless build & consumption of image assets by CDK code deployed to multiple environments
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ export class TarballImageAsset extends Construct implements IAsset {
107107 executable : [
108108 'sh' ,
109109 '-c' ,
110- `docker load -i ${ relativePathInOutDir } | tail -n 1 | sed "${ DOCKER_LOAD_OUTPUT_REGEX } "` ,
110+ `${ process . env . CDK_DOCKER ?? ' docker' } load -i ${ relativePathInOutDir } | tail -n 1 | sed "${ DOCKER_LOAD_OUTPUT_REGEX } "` ,
111111 ] ,
112112 displayName : props . displayName ?? Names . stackRelativeConstructPath ( this ) ,
113113 } ) ;
Original file line number Diff line number Diff line change @@ -190,6 +190,40 @@ describe('image asset', () => {
190190 expect ( oldSedWithNewFormat . stdout . toString ( ) . trim ( ) ) . not . toBe ( 'sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a' ) ;
191191 expect ( oldSedWithNewFormat . stdout . toString ( ) . trim ( ) ) . toBe ( 'Loaded image ID: sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a' ) ;
192192 } ) ;
193+
194+ test ( 'respects CDK_DOCKER environment variable' , ( ) => {
195+ // GIVEN
196+ const originalCdkDocker = process . env . CDK_DOCKER ;
197+ process . env . CDK_DOCKER = 'custom-docker' ;
198+
199+ try {
200+ const app = new App ( ) ;
201+ const stack = new Stack ( app ) ;
202+ const asset = new TarballImageAsset ( stack , 'Image' , {
203+ tarballFile,
204+ } ) ;
205+
206+ // WHEN
207+ const asm = app . synth ( ) ;
208+
209+ // THEN
210+ const manifestArtifact = getAssetManifest ( asm ) ;
211+ const manifest = readAssetManifest ( manifestArtifact ) ;
212+
213+ expect ( manifest . dockerImages ?. [ asset . assetHash ] ?. source ?. executable ) . toEqual ( [
214+ 'sh' ,
215+ '-c' ,
216+ `custom-docker load -i asset.${ asset . assetHash } .tar | tail -n 1 | sed "${ DOCKER_LOAD_OUTPUT_REGEX } "` ,
217+ ] ) ;
218+ } finally {
219+ // Cleanup
220+ if ( originalCdkDocker !== undefined ) {
221+ process . env . CDK_DOCKER = originalCdkDocker ;
222+ } else {
223+ delete process . env . CDK_DOCKER ;
224+ }
225+ }
226+ } ) ;
193227} ) ;
194228
195229function isAssetManifest ( x : cxapi . CloudArtifact ) : x is cxapi . AssetManifestArtifact {
You can’t perform that action at this time.
0 commit comments