Experimental
@aws-cdk/aws-imagebuilder-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.
DockerfileData Class
Helper class for referencing and uploading dockerfile data for the container recipe.
| Stability | Experimental |
|---|---|
| Source | lib/container-recipe.ts |
Example
ts
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'CustomDockerfileContainerRecipe', {
baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
targetRepository: imagebuilder.Repository.fromEcr(
ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
),
dockerfile: imagebuilder.DockerfileData.fromInline(`
FROM {{{ imagebuilder:parentImage }}}
CMD ["echo", "Hello, world!"]
{{{ imagebuilder:environments }}}
{{{ imagebuilder:components }}}
`)
});
python
container_recipe = imagebuilder.ContainerRecipe(self, "CustomDockerfileContainerRecipe",
base_image=imagebuilder.BaseContainerImage.from_docker_hub("amazonlinux", "latest"),
target_repository=imagebuilder.Repository.from_ecr(
ecr.Repository.from_repository_name(self, "Repository", "my-container-repo")),
dockerfile=imagebuilder.DockerfileData.from_inline("""
FROM {{{ imagebuilder:parentImage }}}
CMD ["echo", "Hello, world!"]
{{{ imagebuilder:environments }}}
{{{ imagebuilder:components }}}
""")
)
java
ContainerRecipe containerRecipe = ContainerRecipe.Builder.create(this, "CustomDockerfileContainerRecipe")
.baseImage(BaseContainerImage.fromDockerHub("amazonlinux", "latest"))
.targetRepository(Repository.fromEcr(Repository.fromRepositoryName(this, "Repository", "my-container-repo")))
.dockerfile(DockerfileData.fromInline("\nFROM {{{ imagebuilder:parentImage }}}\nCMD [\"echo\", \"Hello, world!\"]\n{{{ imagebuilder:environments }}}\n{{{ imagebuilder:components }}}\n"))
.build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.ImageBuilder.Alpha
var containerRecipe = new ContainerRecipe(this, "CustomDockerfileContainerRecipe", new ContainerRecipeProps {
BaseImage = BaseContainerImage.FromDockerHub("amazonlinux", "latest"),
TargetRepository = Repository.FromEcr(Repository.FromRepositoryName(this, "Repository", "my-container-repo")),
Dockerfile = DockerfileData.FromInline(@"
FROM {{{ imagebuilder:parentImage }}}
CMD [""echo"", ""Hello, world!""]
{{{ imagebuilder:environments }}}
{{{ imagebuilder:components }}}
")
});
go
// Install: go get github.com/aws/aws-cdk-go/awsimagebuilderalpha/v2
containerRecipe := imagebuilder.NewContainerRecipe(this, jsii.String("CustomDockerfileContainerRecipe"), &ContainerRecipeProps{
BaseImage: imagebuilder.BaseContainerImage_*FromDockerHub(jsii.String("amazonlinux"), jsii.String("latest")),
TargetRepository: imagebuilder.Repository_*FromEcr(ecr.Repository_*FromRepositoryName(this, jsii.String("Repository"), jsii.String("my-container-repo"))),
Dockerfile: imagebuilder.DockerfileData_FromInline(jsii.String(`
FROM {{{ imagebuilder:parentImage }}}
CMD ["echo", "Hello, world!"]
{{{ imagebuilder:environments }}}
{{{ imagebuilder:components }}}
`)),
})
Initializer
ts
new DockerfileData()
python
DockerfileData()
java
new DockerfileData()
csharp
new DockerfileData()
go
NewDockerfileData()
Methods
fromAsset(scope: Construct, id: string, path: string, options?: AssetOptions): S3DockerfileData@staticmethod def from_asset(scope: Construct, id: str, path: str, options: typing.Optional[AssetOptions] = None) -> S3DockerfileDatapublic static S3DockerfileData fromAsset(Construct scope, String id, String path, AssetOptions options)public static S3DockerfileData FromAsset(Construct scope, string id, string path, AssetOptions? options = null)func FromAsset(Scope Construct, Id *string, Path *string, Options AssetOptions) S3DockerfileData static #Uploads dockerfile data from a local file to S3 to use as the dockerfile data.
4 parameters
Parameters
scopescopescopescopeScope— The construct scope.ididididId— Identifier of the construct.pathpathpathpathPath— The local path to the dockerfile data file.optionsoptionsoptionsoptionsOptions— S3 asset upload options.
fromInline(data: string): DockerfileData // chainable@staticmethod def from_inline(data: str) -> DockerfileDatapublic static DockerfileData fromInline(String data)public static DockerfileData FromInline(string data)func FromInline(Data *string) DockerfileData static #Uses an inline string as the dockerfile data.
1 parameter
Parameters
datadatadatadataData— An inline string representing the dockerfile data.
fromS3(bucket: IBucket, key: string): S3DockerfileData@staticmethod def from_s3(bucket: IBucket, key: str) -> S3DockerfileDatapublic static S3DockerfileData fromS3(IBucket bucket, String key)public static S3DockerfileData FromS3(IBucket bucket, string key)func FromS3(Bucket IBucket, Key *string) S3DockerfileData static #References dockerfile data from a pre-existing S3 object.
2 parameters
Parameters
bucketbucketbucketbucketBucket— The S3 bucket where the dockerfile data is stored.keykeykeykeyKey— The S3 key of the dockerfile data file.
render(): DockerfileTemplateConfigdef render(self, ) -> DockerfileTemplateConfigpublic DockerfileTemplateConfig render()public DockerfileTemplateConfig Render()func Render() DockerfileTemplateConfig #The rendered Dockerfile value, for use in CloudFormation.
- For inline dockerfiles, dockerfileTemplateData is the Dockerfile template text
- For S3-backed dockerfiles, dockerfileTemplateUri is the S3 URL