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(core): Docker tags can be prefixed #17028

Merged
merged 2 commits into from
Oct 27, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,20 @@ export interface DefaultStackSynthesizerProps {
/**
* bucketPrefix to use while storing S3 Assets
*
*
* @default - DefaultStackSynthesizer.DEFAULT_FILE_ASSET_PREFIX
*/
readonly bucketPrefix?: string;

/**
* A prefix to use while tagging and uploading Docker images to ECR.
*
* This does not add any separators - the source hash will be appended to
* this string directly.
*
* @default - DefaultStackSynthesizer.DEFAULT_DOCKER_ASSET_PREFIX
*/
readonly dockerTagPrefix?: string;

/**
* Bootstrap stack version SSM parameter.
*
Expand Down Expand Up @@ -242,6 +251,10 @@ export class DefaultStackSynthesizer extends StackSynthesizer {
* Default file asset prefix
*/
public static readonly DEFAULT_FILE_ASSET_PREFIX = '';
/**
* Default Docker asset prefix
*/
public static readonly DEFAULT_DOCKER_ASSET_PREFIX = '';

/**
* Default bootstrap stack version SSM parameter.
Expand All @@ -258,6 +271,7 @@ export class DefaultStackSynthesizer extends StackSynthesizer {
private lookupRoleArn?: string;
private qualifier?: string;
private bucketPrefix?: string;
private dockerTagPrefix?: string;
private bootstrapStackVersionSsmParameter?: string;

private readonly files: NonNullable<cxschema.AssetManifest['files']> = {};
Expand Down Expand Up @@ -319,6 +333,7 @@ export class DefaultStackSynthesizer extends StackSynthesizer {
this.imageAssetPublishingRoleArn = specialize(this.props.imageAssetPublishingRoleArn ?? DefaultStackSynthesizer.DEFAULT_IMAGE_ASSET_PUBLISHING_ROLE_ARN);
this.lookupRoleArn = specialize(this.props.lookupRoleArn ?? DefaultStackSynthesizer.DEFAULT_LOOKUP_ROLE_ARN);
this.bucketPrefix = specialize(this.props.bucketPrefix ?? DefaultStackSynthesizer.DEFAULT_FILE_ASSET_PREFIX);
this.dockerTagPrefix = specialize(this.props.dockerTagPrefix ?? DefaultStackSynthesizer.DEFAULT_DOCKER_ASSET_PREFIX);
this.bootstrapStackVersionSsmParameter = replaceAll(
this.props.bootstrapStackVersionSsmParameter ?? DefaultStackSynthesizer.DEFAULT_BOOTSTRAP_STACK_VERSION_SSM_PARAMETER,
'${Qualifier}',
Expand Down Expand Up @@ -372,7 +387,7 @@ export class DefaultStackSynthesizer extends StackSynthesizer {
assertBound(this.repositoryName);
validateDockerImageAssetSource(asset);

const imageTag = asset.sourceHash;
const imageTag = this.dockerTagPrefix + asset.sourceHash;

// Add to manifest
this.dockerImages[asset.sourceHash] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,30 @@ describe('new style synthesis', () => {

});

test('synthesis with dockerPrefix', () => {
// GIVEN
const myapp = new App();

// WHEN
const mystack = new Stack(myapp, 'mystack-dockerPrefix', {
synthesizer: new DefaultStackSynthesizer({
dockerTagPrefix: 'test-prefix-',
}),
});

mystack.synthesizer.addDockerImageAsset({
directoryName: 'some-folder',
sourceHash: 'docker-asset-hash',
});

const asm = myapp.synth();

// THEN
const manifest = readAssetManifest(getAssetManifest(asm));
const imageTag = manifest.dockerImages?.['docker-asset-hash']?.destinations?.['current_account-current_region'].imageTag;
expect(imageTag).toEqual('test-prefix-docker-asset-hash');
});

test('cannot use same synthesizer for multiple stacks', () => {
// GIVEN
const synthesizer = new DefaultStackSynthesizer();
Expand Down