@@ -14,6 +14,12 @@ import { ComponentConfiguration, IRecipeBase } from './recipe-base';
1414
1515const 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+ */
1723const 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 */
199219export 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
231256class 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 *
0 commit comments