Skip to content

Commit d811b28

Browse files
author
Tarun Belani
committed
Addressed review comments
1 parent fbe2665 commit d811b28

16 files changed

+100
-59
lines changed

packages/@aws-cdk/aws-imagebuilder-alpha/lib/base-image.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class ContainerInstanceImage {
7676
* @param parameter The SSM parameter to use as the container instance image
7777
*/
7878
public static fromSsmParameter(parameter: ssm.IStringParameter): ContainerInstanceImage {
79-
return this.fromSsmParameterName(parameter.parameterArn);
79+
return new ContainerInstanceImage(`ssm:${parameter.parameterArn}`);
8080
}
8181

8282
/**
@@ -89,8 +89,9 @@ export class ContainerInstanceImage {
8989
}
9090

9191
/**
92-
* The string value of the container instance image to use in a container recipe. This can either be an SSM parameter,
93-
* or an AMI ID.
92+
* The string value of the container instance image to use in a container recipe. This can either be:
93+
* - an SSM parameter reference, prefixed with `ssm:` and followed by the parameter name or ARN
94+
* - an AMI ID
9495
*
9596
* @param containerInstanceImageString The container instance image as a direct string value
9697
*/

packages/@aws-cdk/aws-imagebuilder-alpha/lib/container-recipe.ts

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import { ComponentConfiguration, IRecipeBase } from './recipe-base';
1414

1515
const CONTAINER_RECIPE_SYMBOL = Symbol.for('@aws-cdk/aws-imagebuilder-alpha.ContainerRecipe');
1616

17+
/**
18+
* Represents the latest version of a container recipe. When using the recipe in a pipeline, the pipeline will use the
19+
* latest recipe at the time of execution.
20+
*
21+
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/ibhow-semantic-versioning.html
22+
*/
1723
const LATEST_VERSION = 'x.x.x';
1824

1925
/**
@@ -66,7 +72,7 @@ export interface ContainerRecipeProps {
6672
/**
6773
* The version of the container recipe.
6874
*
69-
* @default 1.0.0
75+
* @default 1.0.x
7076
*/
7177
readonly containerRecipeVersion?: string;
7278

@@ -81,7 +87,7 @@ export interface ContainerRecipeProps {
8187
* The dockerfile template used to build the container image.
8288
*
8389
* @default - a standard dockerfile template will be generated to pull the base image, perform environment setup, and
84-
* run all components in the recipe
90+
* run all components in the recipe
8591
*/
8692
readonly dockerfile?: DockerfileData;
8793

@@ -103,15 +109,15 @@ export interface ContainerRecipeProps {
103109
* The working directory for use during build and test workflows.
104110
*
105111
* @default - the Image Builder default working directory is used. For Linux and macOS builds, this would be /tmp. For
106-
* Windows builds, this would be C:/
112+
* Windows builds, this would be C:/
107113
*/
108114
readonly workingDirectory?: string;
109115

110116
/**
111117
* The operating system (OS) version of the base image.
112118
*
113119
* @default - Image Builder will determine the OS version of the base image, if sourced from a third-party container
114-
* registry. Otherwise, the OS version of the base image is required.
120+
* registry. Otherwise, the OS version of the base image is required.
115121
*/
116122
readonly osVersion?: OSVersion;
117123

@@ -137,6 +143,27 @@ export interface ContainerRecipeProps {
137143
readonly tags?: { [key: string]: string };
138144
}
139145

146+
/**
147+
* The rendered Dockerfile value, for use in CloudFormation.
148+
* - For inline dockerfiles, dockerfileTemplateData is the Dockerfile template text
149+
* - For S3-backed dockerfiles, dockerfileTemplateUri is the S3 URL
150+
*/
151+
export interface DockerfileTemplateConfig {
152+
/**
153+
* The rendered Dockerfile data, for use in CloudFormation
154+
*
155+
* @default - none if dockerfileTemplateUri is set
156+
*/
157+
readonly dockerfileTemplateData?: string;
158+
159+
/**
160+
* The rendered Dockerfile URI, for use in CloudFormation
161+
*
162+
* @default - none if dockerfileTemplateData is set
163+
*/
164+
readonly dockerfileTemplateUri?: string;
165+
}
166+
140167
/**
141168
* Helper class for referencing and uploading dockerfile data for the container recipe
142169
*/
@@ -179,36 +206,34 @@ export abstract class DockerfileData {
179206
}
180207

181208
/**
182-
* Indicates that the provided dockerfile data is an S3 reference
183-
*/
184-
abstract readonly isS3Reference: boolean;
185-
186-
/**
187-
* The resulting inline string or S3 URL which references the dockerfile data
209+
* The rendered Dockerfile value, for use in CloudFormation.
210+
* - For inline dockerfiles, dockerfileTemplateData is the Dockerfile template text
211+
* - For S3-backed dockerfiles, dockerfileTemplateUri is the S3 URL
188212
*/
189-
public readonly value: string;
190-
191-
protected constructor(value: string) {
192-
this.value = value;
193-
}
213+
abstract render(): DockerfileTemplateConfig;
194214
}
195215

196216
/**
197217
* Helper class for S3-based dockerfile data references, containing additional permission grant methods on the S3 object
198218
*/
199219
export abstract class S3DockerfileData extends DockerfileData {
200-
public readonly isS3Reference = true;
201-
202220
protected readonly bucket: s3.IBucket;
203221
protected readonly key: string;
204222

205223
protected constructor(bucket: s3.IBucket, key: string) {
206-
super(bucket.s3UrlForObject(key));
224+
super();
207225

208226
this.bucket = bucket;
209227
this.key = key;
210228
}
211229

230+
/**
231+
* The rendered Dockerfile S3 URL, for use in CloudFormation
232+
*/
233+
public render(): DockerfileTemplateConfig {
234+
return { dockerfileTemplateUri: this.bucket.s3UrlForObject(this.key) };
235+
}
236+
212237
/**
213238
* Grant put permissions to the given grantee for the dockerfile data in S3
214239
*
@@ -229,10 +254,19 @@ export abstract class S3DockerfileData extends DockerfileData {
229254
}
230255

231256
class InlineDockerfileData extends DockerfileData {
232-
public readonly isS3Reference = false;
257+
protected readonly data: string;
233258

234259
public constructor(data: string) {
235-
super(data);
260+
super();
261+
262+
this.data = data;
263+
}
264+
265+
/**
266+
* The rendered Dockerfile text, for use in CloudFormation
267+
*/
268+
public render(): DockerfileTemplateConfig {
269+
return { dockerfileTemplateData: this.data };
236270
}
237271
}
238272

@@ -255,24 +289,22 @@ export interface ContainerRecipeAttributes {
255289
/**
256290
* The ARN of the container recipe
257291
*
258-
* @default - the ARN is automatically constructed if a containerRecipeName is provided, otherwise a
259-
* containerRecipeArn is required
292+
* @default - derived from containerRecipeName
260293
*/
261294
readonly containerRecipeArn?: string;
262295

263296
/**
264297
* The name of the container recipe
265298
*
266-
* @default - the name is automatically constructed if a containerRecipeArn is provided, otherwise a
267-
* containerRecipeName is required
299+
* @default - derived from containerRecipeArn
268300
*/
269301
readonly containerRecipeName?: string;
270302

271303
/**
272304
* The version of the container recipe
273305
*
274-
* @default - the version is automatically constructed if a containerRecipeArn is provided, otherwise the latest
275-
* version is used.
306+
* @default - derived from containerRecipeArn. if a containerRecipeName is provided, the latest version, x.x.x, will
307+
* be used.
276308
*/
277309
readonly containerRecipeVersion?: string;
278310
}
@@ -468,7 +500,7 @@ export class ContainerRecipe extends ContainerRecipeBase {
468500
'FROM {{{ imagebuilder:parentImage }}}\n{{{ imagebuilder:environments }}}\n{{{ imagebuilder:components }}}',
469501
);
470502

471-
const containerRecipeVersion = props.containerRecipeVersion ?? '1.0.0';
503+
const containerRecipeVersion = props.containerRecipeVersion ?? '1.0.x';
472504
const containerRecipe = new CfnContainerRecipe(this, 'Resource', {
473505
name: this.physicalName,
474506
version: containerRecipeVersion,
@@ -485,10 +517,8 @@ export class ContainerRecipe extends ContainerRecipeBase {
485517
instanceConfiguration: cdk.Lazy.any({ produce: () => this.buildInstanceConfiguration(props) }),
486518
workingDirectory: props.workingDirectory,
487519
tags: props.tags,
520+
...dockerfile.render(),
488521
...(components?.length && { components }),
489-
...(dockerfile.isS3Reference
490-
? { dockerfileTemplateUri: dockerfile.value }
491-
: { dockerfileTemplateData: dockerfile.value }),
492522
});
493523

494524
this.containerRecipeName = this.getResourceNameAttribute(containerRecipe.attrName);
@@ -499,6 +529,7 @@ export class ContainerRecipe extends ContainerRecipeBase {
499529
});
500530
this.containerRecipeVersion = containerRecipe.getAtt('Version').toString();
501531
}
532+
502533
/**
503534
* Adds block devices to attach to the instance used for building, testing, and distributing the container image.
504535
*

packages/@aws-cdk/aws-imagebuilder-alpha/test/container-recipe.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ CMD ["echo", "Hello, world!"]
345345
Type: 'AWS::ImageBuilder::ContainerRecipe',
346346
Properties: {
347347
Name: 'stack-containerrecipe-fcc21fd4',
348-
Version: '1.0.0',
348+
Version: '1.0.x',
349349
ContainerType: 'DOCKER',
350350
ParentImage: 'amazonlinux:latest',
351351
DockerfileTemplateData:
@@ -373,7 +373,7 @@ CMD ["echo", "Hello, world!"]
373373
Type: 'AWS::ImageBuilder::ContainerRecipe',
374374
Properties: {
375375
Name: 'stack-containerrecipe-fcc21fd4',
376-
Version: '1.0.0',
376+
Version: '1.0.x',
377377
ContainerType: 'DOCKER',
378378
ParentImage: 'amazonlinux:latest',
379379
DockerfileTemplateUri:
@@ -402,7 +402,7 @@ CMD ["echo", "Hello, world!"]
402402
Type: 'AWS::ImageBuilder::ContainerRecipe',
403403
Properties: {
404404
Name: 'stack-containerrecipe-fcc21fd4',
405-
Version: '1.0.0',
405+
Version: '1.0.x',
406406
ContainerType: 'DOCKER',
407407
ParentImage: 'amazonlinux:latest',
408408
DockerfileTemplateUri: 's3://dockerfile-bucket-123456789012-us-east-1/dockerfile/Dockerfile',

packages/@aws-cdk/aws-imagebuilder-alpha/test/integ.all-parameters.container-recipe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ const parameterizedComponent = new imagebuilder.Component(stack, 'ParameterizedC
3232
{
3333
name: 'step1',
3434
action: imagebuilder.ComponentAction.EXECUTE_BASH,
35-
inputs: {
35+
inputs: imagebuilder.ComponentStepInputs.fromObject({
3636
commands: ['echo ${{ parameter1 }}', 'echo ${{ parameter2 }}'],
37-
},
37+
}),
3838
},
3939
],
4040
},

packages/@aws-cdk/aws-imagebuilder-alpha/test/integ.asset.container-recipe.js.snapshot/aws-cdk-imagebuilder-container-recipe-asset.assets.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-imagebuilder-alpha/test/integ.asset.container-recipe.js.snapshot/aws-cdk-imagebuilder-container-recipe-asset.template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"Service": "ECR"
3131
},
32-
"Version": "1.0.0"
32+
"Version": "1.0.x"
3333
}
3434
}
3535
},

packages/@aws-cdk/aws-imagebuilder-alpha/test/integ.asset.container-recipe.js.snapshot/manifest.json

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-imagebuilder-alpha/test/integ.asset.container-recipe.js.snapshot/tree.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)