Skip to content

Commit 5ca5297

Browse files
author
Tarun Belani
committed
Addressed review comments
1 parent 4aea8e6 commit 5ca5297

11 files changed

+233
-204
lines changed

packages/@aws-cdk/aws-imagebuilder-alpha/README.md

Lines changed: 175 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,181 @@ const imageRecipe = new imagebuilder.ImageRecipe(this, 'TaggedImageRecipe', {
232232
});
233233
```
234234

235+
### Container Recipe
236+
237+
A container recipe is similar to an image recipe but specifically for container images. It defines the base container
238+
image and components applied to produce the desired configuration for the output container image. Container recipes work
239+
with Docker images from DockerHub, Amazon ECR, or Amazon-managed container images as starting points.
240+
241+
#### Container Recipe Basic Usage
242+
243+
Create a container recipe with the required base image and target repository:
244+
245+
```ts
246+
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'MyContainerRecipe', {
247+
baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
248+
targetRepository: imagebuilder.Repository.fromEcr(
249+
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
250+
)
251+
});
252+
```
253+
254+
#### Container Recipe Base Images
255+
256+
##### DockerHub Images
257+
258+
Using public Docker Hub images:
259+
260+
```ts
261+
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'DockerHubContainerRecipe', {
262+
baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
263+
targetRepository: imagebuilder.Repository.fromEcr(
264+
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
265+
)
266+
});
267+
```
268+
269+
##### ECR Images
270+
271+
Using images from your own ECR repositories:
272+
273+
```ts
274+
const sourceRepo = ecr.Repository.fromRepositoryName(this, 'SourceRepo', 'my-base-image');
275+
const targetRepo = ecr.Repository.fromRepositoryName(this, 'TargetRepo', 'my-container-repo');
276+
277+
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'EcrContainerRecipe', {
278+
baseImage: imagebuilder.BaseContainerImage.fromEcr(sourceRepo, '1.0.0'),
279+
targetRepository: imagebuilder.Repository.fromEcr(targetRepo)
280+
});
281+
```
282+
283+
##### ECR Public Images
284+
285+
Using images from Amazon ECR Public:
286+
287+
```ts
288+
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'EcrPublicContainerRecipe', {
289+
baseImage: imagebuilder.BaseContainerImage.fromEcrPublic('amazonlinux', 'amazonlinux', '2023'),
290+
targetRepository: imagebuilder.Repository.fromEcr(
291+
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
292+
)
293+
});
294+
```
295+
296+
#### Container Recipe Components
297+
298+
##### Custom Components in Container Recipes
299+
300+
Add your own components to the container recipe:
301+
302+
```ts
303+
const customComponent = new imagebuilder.Component(this, 'MyComponent', {
304+
platform: imagebuilder.Platform.LINUX,
305+
data: imagebuilder.ComponentData.fromJsonObject({
306+
schemaVersion: imagebuilder.ComponentSchemaVersion.V1_0,
307+
phases: [
308+
{
309+
name: imagebuilder.ComponentPhaseName.BUILD,
310+
steps: [
311+
{
312+
name: 'install-app',
313+
action: imagebuilder.ComponentAction.EXECUTE_BASH,
314+
inputs: {
315+
commands: ['yum install -y my-container-application']
316+
}
317+
}
318+
]
319+
}
320+
]
321+
})
322+
});
323+
324+
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'ComponentContainerRecipe', {
325+
baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
326+
targetRepository: imagebuilder.Repository.fromEcr(
327+
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
328+
),
329+
components: [
330+
{
331+
component: customComponent
332+
}
333+
]
334+
});
335+
```
336+
337+
##### AWS-Managed Components in Container Recipes
338+
339+
Use pre-built AWS components:
340+
341+
```ts
342+
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'AwsManagedContainerRecipe', {
343+
baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
344+
targetRepository: imagebuilder.Repository.fromEcr(
345+
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
346+
),
347+
components: [
348+
{
349+
component: imagebuilder.AwsManagedComponent.updateOS(this, 'UpdateOS', {
350+
platform: imagebuilder.Platform.LINUX
351+
})
352+
},
353+
{
354+
component: imagebuilder.AwsManagedComponent.awsCliV2(this, 'AwsCli', {
355+
platform: imagebuilder.Platform.LINUX
356+
})
357+
}
358+
]
359+
});
360+
```
361+
362+
#### Container Recipe Configuration
363+
364+
##### Custom Dockerfile
365+
366+
Provide your own Dockerfile template:
367+
368+
```ts
369+
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'CustomDockerfileContainerRecipe', {
370+
baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
371+
targetRepository: imagebuilder.Repository.fromEcr(
372+
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
373+
),
374+
dockerfile: imagebuilder.DockerfileData.fromInline(`
375+
FROM {{{ imagebuilder:parentImage }}}
376+
CMD ["echo", "Hello, world!"]
377+
{{{ imagebuilder:environments }}}
378+
{{{ imagebuilder:components }}}
379+
`)
380+
});
381+
```
382+
383+
##### Instance Configuration
384+
385+
Configure the build instance:
386+
387+
```ts
388+
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'InstanceConfigContainerRecipe', {
389+
baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
390+
targetRepository: imagebuilder.Repository.fromEcr(
391+
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
392+
),
393+
// Custom ECS-optimized AMI for building
394+
instanceImage: imagebuilder.ContainerInstanceImage.fromSsmParameterName(
395+
'/aws/service/ecs/optimized-ami/amazon-linux-2023/recommended/image_id'
396+
),
397+
// Additional storage for build process
398+
instanceBlockDevices: [
399+
{
400+
deviceName: '/dev/xvda',
401+
volume: ec2.BlockDeviceVolume.ebs(50, {
402+
encrypted: true,
403+
volumeType: ec2.EbsDeviceVolumeType.GENERAL_PURPOSE_SSD_GP3
404+
})
405+
}
406+
]
407+
});
408+
```
409+
235410
### Component
236411

237412
A component defines the sequence of steps required to customize an instance during image creation (build component) or
@@ -476,181 +651,6 @@ const marketplaceComponent = imagebuilder.AwsMarketplaceComponent.fromAwsMarketp
476651
);
477652
```
478653

479-
### Container Recipe
480-
481-
A container recipe is similar to an image recipe but specifically for container images. It defines the base container
482-
image and components applied to produce the desired configuration for the output container image. Container recipes work
483-
with Docker images from DockerHub, Amazon ECR, or Amazon-managed container images as starting points.
484-
485-
#### Container Recipe Basic Usage
486-
487-
Create a container recipe with the required base image and target repository:
488-
489-
```ts
490-
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'MyContainerRecipe', {
491-
baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
492-
targetRepository: imagebuilder.Repository.fromEcr(
493-
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
494-
)
495-
});
496-
```
497-
498-
#### Container Recipe Base Images
499-
500-
##### DockerHub Images
501-
502-
Using public Docker Hub images:
503-
504-
```ts
505-
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'DockerHubContainerRecipe', {
506-
baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
507-
targetRepository: imagebuilder.Repository.fromEcr(
508-
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
509-
)
510-
});
511-
```
512-
513-
##### ECR Images
514-
515-
Using images from your own ECR repositories:
516-
517-
```ts
518-
const sourceRepo = ecr.Repository.fromRepositoryName(this, 'SourceRepo', 'my-base-image');
519-
const targetRepo = ecr.Repository.fromRepositoryName(this, 'TargetRepo', 'my-container-repo');
520-
521-
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'EcrContainerRecipe', {
522-
baseImage: imagebuilder.BaseContainerImage.fromEcr(sourceRepo, '1.0.0'),
523-
targetRepository: imagebuilder.Repository.fromEcr(targetRepo)
524-
});
525-
```
526-
527-
##### ECR Public Images
528-
529-
Using images from Amazon ECR Public:
530-
531-
```ts
532-
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'EcrPublicContainerRecipe', {
533-
baseImage: imagebuilder.BaseContainerImage.fromEcrPublic('amazonlinux', 'amazonlinux', '2023'),
534-
targetRepository: imagebuilder.Repository.fromEcr(
535-
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
536-
)
537-
});
538-
```
539-
540-
#### Container Recipe Components
541-
542-
##### Custom Components in Container Recipes
543-
544-
Add your own components to the container recipe:
545-
546-
```ts
547-
const customComponent = new imagebuilder.Component(this, 'MyComponent', {
548-
platform: imagebuilder.Platform.LINUX,
549-
data: imagebuilder.ComponentData.fromJsonObject({
550-
schemaVersion: imagebuilder.ComponentSchemaVersion.V1_0,
551-
phases: [
552-
{
553-
name: imagebuilder.ComponentPhaseName.BUILD,
554-
steps: [
555-
{
556-
name: 'install-app',
557-
action: imagebuilder.ComponentAction.EXECUTE_BASH,
558-
inputs: {
559-
commands: ['yum install -y my-container-application']
560-
}
561-
}
562-
]
563-
}
564-
]
565-
})
566-
});
567-
568-
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'ComponentContainerRecipe', {
569-
baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
570-
targetRepository: imagebuilder.Repository.fromEcr(
571-
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
572-
),
573-
components: [
574-
{
575-
component: customComponent
576-
}
577-
]
578-
});
579-
```
580-
581-
##### AWS-Managed Components in Container Recipes
582-
583-
Use pre-built AWS components:
584-
585-
```ts
586-
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'AwsManagedContainerRecipe', {
587-
baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
588-
targetRepository: imagebuilder.Repository.fromEcr(
589-
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
590-
),
591-
components: [
592-
{
593-
component: imagebuilder.AwsManagedComponent.updateOS(this, 'UpdateOS', {
594-
platform: imagebuilder.Platform.LINUX
595-
})
596-
},
597-
{
598-
component: imagebuilder.AwsManagedComponent.awsCliV2(this, 'AwsCli', {
599-
platform: imagebuilder.Platform.LINUX
600-
})
601-
}
602-
]
603-
});
604-
```
605-
606-
#### Container Recipe Configuration
607-
608-
##### Custom Dockerfile
609-
610-
Provide your own Dockerfile template:
611-
612-
```ts
613-
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'CustomDockerfileContainerRecipe', {
614-
baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
615-
targetRepository: imagebuilder.Repository.fromEcr(
616-
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
617-
),
618-
dockerfile: imagebuilder.DockerfileData.fromInline(`
619-
FROM {{{ imagebuilder:parentImage }}}
620-
CMD ["echo", "Hello, world!"]
621-
{{{ imagebuilder:environments }}}
622-
{{{ imagebuilder:components }}}
623-
`)
624-
});
625-
```
626-
627-
##### Instance Configuration
628-
629-
Configure the build instance:
630-
631-
```ts
632-
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'InstanceConfigContainerRecipe', {
633-
baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
634-
targetRepository: imagebuilder.Repository.fromEcr(
635-
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
636-
),
637-
// Custom ECS-optimized AMI for building
638-
instanceImage: imagebuilder.ContainerInstanceImage.fromSsmParameterName(
639-
'/aws/service/ecs/optimized-ami/amazon-linux-2023/recommended/image_id'
640-
),
641-
// Additional storage for build process
642-
instanceBlockDevices: [
643-
{
644-
deviceName: '/dev/xvda',
645-
volume: ec2.BlockDeviceVolume.ebs(50, {
646-
encrypted: true,
647-
volumeType: ec2.EbsDeviceVolumeType.GENERAL_PURPOSE_SSD_GP3
648-
})
649-
}
650-
]
651-
});
652-
```
653-
654654
### Infrastructure Configuration
655655

656656
Infrastructure configuration defines the compute resources and environment settings used during the image building

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class BaseImage {
2929
* @param parameter The SSM parameter to use as the base image
3030
*/
3131
public static fromSsmParameter(parameter: ssm.IParameter): BaseImage {
32-
return this.fromSsmParameterName(parameter.parameterArn);
32+
return new BaseImage(`ssm:${parameter.parameterArn}`);
3333
}
3434

3535
/**
@@ -140,7 +140,7 @@ export class ContainerInstanceImage {
140140
}
141141

142142
/**
143-
* The name of the SSM parameter used to launch the instance for building the container image
143+
* The ARN of the SSM parameter used to launch the instance for building the container image
144144
*
145145
* @param parameterName The name of the SSM parameter used as the container instance image
146146
*/
@@ -168,4 +168,3 @@ export class ContainerInstanceImage {
168168
this.image = image;
169169
}
170170
}
171-

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export class ImageRecipe extends ImageRecipeBase {
257257
public static fromImageRecipeAttributes(scope: Construct, id: string, attrs: ImageRecipeAttributes): IImageRecipe {
258258
if (!attrs.imageRecipeArn && !attrs.imageRecipeName) {
259259
throw new cdk.ValidationError(
260-
'either imageRecipeArn or imageRecipeName must be provided to import a image recipe',
260+
'either imageRecipeArn or imageRecipeName must be provided to import an image recipe',
261261
scope,
262262
);
263263
}

0 commit comments

Comments
 (0)