Skip to content
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
4 changes: 4 additions & 0 deletions packages/aws-cdk-lib/aws-ecr-assets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ This will instruct the toolkit to add the tarball as a file asset. During deploy
from `local-image.tar`, push it to an Amazon ECR repository and wire the name of the repository as CloudFormation parameters
to your stack.

Similar to `DockerImageAsset`, you can set the `CDK_DOCKER` environment variable to provide a custom Docker executable
command or path. This may be needed when building in environments where the standard docker cannot be executed or when
using alternative container runtimes like Finch.

## Publishing images to ECR repositories

`DockerImageAsset` is designed for seamless build & consumption of image assets by CDK code deployed to multiple environments
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-ecr-assets/lib/tarball-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class TarballImageAsset extends Construct implements IAsset {
executable: [
'sh',
'-c',
`docker load -i ${relativePathInOutDir} | tail -n 1 | sed "${DOCKER_LOAD_OUTPUT_REGEX}"`,
`${process.env.CDK_DOCKER ?? 'docker'} load -i ${relativePathInOutDir} | tail -n 1 | sed "${DOCKER_LOAD_OUTPUT_REGEX}"`,
],
displayName: props.displayName ?? Names.stackRelativeConstructPath(this),
});
Expand Down
34 changes: 34 additions & 0 deletions packages/aws-cdk-lib/aws-ecr-assets/test/tarball-asset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,40 @@ describe('image asset', () => {
expect(oldSedWithNewFormat.stdout.toString().trim()).not.toBe('sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a');
expect(oldSedWithNewFormat.stdout.toString().trim()).toBe('Loaded image ID: sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a');
});

test('respects CDK_DOCKER environment variable', () => {
// GIVEN
const originalCdkDocker = process.env.CDK_DOCKER;
process.env.CDK_DOCKER = 'custom-docker';

try {
const app = new App();
const stack = new Stack(app);
const asset = new TarballImageAsset(stack, 'Image', {
tarballFile,
});

// WHEN
const asm = app.synth();

// THEN
const manifestArtifact = getAssetManifest(asm);
const manifest = readAssetManifest(manifestArtifact);

expect(manifest.dockerImages?.[asset.assetHash]?.source?.executable).toEqual([
'sh',
'-c',
`custom-docker load -i asset.${asset.assetHash}.tar | tail -n 1 | sed "${DOCKER_LOAD_OUTPUT_REGEX}"`,
]);
} finally {
// Cleanup
if (originalCdkDocker !== undefined) {
process.env.CDK_DOCKER = originalCdkDocker;
} else {
delete process.env.CDK_DOCKER;
}
}
});
});

function isAssetManifest(x: cxapi.CloudArtifact): x is cxapi.AssetManifestArtifact {
Expand Down
Loading