Skip to content
v2.278.0

DockerImageAssetOptions Struct ​

Options for DockerImageAsset.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_ecr_assets as ecr_assets } from 'aws-cdk-lib';

declare const networkMode: ecr_assets.NetworkMode;
declare const platform: ecr_assets.Platform;
const dockerImageAssetOptions: ecr_assets.DockerImageAssetOptions = {
  assetName: 'assetName',
  buildArgs: {
    buildArgsKey: 'buildArgs',
  },
  buildContexts: {
    buildContextsKey: 'buildContexts',
  },
  buildSecrets: {
    buildSecretsKey: 'buildSecrets',
  },
  buildSsh: 'buildSsh',
  cacheDisabled: false,
  cacheFrom: [{
    type: 'type',

    // the properties below are optional
    params: {
      paramsKey: 'params',
    },
  }],
  cacheTo: {
    type: 'type',

    // the properties below are optional
    params: {
      paramsKey: 'params',
    },
  },
  displayName: 'displayName',
  exclude: ['exclude'],
  extraHash: 'extraHash',
  file: 'file',
  followSymlinks: cdk.SymlinkFollowMode.NEVER,
  ignoreMode: cdk.IgnoreMode.GLOB,
  invalidation: {
    buildArgs: false,
    buildContexts: false,
    buildSecrets: false,
    buildSsh: false,
    extraHash: false,
    file: false,
    networkMode: false,
    outputs: false,
    platform: false,
    repositoryName: false,
    target: false,
  },
  networkMode: networkMode,
  outputs: ['outputs'],
  platform: platform,
  target: 'target',
};
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk
from aws_cdk import aws_ecr_assets as ecr_assets

# network_mode: ecr_assets.NetworkMode
# platform: ecr_assets.Platform

docker_image_asset_options = ecr_assets.DockerImageAssetOptions(
    asset_name="assetName",
    build_args={
        "build_args_key": "buildArgs"
    },
    build_contexts={
        "build_contexts_key": "buildContexts"
    },
    build_secrets={
        "build_secrets_key": "buildSecrets"
    },
    build_ssh="buildSsh",
    cache_disabled=False,
    cache_from=[ecr_assets.DockerCacheOption(
        type="type",

        # the properties below are optional
        params={
            "params_key": "params"
        }
    )],
    cache_to=ecr_assets.DockerCacheOption(
        type="type",

        # the properties below are optional
        params={
            "params_key": "params"
        }
    ),
    display_name="displayName",
    exclude=["exclude"],
    extra_hash="extraHash",
    file="file",
    follow_symlinks=cdk.SymlinkFollowMode.NEVER,
    ignore_mode=cdk.IgnoreMode.GLOB,
    invalidation=ecr_assets.DockerImageAssetInvalidationOptions(
        build_args=False,
        build_contexts=False,
        build_secrets=False,
        build_ssh=False,
        extra_hash=False,
        file=False,
        network_mode=False,
        outputs=False,
        platform=False,
        repository_name=False,
        target=False
    ),
    network_mode=network_mode,
    outputs=["outputs"],
    platform=platform,
    target="target"
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.ecr.assets.*;

NetworkMode networkMode;
Platform platform;

DockerImageAssetOptions dockerImageAssetOptions = DockerImageAssetOptions.builder()
        .assetName("assetName")
        .buildArgs(Map.of(
                "buildArgsKey", "buildArgs"))
        .buildContexts(Map.of(
                "buildContextsKey", "buildContexts"))
        .buildSecrets(Map.of(
                "buildSecretsKey", "buildSecrets"))
        .buildSsh("buildSsh")
        .cacheDisabled(false)
        .cacheFrom(List.of(DockerCacheOption.builder()
                .type("type")

                // the properties below are optional
                .params(Map.of(
                        "paramsKey", "params"))
                .build()))
        .cacheTo(DockerCacheOption.builder()
                .type("type")

                // the properties below are optional
                .params(Map.of(
                        "paramsKey", "params"))
                .build())
        .displayName("displayName")
        .exclude(List.of("exclude"))
        .extraHash("extraHash")
        .file("file")
        .followSymlinks(SymlinkFollowMode.NEVER)
        .ignoreMode(IgnoreMode.GLOB)
        .invalidation(DockerImageAssetInvalidationOptions.builder()
                .buildArgs(false)
                .buildContexts(false)
                .buildSecrets(false)
                .buildSsh(false)
                .extraHash(false)
                .file(false)
                .networkMode(false)
                .outputs(false)
                .platform(false)
                .repositoryName(false)
                .target(false)
                .build())
        .networkMode(networkMode)
        .outputs(List.of("outputs"))
        .platform(platform)
        .target("target")
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK;
using Amazon.CDK.AWS.Ecr.Assets;

NetworkMode networkMode;
Platform platform;

var dockerImageAssetOptions = new DockerImageAssetOptions {
    AssetName = "assetName",
    BuildArgs = new Dictionary<string, string> {
        { "buildArgsKey", "buildArgs" }
    },
    BuildContexts = new Dictionary<string, string> {
        { "buildContextsKey", "buildContexts" }
    },
    BuildSecrets = new Dictionary<string, string> {
        { "buildSecretsKey", "buildSecrets" }
    },
    BuildSsh = "buildSsh",
    CacheDisabled = false,
    CacheFrom = new [] { new DockerCacheOption {
        Type = "type",

        // the properties below are optional
        Params = new Dictionary<string, string> {
            { "paramsKey", "params" }
        }
    } },
    CacheTo = new DockerCacheOption {
        Type = "type",

        // the properties below are optional
        Params = new Dictionary<string, string> {
            { "paramsKey", "params" }
        }
    },
    DisplayName = "displayName",
    Exclude = new [] { "exclude" },
    ExtraHash = "extraHash",
    File = "file",
    FollowSymlinks = SymlinkFollowMode.NEVER,
    IgnoreMode = IgnoreMode.GLOB,
    Invalidation = new DockerImageAssetInvalidationOptions {
        BuildArgs = false,
        BuildContexts = false,
        BuildSecrets = false,
        BuildSsh = false,
        ExtraHash = false,
        File = false,
        NetworkMode = false,
        Outputs = false,
        Platform = false,
        RepositoryName = false,
        Target = false
    },
    NetworkMode = networkMode,
    Outputs = new [] { "outputs" },
    Platform = platform,
    Target = "target"
};
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var networkMode NetworkMode
var platform Platform

dockerImageAssetOptions := &DockerImageAssetOptions{
	AssetName: jsii.String("assetName"),
	BuildArgs: map[string]*string{
		"buildArgsKey": jsii.String("buildArgs"),
	},
	BuildContexts: map[string]*string{
		"buildContextsKey": jsii.String("buildContexts"),
	},
	BuildSecrets: map[string]*string{
		"buildSecretsKey": jsii.String("buildSecrets"),
	},
	BuildSsh: jsii.String("buildSsh"),
	CacheDisabled: jsii.Boolean(false),
	CacheFrom: []DockerCacheOption{
		&DockerCacheOption{
			Type: jsii.String("type"),

			// the properties below are optional
			Params: map[string]*string{
				"paramsKey": jsii.String("params"),
			},
		},
	},
	CacheTo: &DockerCacheOption{
		Type: jsii.String("type"),

		// the properties below are optional
		Params: map[string]*string{
			"paramsKey": jsii.String("params"),
		},
	},
	DisplayName: jsii.String("displayName"),
	Exclude: []*string{
		jsii.String("exclude"),
	},
	ExtraHash: jsii.String("extraHash"),
	File: jsii.String("file"),
	FollowSymlinks: cdk.SymlinkFollowMode_NEVER,
	IgnoreMode: cdk.IgnoreMode_GLOB,
	Invalidation: &DockerImageAssetInvalidationOptions{
		BuildArgs: jsii.Boolean(false),
		BuildContexts: jsii.Boolean(false),
		BuildSecrets: jsii.Boolean(false),
		BuildSsh: jsii.Boolean(false),
		ExtraHash: jsii.Boolean(false),
		File: jsii.Boolean(false),
		NetworkMode: jsii.Boolean(false),
		Outputs: jsii.Boolean(false),
		Platform: jsii.Boolean(false),
		RepositoryName: jsii.Boolean(false),
		Target: jsii.Boolean(false),
	},
	NetworkMode: networkMode,
	Outputs: []*string{
		jsii.String("outputs"),
	},
	Platform: platform,
	Target: jsii.String("target"),
}

Properties ​

assetNameoptionalstringasset_nameoptionalstrassetNameoptionalStringAssetNameoptionalstringAssetNameoptional*string #
Unique identifier of the docker image asset and its potential revisions.

Default: no asset name

Required if using AppScopedStagingSynthesizer.

buildArgsoptional{ [key: string]: string }build_argsoptionaltyping.Mapping[str, str]buildArgsoptionalMap<String, String>BuildArgsoptionalIDictionary<string, string>BuildArgsoptional*map[string]*string #
Build args to pass to the `docker build` command.

Default: no build args are passed

Since Docker build arguments are resolved before deployment, keys and values cannot refer to unresolved tokens (such as lambda.functionArn or queue.queueUrl).

buildContextsoptional{ [key: string]: string }build_contextsoptionaltyping.Mapping[str, str]buildContextsoptionalMap<String, String>BuildContextsoptionalIDictionary<string, string>BuildContextsoptional*map[string]*string #
Build contexts to pass to the `docker build` command.

Default: no additional build contexts

notes

Build contexts can be used to specify additional directories or images to use during the build. Each entry specifies a named build context and its source (a directory path, a URL, or a docker image).

Since Docker build contexts are resolved before deployment, keys and values cannot refer to unresolved tokens (such as lambda.functionArn or queue.queueUrl).

buildSecretsoptional{ [key: string]: string }build_secretsoptionaltyping.Mapping[str, str]buildSecretsoptionalMap<String, String>BuildSecretsoptionalIDictionary<string, string>BuildSecretsoptional*map[string]*string #
Build secrets.

Default: no build secrets

Docker BuildKit must be enabled to use build secrets.

example
ts
import { DockerBuildSecret } from 'aws-cdk-lib';

const buildSecrets = {
  'MY_SECRET': DockerBuildSecret.fromSrc('file.txt')
};
buildSshoptionalstringbuild_sshoptionalstrbuildSshoptionalStringBuildSshoptionalstringBuildSshoptional*string #
SSH agent socket or keys to pass to the `docker build` command.

Default: no --ssh flag

Docker BuildKit must be enabled to use the ssh flag

cacheDisabledoptionalbooleancache_disabledoptionalboolcacheDisabledoptionalBooleanCacheDisabledoptionalboolCacheDisabledoptional*bool #
Disable the cache and pass `--no-cache` to the `docker build` command.

Default: cache is used

cacheFromoptionalDockerCacheOption[]cache_fromoptionaltyping.List[DockerCacheOption]cacheFromoptionalList<DockerCacheOption>CacheFromoptionalDockerCacheOption[]CacheFromoptional*[]DockerCacheOption #
Cache from options to pass to the `docker build` command.

Default: no cache from options are passed to the build command

cacheTooptionalDockerCacheOptioncache_tooptionalDockerCacheOptioncacheTooptionalDockerCacheOptionCacheTooptionalDockerCacheOptionCacheTooptionalDockerCacheOption #
Cache to options to pass to the `docker build` command.

Default: no cache to options are passed to the build command

displayNameoptionalstringdisplay_nameoptionalstrdisplayNameoptionalStringDisplayNameoptionalstringDisplayNameoptional*string #
A display name for this asset.

Default: Stack-relative construct path

notes

If supplied, the display name will be used in locations where the asset identifier is printed, like in the CLI progress information. If the same asset is added multiple times, the display name of the first occurrence is used.

If assetName is given, it will also be used as the default displayName. Otherwise, the default is the construct path of the ImageAsset construct, with respect to the enclosing stack. If the asset is produced by a construct helper function (such as lambda.Code.fromAssetImage()), this will look like MyFunction/AssetImage.

We use the stack-relative construct path so that in the common case where you have multiple stacks with the same asset, we won't show something like /MyBetaStack/MyFunction/Code when you are actually deploying to production.

excludeoptionalstring[]excludeoptionaltyping.List[str]excludeoptionalList<String>Excludeoptionalstring[]Excludeoptional*[]*string #
File paths matching the patterns will be excluded. See `ignoreMode` to set the matching behavior.

Default: nothing is excluded

notes

Without bundling ​

When used without the bundling property, the asset is just a regular file copy operation. In that case, this controls the files that will be included in the copy. Files matching the exclude patterns will not be included in the copy.

With bundling ​

When used with the bundling property, the asset is produced by a bundling operation. In that case, the value of exclude is only meaningful if the assetHashType is set to AssetHashType.SOURCE, and ignored for other asset hash types. The exclude patterns will be used to determine which files contribute to the asset, and the bundling command is skipped if the source files have not changed since the last bundling operation.

NOTE: The bundling operation still has access to all files in the source path, regardless of the exclude patterns. It is your responsibility to ensure the exclude pattern accurately matches the files the bundling operation will actually access and base its final output on.

For OUTPUT or CUSTOM asset hash types, the exclude pattern is ignored.

extraHashoptionalstringextra_hashoptionalstrextraHashoptionalStringExtraHashoptionalstringExtraHashoptional*string #
Extra information to encode into the fingerprint (e.g. build instructions and other inputs).

Default: hash is only based on the file fingerprint

fileoptionalstringfileoptionalstrfileoptionalStringFileoptionalstringFileoptional*string = 'Dockerfile' #
Path to the Dockerfile (relative to the directory).
ignoreModeoptionalIgnoreModeignore_modeoptionalIgnoreModeignoreModeoptionalIgnoreModeIgnoreModeoptionalIgnoreModeIgnoreModeoptionalIgnoreMode #
What syntax the `exclude` patterns are written in.

Default: IgnoreMode.GLOB for file assets, IgnoreMode.DOCKER for image assets (requires that the @aws-cdk/aws-ecr-assets:dockerIgnoreSupport feature flag is set, which is recommended)

Options to control which parameters are used to invalidate the asset hash.

Default: hash all parameters

networkModeoptionalNetworkModenetwork_modeoptionalNetworkModenetworkModeoptionalNetworkModeNetworkModeoptionalNetworkModeNetworkModeoptionalNetworkMode #
Networking mode for the RUN commands during build.

Default: no networking mode specified (the default networking mode NetworkMode.DEFAULT will be used)

Support docker API 1.25+.

outputsoptionalstring[]outputsoptionaltyping.List[str]outputsoptionalList<String>Outputsoptionalstring[]Outputsoptional*[]*string #
Outputs to pass to the `docker build` command.

Default: no outputs are passed to the build command (default outputs are used)

platformoptionalPlatformplatformoptionalPlatformplatformoptionalPlatformPlatformoptionalPlatformPlatformoptionalPlatform #
Platform to build for.

Default: no platform specified (the current machine architecture will be used)

Requires Docker Buildx.

targetoptionalstringtargetoptionalstrtargetoptionalStringTargetoptionalstringTargetoptional*string #
Docker target to build to.

Default: no target