DockerImageAsset
- class aws_cdk.aws_ecr_assets.DockerImageAsset(scope, id, *, directory, asset_name=None, build_args=None, build_secrets=None, build_ssh=None, cache_disabled=None, cache_from=None, cache_to=None, file=None, invalidation=None, network_mode=None, outputs=None, platform=None, target=None, extra_hash=None, exclude=None, follow_symlinks=None, ignore_mode=None)
Bases:
Construct
An asset that represents a Docker image.
The image will be created in build time and uploaded to an ECR repository.
- ExampleMetadata:
infused
Example:
from aws_cdk.aws_ecr_assets import DockerImageAsset asset = DockerImageAsset(self, "MyBuildImage", directory=path.join(__dirname, "my-image"), build_args={ "HTTP_PROXY": "http://10.20.30.2:1234" }, invalidation=ecr_assets.DockerImageAssetInvalidationOptions( build_args=False ) )
- Parameters:
scope (
Construct
) –id (
str
) –directory (
str
) – The directory where the Dockerfile is stored. Any directory inside with a name that matches the CDK output folder (cdk.out by default) will be excluded from the assetasset_name (
Optional
[str
]) – Unique identifier of the docker image asset and its potential revisions. Required if using AppScopedStagingSynthesizer. Default: - no asset namebuild_args (
Optional
[Mapping
[str
,str
]]) – Build args to pass to thedocker build
command. Since Docker build arguments are resolved before deployment, keys and values cannot refer to unresolved tokens (such aslambda.functionArn
orqueue.queueUrl
). Default: - no build args are passedbuild_secrets (
Optional
[Mapping
[str
,str
]]) – Build secrets. Docker BuildKit must be enabled to use build secrets. Default: - no build secretsbuild_ssh (
Optional
[str
]) – SSH agent socket or keys to pass to thedocker build
command. Docker BuildKit must be enabled to use the ssh flag Default: - no –ssh flagcache_disabled (
Optional
[bool
]) – Disable the cache and pass--no-cache
to thedocker build
command. Default: - cache is usedcache_from (
Optional
[Sequence
[Union
[DockerCacheOption
,Dict
[str
,Any
]]]]) – Cache from options to pass to thedocker build
command. Default: - no cache from options are passed to the build commandcache_to (
Union
[DockerCacheOption
,Dict
[str
,Any
],None
]) – Cache to options to pass to thedocker build
command. Default: - no cache to options are passed to the build commandfile (
Optional
[str
]) – Path to the Dockerfile (relative to the directory). Default: ‘Dockerfile’invalidation (
Union
[DockerImageAssetInvalidationOptions
,Dict
[str
,Any
],None
]) – Options to control which parameters are used to invalidate the asset hash. Default: - hash all parametersnetwork_mode (
Optional
[NetworkMode
]) – Networking mode for the RUN commands during build. Support docker API 1.25+. Default: - no networking mode specified (the default networking modeNetworkMode.DEFAULT
will be used)outputs (
Optional
[Sequence
[str
]]) – Outputs to pass to thedocker build
command. Default: - no outputs are passed to the build command (default outputs are used)platform (
Optional
[Platform
]) – Platform to build for. Requires Docker Buildx. Default: - no platform specified (the current machine architecture will be used)target (
Optional
[str
]) – Docker target to build to. Default: - no targetextra_hash (
Optional
[str
]) – Extra information to encode into the fingerprint (e.g. build instructions and other inputs). Default: - hash is only based on source contentexclude (
Optional
[Sequence
[str
]]) – File paths matching the patterns will be excluded. SeeignoreMode
to set the matching behavior. Has no effect on Assets bundled using thebundling
property. Default: - nothing is excludedfollow_symlinks (
Optional
[SymlinkFollowMode
]) – A strategy for how to handle symlinks. Default: SymlinkFollowMode.NEVERignore_mode (
Optional
[IgnoreMode
]) – The ignore behavior to use forexclude
patterns. Default: IgnoreMode.GLOB
Methods
- add_resource_metadata(resource, resource_property)
Adds CloudFormation template metadata to the specified resource with information that indicates which resource property is mapped to this local asset.
This can be used by tools such as SAM CLI to provide local experience such as local invocation and debugging of Lambda functions.
Asset metadata will only be included if the stack is synthesized with the “aws:cdk:enable-asset-metadata” context key defined, which is the default behavior when synthesizing via the CDK Toolkit.
- Parameters:
resource (
CfnResource
) – The CloudFormation resource which is using this asset [disable-awslint:ref-via-interface].resource_property (
str
) – The property name where this asset is referenced.
- See:
- Return type:
None
- to_string()
Returns a string representation of this construct.
- Return type:
str
Attributes
- asset_hash
A hash of this asset, which is available at construction time.
As this is a plain string, it can be used in construct IDs in order to enforce creation of a new resource when the content hash has changed.
- image_tag
The tag of this asset when it is uploaded to ECR.
The tag may differ from the assetHash if a stack synthesizer adds a dockerTagPrefix.
- image_uri
The full URI of the image (including a tag).
Use this reference to pull the asset.
- node
The tree node.
- repository
Repository where the image is stored.
Static Methods
- classmethod is_construct(x)
Checks if
x
is a construct.Use this method instead of
instanceof
to properly detectConstruct
instances, even when the construct library is symlinked.Explanation: in JavaScript, multiple copies of the
constructs
library on disk are seen as independent, completely different libraries. As a consequence, the classConstruct
in each copy of theconstructs
library is seen as a different class, and an instance of one class will not test asinstanceof
the other class.npm install
will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of theconstructs
library can be accidentally installed, andinstanceof
will behave unpredictably. It is safest to avoid usinginstanceof
, and using this type-testing method instead.- Parameters:
x (
Any
) – Any object.- Return type:
bool
- Returns:
true if
x
is an object created from a class which extendsConstruct
.