# DockerImageAssetProps

Props for DockerImageAssets.

Extends: [DockerImageAssetOptions](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets.DockerImageAssetOptions.html)
Used as props by: [DockerImageAsset](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets.DockerImageAsset.html)
Used as argument in: [DockerImage.fromAsset](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions_tasks.DockerImage.html#fromasset), [LinuxBuildImage.fromAsset](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.LinuxBuildImage.html#fromasset), MacBuildImage.fromAsset, WindowsBuildImage.fromAsset

- Source: [`aws-ecr-assets/lib/image-asset.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ecr-assets/lib/image-asset.ts#L376)

## Example

TypeScript:

```ts
import { DockerImageAsset } from 'aws-cdk-lib/aws-ecr-assets';

const asset = new DockerImageAsset(this, 'MyBuildImage', {
  directory: path.join(__dirname, 'my-image'),
  buildContexts: {
    mycontext: path.join(__dirname, 'path/to/context'),
    alpine: 'docker-image://alpine:latest',
  },
});
```

Python:

```python
from aws_cdk.aws_ecr_assets import DockerImageAsset

asset = DockerImageAsset(self, "MyBuildImage",
    directory=path.join(__dirname, "my-image"),
    build_contexts={
        "mycontext": path.join(__dirname, "path/to/context"),
        "alpine": "docker-image://alpine:latest"
    }
)
```

Java:

```java
import software.amazon.awscdk.services.ecr.assets.DockerImageAsset;

DockerImageAsset asset = DockerImageAsset.Builder.create(this, "MyBuildImage")
        .directory(join(__dirname, "my-image"))
        .buildContexts(Map.of(
                "mycontext", join(__dirname, "path/to/context"),
                "alpine", "docker-image://alpine:latest"))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Ecr.Assets;

var asset = new DockerImageAsset(this, "MyBuildImage", new DockerImageAssetProps {
    Directory = Join(__dirname, "my-image"),
    BuildContexts = new Dictionary<string, string> {
        { "mycontext", Join(__dirname, "path/to/context") },
        { "alpine", "docker-image://alpine:latest" }
    }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"

asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
	BuildContexts: map[string]*string{
		"mycontext": path.join(__dirname, jsii.String("path/to/context")),
		"alpine": jsii.String("docker-image://alpine:latest"),
	},
})
```

## Properties

- `assetName`: string — Unique identifier of the docker image asset and its potential revisions.

  **Default:** no asset name

  Required if using AppScopedStagingSynthesizer.

- `buildArgs`: { [key: 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`).

- `buildContexts`: { [key: string]: string } — Build contexts to pass to the `docker build` command.

  **Default:** no additional build contexts

  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`).

- `buildSecrets`: { [key: string]: string } — Build secrets.

  **Default:** no build secrets

  Docker BuildKit must be enabled to use build secrets.

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

  const buildSecrets = {
    'MY_SECRET': DockerBuildSecret.fromSrc('file.txt')
  };
  ```

- `buildSsh`: 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

- `cacheDisabled`: boolean — Disable the cache and pass `--no-cache` to the `docker build` command.

  **Default:** cache is used

- `cacheFrom`: [DockerCacheOption](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets.DockerCacheOption.html)[] — Cache from options to pass to the `docker build` command.

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

- `cacheTo`: [DockerCacheOption](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets.DockerCacheOption.html) — Cache to options to pass to the `docker build` command.

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

- `directory`: string (required) — 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 asset

- `displayName`: string — A display name for this asset.

  **Default:** Stack-relative construct path

  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.

- `exclude`: string[] — File paths matching the patterns will be excluded. See `ignoreMode` to set the matching behavior.

  **Default:** nothing is excluded

  ## 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.

- `extraHash`: string — Extra information to encode into the fingerprint (e.g. build instructions and other inputs).

  **Default:** hash is only based on the file fingerprint

- `file`: string = 'Dockerfile' — Path to the Dockerfile (relative to the directory).

- `followSymlinks`: [SymlinkFollowMode](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.SymlinkFollowMode.html) = SymlinkFollowMode.EXTERNAL — A strategy for how to handle symlinks.

  Symlinks may be copied, materialized or rejected. Note that if symlinks are
  copied they should be relative; absolute symlinks will lose their
  meaning if the cloud assembly is moved to another machine.

  ## Without bundling

  When used without the `bundling` property, the asset is just a regular file
  copy operation. In that case, symlinks are materialized or blocked with respect
  to the `sourcePath` directory as they are being copied.

  ## With bundling

  When used with the `bundling` property, the asset is produced by a
  bundling operation. In that case, the bundling command is fully
  in charge of producing a set of files in an output directory, and
  the `AssetStaging` construct will never affect symlink materialization.

  If the `assetHashType` is `AssetHashType.SOURCE`, this flag affects what
  the source hash is based on, and the recommended value is one of
  `SymlinkFollowMode.EXTERNAL` or `SymlinkFollowMode.BLOCK_EXTERNAL`.

  If the `SymlinkFollowMode.BLOCK_EXTERNAL` mode is used:
  - symlinks pointing outside the source tree will be blocked if using `AssetHashType.SOURCE`.
  - symlinks pointing outside the bundle output will be blocked.

- `ignoreMode`: [IgnoreMode](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IgnoreMode.html) — 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)

- `invalidation`: [DockerImageAssetInvalidationOptions](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets.DockerImageAssetInvalidationOptions.html) — Options to control which parameters are used to invalidate the asset hash.

  **Default:** hash all parameters

- `networkMode`: [NetworkMode](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets.NetworkMode.html) — 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+.

- `outputs`: string[] — Outputs to pass to the `docker build` command.

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

- `platform`: [Platform](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets.Platform.html) — Platform to build for.

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

  _Requires Docker Buildx_.

- `target`: string — Docker target to build to.

  **Default:** no target
