@@ -36,6 +36,181 @@ EC2 Image Builder supports AWS-managed components for common tasks, AWS Marketpl
3636that you create. Components run during specific workflow phases: build and validate phases during the build stage, and
3737test phase during the test stage.
3838
39+ ### Container Recipe
40+
41+ A container recipe is similar to an image recipe but specifically for container images. It defines the base container
42+ image and components applied to produce the desired configuration for the output container image. Container recipes work
43+ with Docker images from DockerHub, Amazon ECR, or Amazon-managed container images as starting points.
44+
45+ #### Container Recipe Basic Usage
46+
47+ Create a container recipe with the required base image and target repository:
48+
49+ ``` ts
50+ const containerRecipe = new imagebuilder .ContainerRecipe (this , ' MyContainerRecipe' , {
51+ baseImage: imagebuilder .BaseContainerImage .fromDockerHub (' amazonlinux' , ' latest' ),
52+ targetRepository: imagebuilder .Repository .fromEcr (
53+ ecr .Repository .fromRepositoryName (this , ' Repository' , ' my-container-repo' )
54+ )
55+ });
56+ ```
57+
58+ #### Container Recipe Base Images
59+
60+ ##### DockerHub Images
61+
62+ Using public Docker Hub images:
63+
64+ ``` ts
65+ const containerRecipe = new imagebuilder .ContainerRecipe (this , ' DockerHubContainerRecipe' , {
66+ baseImage: imagebuilder .BaseContainerImage .fromDockerHub (' amazonlinux' , ' latest' ),
67+ targetRepository: imagebuilder .Repository .fromEcr (
68+ ecr .Repository .fromRepositoryName (this , ' Repository' , ' my-container-repo' )
69+ )
70+ });
71+ ```
72+
73+ ##### ECR Images
74+
75+ Using images from your own ECR repositories:
76+
77+ ``` ts
78+ const sourceRepo = ecr .Repository .fromRepositoryName (this , ' SourceRepo' , ' my-base-image' );
79+ const targetRepo = ecr .Repository .fromRepositoryName (this , ' TargetRepo' , ' my-container-repo' );
80+
81+ const containerRecipe = new imagebuilder .ContainerRecipe (this , ' EcrContainerRecipe' , {
82+ baseImage: imagebuilder .BaseContainerImage .fromEcr (sourceRepo , ' 1.0.0' ),
83+ targetRepository: imagebuilder .Repository .fromEcr (targetRepo )
84+ });
85+ ```
86+
87+ ##### ECR Public Images
88+
89+ Using images from Amazon ECR Public:
90+
91+ ``` ts
92+ const containerRecipe = new imagebuilder .ContainerRecipe (this , ' EcrPublicContainerRecipe' , {
93+ baseImage: imagebuilder .BaseContainerImage .fromEcrPublic (' amazonlinux' , ' amazonlinux' , ' 2023' ),
94+ targetRepository: imagebuilder .Repository .fromEcr (
95+ ecr .Repository .fromRepositoryName (this , ' Repository' , ' my-container-repo' )
96+ )
97+ });
98+ ```
99+
100+ #### Container Recipe Components
101+
102+ ##### Custom Components in Container Recipes
103+
104+ Add your own components to the container recipe:
105+
106+ ``` ts
107+ const customComponent = new imagebuilder .Component (this , ' MyComponent' , {
108+ platform: imagebuilder .Platform .LINUX ,
109+ data: imagebuilder .ComponentData .fromJsonObject ({
110+ schemaVersion: imagebuilder .ComponentSchemaVersion .V1_0 ,
111+ phases: [
112+ {
113+ name: imagebuilder .ComponentPhaseName .BUILD ,
114+ steps: [
115+ {
116+ name: ' install-app' ,
117+ action: imagebuilder .ComponentAction .EXECUTE_BASH ,
118+ inputs: {
119+ commands: [' yum install -y my-container-application' ]
120+ }
121+ }
122+ ]
123+ }
124+ ]
125+ })
126+ });
127+
128+ const containerRecipe = new imagebuilder .ContainerRecipe (this , ' ComponentContainerRecipe' , {
129+ baseImage: imagebuilder .BaseContainerImage .fromDockerHub (' amazonlinux' , ' latest' ),
130+ targetRepository: imagebuilder .Repository .fromEcr (
131+ ecr .Repository .fromRepositoryName (this , ' Repository' , ' my-container-repo' )
132+ ),
133+ components: [
134+ {
135+ component: customComponent
136+ }
137+ ]
138+ });
139+ ```
140+
141+ ##### AWS-Managed Components in Container Recipes
142+
143+ Use pre-built AWS components:
144+
145+ ``` ts
146+ const containerRecipe = new imagebuilder .ContainerRecipe (this , ' AwsManagedContainerRecipe' , {
147+ baseImage: imagebuilder .BaseContainerImage .fromDockerHub (' amazonlinux' , ' latest' ),
148+ targetRepository: imagebuilder .Repository .fromEcr (
149+ ecr .Repository .fromRepositoryName (this , ' Repository' , ' my-container-repo' )
150+ ),
151+ components: [
152+ {
153+ component: imagebuilder .AwsManagedComponent .updateOS (this , ' UpdateOS' , {
154+ platform: imagebuilder .Platform .LINUX
155+ })
156+ },
157+ {
158+ component: imagebuilder .AwsManagedComponent .awsCliV2 (this , ' AwsCli' , {
159+ platform: imagebuilder .Platform .LINUX
160+ })
161+ }
162+ ]
163+ });
164+ ```
165+
166+ #### Container Recipe Configuration
167+
168+ ##### Custom Dockerfile
169+
170+ Provide your own Dockerfile template:
171+
172+ ``` ts
173+ const containerRecipe = new imagebuilder .ContainerRecipe (this , ' CustomDockerfileContainerRecipe' , {
174+ baseImage: imagebuilder .BaseContainerImage .fromDockerHub (' amazonlinux' , ' latest' ),
175+ targetRepository: imagebuilder .Repository .fromEcr (
176+ ecr .Repository .fromRepositoryName (this , ' Repository' , ' my-container-repo' )
177+ ),
178+ dockerfile: imagebuilder .DockerfileData .fromInline (`
179+ FROM {{{ imagebuilder:parentImage }}}
180+ CMD ["echo", "Hello, world!"]
181+ {{{ imagebuilder:environments }}}
182+ {{{ imagebuilder:components }}}
183+ ` )
184+ });
185+ ```
186+
187+ ##### Instance Configuration
188+
189+ Configure the build instance:
190+
191+ ``` ts
192+ const containerRecipe = new imagebuilder .ContainerRecipe (this , ' InstanceConfigContainerRecipe' , {
193+ baseImage: imagebuilder .BaseContainerImage .fromDockerHub (' amazonlinux' , ' latest' ),
194+ targetRepository: imagebuilder .Repository .fromEcr (
195+ ecr .Repository .fromRepositoryName (this , ' Repository' , ' my-container-repo' )
196+ ),
197+ // Custom ECS-optimized AMI for building
198+ instanceImage: imagebuilder .ContainerInstanceImage .fromSsmParameterName (
199+ ' /aws/service/ecs/optimized-ami/amazon-linux-2023/recommended/image_id'
200+ ),
201+ // Additional storage for build process
202+ instanceBlockDevices: [
203+ {
204+ deviceName: ' /dev/xvda' ,
205+ volume: ec2 .BlockDeviceVolume .ebs (50 , {
206+ encrypted: true ,
207+ volumeType: ec2 .EbsDeviceVolumeType .GENERAL_PURPOSE_SSD_GP3
208+ })
209+ }
210+ ]
211+ });
212+ ```
213+
39214### Component
40215
41216A component defines the sequence of steps required to customize an instance during image creation (build component) or
0 commit comments