awsecrassets

package
v2.115.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 8 Imported by: 6

README

AWS CDK Docker Image Assets

This module allows bundling Docker images as assets.

Images from Dockerfile

Images are built from a local Docker context directory (with a Dockerfile), uploaded to Amazon Elastic Container Registry (ECR) by the CDK toolkit and/or your app's CI/CD pipeline, and can be naturally referenced in your CDK app.

import "github.com/aws/aws-cdk-go/awscdk"


asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
})

The directory my-image must include a Dockerfile.

This will instruct the toolkit to build a Docker image from my-image, push it to an Amazon ECR repository and wire the name of the repository as CloudFormation parameters to your stack.

By default, all files in the given directory will be copied into the docker build context. If there is a large directory that you know you definitely don't need in the build context you can improve the performance by adding the names of files and directories to ignore to a file called .dockerignore, or pass them via the exclude property. If both are available, the patterns found in exclude are appended to the patterns found in .dockerignore.

The ignoreMode property controls how the set of ignore patterns is interpreted. The recommended setting for Docker image assets is IgnoreMode.DOCKER. If the context flag @aws-cdk/aws-ecr-assets:dockerIgnoreSupport is set to true in your cdk.json (this is by default for new projects, but must be set manually for old projects) then IgnoreMode.DOCKER is the default and you don't need to configure it on the asset itself.

Use asset.imageUri to reference the image. It includes both the ECR image URL and tag.

Use asset.imageTag to reference only the image tag.

You can optionally pass build args to the docker build command by specifying the buildArgs property. It is recommended to skip hashing of buildArgs for values that can change between different machines to maintain a consistent asset hash.

Additionally, you can supply buildSecrets. Your system must have Buildkit enabled, see https://docs.docker.com/build/buildkit/.

SSH agent sockets or keys may be passed to docker build via buildSsh.

import "github.com/aws/aws-cdk-go/awscdk"


asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
	BuildArgs: map[string]*string{
		"HTTP_PROXY": jsii.String("http://10.20.30.2:1234"),
	},
	Invalidation: &DockerImageAssetInvalidationOptions{
		BuildArgs: jsii.Boolean(false),
	},
})

You can optionally pass a target to the docker build command by specifying the target property:

import "github.com/aws/aws-cdk-go/awscdk"


asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
	Target: jsii.String("a-target"),
})

You can optionally pass networking mode to the docker build command by specifying the networkMode property:

import "github.com/aws/aws-cdk-go/awscdk"


asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
	NetworkMode: awscdk.NetworkMode_HOST(),
})

You can optionally pass an alternate platform to the docker build command by specifying the platform property:

import "github.com/aws/aws-cdk-go/awscdk"


asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
	Platform: awscdk.Platform_LINUX_ARM64(),
})

You can optionally pass an array of outputs to the docker build command by specifying the outputs property:

import "github.com/aws/aws-cdk-go/awscdk"


asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
	Outputs: []*string{
		jsii.String("type=local,dest=out"),
	},
})

You can optionally pass cache from and cache to options to cache images:

import "github.com/aws/aws-cdk-go/awscdk"


asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
	CacheFrom: []dockerCacheOption{
		&dockerCacheOption{
			Type: jsii.String("registry"),
			Params: map[string]*string{
				"ref": jsii.String("ghcr.io/myorg/myimage:cache"),
			},
		},
	},
	CacheTo: &dockerCacheOption{
		Type: jsii.String("registry"),
		Params: map[string]*string{
			"ref": jsii.String("ghcr.io/myorg/myimage:cache"),
			"mode": jsii.String("max"),
			"compression": jsii.String("zstd"),
		},
	},
})

Images from Tarball

Images are loaded from a local tarball, uploaded to ECR by the CDK toolkit and/or your app's CI-CD pipeline, and can be naturally referenced in your CDK app.

import "github.com/aws/aws-cdk-go/awscdk"


asset := awscdk.NewTarballImageAsset(this, jsii.String("MyBuildImage"), &TarballImageAssetProps{
	TarballFile: jsii.String("local-image.tar"),
})

This will instruct the toolkit to add the tarball as a file asset. During deployment it will load the container image from local-image.tar, push it to an Amazon ECR repository and wire the name of the repository as CloudFormation parameters to your stack.

Publishing images to ECR repositories

DockerImageAsset is designed for seamless build & consumption of image assets by CDK code deployed to multiple environments through the CDK CLI or through CI/CD workflows. To that end, the ECR repository behind this construct is controlled by the AWS CDK. The mechanics of where these images are published and how are intentionally kept as an implementation detail, and the construct does not support customizations such as specifying the ECR repository name or tags.

If you are looking for a way to publish image assets to an ECR repository in your control, you should consider using cdklabs/cdk-ecr-deployment, which is able to replicate an image asset from the CDK-controlled ECR repository to a repository of your choice.

Here an example from the cdklabs/cdk-ecr-deployment project:

// This example available in TypeScript only

import { DockerImageAsset } from 'aws-cdk-lib/aws-ecr-assets';
import * as ecrdeploy from 'cdk-ecr-deployment';

const image = new DockerImageAsset(this, 'CDKDockerImage', {
  directory: path.join(__dirname, 'docker'),
});

new ecrdeploy.ECRDeployment(this, 'DeployDockerImage', {
  src: new ecrdeploy.DockerImageName(image.imageUri),
  dest: new ecrdeploy.DockerImageName(`${cdk.Aws.ACCOUNT_ID}.dkr.ecr.us-west-2.amazonaws.com/test:nginx`),
});

⚠️ Please note that this is a 3rd-party construct library and is not officially supported by AWS. You are welcome to +1 this GitHub issue if you would like to see native support for this use-case in the AWS CDK.

Pull Permissions

Depending on the consumer of your image asset, you will need to make sure the principal has permissions to pull the image.

In most cases, you should use the asset.repository.grantPull(principal) method. This will modify the IAM policy of the principal to allow it to pull images from this repository.

If the pulling principal is not in the same account or is an AWS service that doesn't assume a role in your account (e.g. AWS CodeBuild), pull permissions must be granted on the resource policy (and not on the principal's policy). To do that, you can use asset.repository.addToResourcePolicy(statement) to grant the desired principal the following permissions: "ecr:GetDownloadUrlForLayer", "ecr:BatchGetImage" and "ecr:BatchCheckLayerAvailability".

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DockerImageAsset_IsConstruct

func DockerImageAsset_IsConstruct(x interface{}) *bool

Checks if `x` is a construct.

Use this method instead of `instanceof` to properly detect `Construct` 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 class `Construct` in each copy of the `constructs` library is seen as a different class, and an instance of one class will not test as `instanceof` 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 the `constructs` library can be accidentally installed, and `instanceof` will behave unpredictably. It is safest to avoid using `instanceof`, and using this type-testing method instead.

Returns: true if `x` is an object created from a class which extends `Construct`.

func NewDockerImageAsset_Override

func NewDockerImageAsset_Override(d DockerImageAsset, scope constructs.Construct, id *string, props *DockerImageAssetProps)

func NewTarballImageAsset_Override

func NewTarballImageAsset_Override(t TarballImageAsset, scope constructs.Construct, id *string, props *TarballImageAssetProps)

func TarballImageAsset_IsConstruct

func TarballImageAsset_IsConstruct(x interface{}) *bool

Checks if `x` is a construct.

Use this method instead of `instanceof` to properly detect `Construct` 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 class `Construct` in each copy of the `constructs` library is seen as a different class, and an instance of one class will not test as `instanceof` 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 the `constructs` library can be accidentally installed, and `instanceof` will behave unpredictably. It is safest to avoid using `instanceof`, and using this type-testing method instead.

Returns: true if `x` is an object created from a class which extends `Construct`.

Types

type DockerCacheOption added in v2.69.0

type DockerCacheOption struct {
	// The type of cache to use.
	//
	// Refer to https://docs.docker.com/build/cache/backends/ for full list of backends.
	//
	// Example:
	//   "registry"
	//
	// Default: - unspecified.
	//
	Type *string `field:"required" json:"type" yaml:"type"`
	// Any parameters to pass into the docker cache backend configuration.
	//
	// Refer to https://docs.docker.com/build/cache/backends/ for cache backend configuration.
	//
	// Example:
	//   var branch string
	//
	//
	//   params := map[string]interface{}{
	//   	"ref": fmt.Sprintf("12345678.dkr.ecr.us-west-2.amazonaws.com/cache:%v", branch),
	//   	"mode": jsii.String("max"),
	//   }
	//
	// Default: {} No options provided.
	//
	Params *map[string]*string `field:"optional" json:"params" yaml:"params"`
}

Options for configuring the Docker cache backend.

Example:

import "github.com/aws/aws-cdk-go/awscdk"

asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
	CacheFrom: []dockerCacheOption{
		&dockerCacheOption{
			Type: jsii.String("registry"),
			Params: map[string]*string{
				"ref": jsii.String("ghcr.io/myorg/myimage:cache"),
			},
		},
	},
	CacheTo: &dockerCacheOption{
		Type: jsii.String("registry"),
		Params: map[string]*string{
			"ref": jsii.String("ghcr.io/myorg/myimage:cache"),
			"mode": jsii.String("max"),
			"compression": jsii.String("zstd"),
		},
	},
})

type DockerImageAsset

type DockerImageAsset interface {
	constructs.Construct
	// 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.
	AssetHash() *string
	// 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.
	ImageTag() *string
	// The full URI of the image (including a tag).
	//
	// Use this reference to pull
	// the asset.
	ImageUri() *string
	SetImageUri(val *string)
	// The tree node.
	Node() constructs.Node
	// Repository where the image is stored.
	Repository() awsecr.IRepository
	SetRepository(val awsecr.IRepository)
	// 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.
	// See: https://github.com/aws/aws-cdk/issues/1432
	//
	AddResourceMetadata(resource awscdk.CfnResource, resourceProperty *string)
	// Returns a string representation of this construct.
	ToString() *string
}

An asset that represents a Docker image.

The image will be created in build time and uploaded to an ECR repository.

Example:

import "github.com/aws/aws-cdk-go/awscdk"

asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
	BuildArgs: map[string]*string{
		"HTTP_PROXY": jsii.String("http://10.20.30.2:1234"),
	},
	Invalidation: &DockerImageAssetInvalidationOptions{
		BuildArgs: jsii.Boolean(false),
	},
})

func NewDockerImageAsset

func NewDockerImageAsset(scope constructs.Construct, id *string, props *DockerImageAssetProps) DockerImageAsset

type DockerImageAssetInvalidationOptions

type DockerImageAssetInvalidationOptions struct {
	// Use `buildArgs` while calculating the asset hash.
	// Default: true.
	//
	BuildArgs *bool `field:"optional" json:"buildArgs" yaml:"buildArgs"`
	// Use `buildSecrets` while calculating the asset hash.
	// Default: true.
	//
	BuildSecrets *bool `field:"optional" json:"buildSecrets" yaml:"buildSecrets"`
	// Use `buildSsh` while calculating the asset hash.
	// Default: true.
	//
	BuildSsh *bool `field:"optional" json:"buildSsh" yaml:"buildSsh"`
	// Use `extraHash` while calculating the asset hash.
	// Default: true.
	//
	ExtraHash *bool `field:"optional" json:"extraHash" yaml:"extraHash"`
	// Use `file` while calculating the asset hash.
	// Default: true.
	//
	File *bool `field:"optional" json:"file" yaml:"file"`
	// Use `networkMode` while calculating the asset hash.
	// Default: true.
	//
	NetworkMode *bool `field:"optional" json:"networkMode" yaml:"networkMode"`
	// Use `outputs` while calculating the asset hash.
	// Default: true.
	//
	Outputs *bool `field:"optional" json:"outputs" yaml:"outputs"`
	// Use `platform` while calculating the asset hash.
	// Default: true.
	//
	Platform *bool `field:"optional" json:"platform" yaml:"platform"`
	// Use `repositoryName` while calculating the asset hash.
	// Default: true.
	//
	RepositoryName *bool `field:"optional" json:"repositoryName" yaml:"repositoryName"`
	// Use `target` while calculating the asset hash.
	// Default: true.
	//
	Target *bool `field:"optional" json:"target" yaml:"target"`
}

Options to control invalidation of `DockerImageAsset` asset hashes.

Example:

import "github.com/aws/aws-cdk-go/awscdk"

asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
	BuildArgs: map[string]*string{
		"HTTP_PROXY": jsii.String("http://10.20.30.2:1234"),
	},
	Invalidation: &DockerImageAssetInvalidationOptions{
		BuildArgs: jsii.Boolean(false),
	},
})

type DockerImageAssetOptions

type DockerImageAssetOptions struct {
	// File paths matching the patterns will be excluded.
	//
	// See `ignoreMode` to set the matching behavior.
	// Has no effect on Assets bundled using the `bundling` property.
	// Default: - nothing is excluded.
	//
	Exclude *[]*string `field:"optional" json:"exclude" yaml:"exclude"`
	// A strategy for how to handle symlinks.
	// Default: SymlinkFollowMode.NEVER
	//
	FollowSymlinks awscdk.SymlinkFollowMode `field:"optional" json:"followSymlinks" yaml:"followSymlinks"`
	// The ignore behavior to use for `exclude` patterns.
	// Default: IgnoreMode.GLOB
	//
	IgnoreMode awscdk.IgnoreMode `field:"optional" json:"ignoreMode" yaml:"ignoreMode"`
	// Extra information to encode into the fingerprint (e.g. build instructions and other inputs).
	// Default: - hash is only based on source content.
	//
	ExtraHash *string `field:"optional" json:"extraHash" yaml:"extraHash"`
	// Unique identifier of the docker image asset and its potential revisions.
	//
	// Required if using AppScopedStagingSynthesizer.
	// Default: - no asset name.
	//
	AssetName *string `field:"optional" json:"assetName" yaml:"assetName"`
	// Build args to pass to the `docker build` command.
	//
	// Since Docker build arguments are resolved before deployment, keys and
	// values cannot refer to unresolved tokens (such as `lambda.functionArn` or
	// `queue.queueUrl`).
	// Default: - no build args are passed.
	//
	BuildArgs *map[string]*string `field:"optional" json:"buildArgs" yaml:"buildArgs"`
	// Build secrets.
	//
	// Docker BuildKit must be enabled to use build secrets.
	//
	// Example:
	//   import "github.com/aws/aws-cdk-go/awscdk"
	//
	//
	//   buildSecrets := map[string]*string{
	//   	"MY_SECRET": awscdk.DockerBuildSecret_fromSrc(jsii.String("file.txt")),
	//   }
	//
	// See: https://docs.docker.com/build/buildkit/
	//
	// Default: - no build secrets.
	//
	BuildSecrets *map[string]*string `field:"optional" json:"buildSecrets" yaml:"buildSecrets"`
	// SSH agent socket or keys to pass to the `docker build` command.
	//
	// Docker BuildKit must be enabled to use the ssh flag.
	// See: https://docs.docker.com/build/buildkit/
	//
	// Default: - no --ssh flag.
	//
	BuildSsh *string `field:"optional" json:"buildSsh" yaml:"buildSsh"`
	// Cache from options to pass to the `docker build` command.
	// See: https://docs.docker.com/build/cache/backends/
	//
	// Default: - no cache from options are passed to the build command.
	//
	CacheFrom *[]*DockerCacheOption `field:"optional" json:"cacheFrom" yaml:"cacheFrom"`
	// Cache to options to pass to the `docker build` command.
	// See: https://docs.docker.com/build/cache/backends/
	//
	// Default: - no cache to options are passed to the build command.
	//
	CacheTo *DockerCacheOption `field:"optional" json:"cacheTo" yaml:"cacheTo"`
	// Path to the Dockerfile (relative to the directory).
	// Default: 'Dockerfile'.
	//
	File *string `field:"optional" json:"file" yaml:"file"`
	// Options to control which parameters are used to invalidate the asset hash.
	// Default: - hash all parameters.
	//
	Invalidation *DockerImageAssetInvalidationOptions `field:"optional" json:"invalidation" yaml:"invalidation"`
	// Networking mode for the RUN commands during build.
	//
	// Support docker API 1.25+.
	// Default: - no networking mode specified (the default networking mode `NetworkMode.DEFAULT` will be used)
	//
	NetworkMode NetworkMode `field:"optional" json:"networkMode" yaml:"networkMode"`
	// Outputs to pass to the `docker build` command.
	// See: https://docs.docker.com/engine/reference/commandline/build/#custom-build-outputs
	//
	// Default: - no outputs are passed to the build command (default outputs are used).
	//
	Outputs *[]*string `field:"optional" json:"outputs" yaml:"outputs"`
	// Platform to build for.
	//
	// _Requires Docker Buildx_.
	// Default: - no platform specified (the current machine architecture will be used).
	//
	Platform Platform `field:"optional" json:"platform" yaml:"platform"`
	// Docker target to build to.
	// Default: - no target.
	//
	Target *string `field:"optional" json:"target" yaml:"target"`
}

Options for DockerImageAsset.

Example:

// 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"),
	},
	BuildSecrets: map[string]*string{
		"buildSecretsKey": jsii.String("buildSecrets"),
	},
	BuildSsh: jsii.String("buildSsh"),
	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"),
		},
	},
	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),
		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"),
}

type DockerImageAssetProps

type DockerImageAssetProps struct {
	// File paths matching the patterns will be excluded.
	//
	// See `ignoreMode` to set the matching behavior.
	// Has no effect on Assets bundled using the `bundling` property.
	// Default: - nothing is excluded.
	//
	Exclude *[]*string `field:"optional" json:"exclude" yaml:"exclude"`
	// A strategy for how to handle symlinks.
	// Default: SymlinkFollowMode.NEVER
	//
	FollowSymlinks awscdk.SymlinkFollowMode `field:"optional" json:"followSymlinks" yaml:"followSymlinks"`
	// The ignore behavior to use for `exclude` patterns.
	// Default: IgnoreMode.GLOB
	//
	IgnoreMode awscdk.IgnoreMode `field:"optional" json:"ignoreMode" yaml:"ignoreMode"`
	// Extra information to encode into the fingerprint (e.g. build instructions and other inputs).
	// Default: - hash is only based on source content.
	//
	ExtraHash *string `field:"optional" json:"extraHash" yaml:"extraHash"`
	// Unique identifier of the docker image asset and its potential revisions.
	//
	// Required if using AppScopedStagingSynthesizer.
	// Default: - no asset name.
	//
	AssetName *string `field:"optional" json:"assetName" yaml:"assetName"`
	// Build args to pass to the `docker build` command.
	//
	// Since Docker build arguments are resolved before deployment, keys and
	// values cannot refer to unresolved tokens (such as `lambda.functionArn` or
	// `queue.queueUrl`).
	// Default: - no build args are passed.
	//
	BuildArgs *map[string]*string `field:"optional" json:"buildArgs" yaml:"buildArgs"`
	// Build secrets.
	//
	// Docker BuildKit must be enabled to use build secrets.
	//
	// Example:
	//   import { DockerBuildSecret } from 'aws-cdk-lib';
	//
	//   const buildSecrets = {
	//     'MY_SECRET': DockerBuildSecret.fromSrc('file.txt')
	//   };
	//
	// See: https://docs.docker.com/build/buildkit/
	//
	// Default: - no build secrets.
	//
	BuildSecrets *map[string]*string `field:"optional" json:"buildSecrets" yaml:"buildSecrets"`
	// SSH agent socket or keys to pass to the `docker build` command.
	//
	// Docker BuildKit must be enabled to use the ssh flag.
	// See: https://docs.docker.com/build/buildkit/
	//
	// Default: - no --ssh flag.
	//
	BuildSsh *string `field:"optional" json:"buildSsh" yaml:"buildSsh"`
	// Cache from options to pass to the `docker build` command.
	// See: https://docs.docker.com/build/cache/backends/
	//
	// Default: - no cache from options are passed to the build command.
	//
	CacheFrom *[]*DockerCacheOption `field:"optional" json:"cacheFrom" yaml:"cacheFrom"`
	// Cache to options to pass to the `docker build` command.
	// See: https://docs.docker.com/build/cache/backends/
	//
	// Default: - no cache to options are passed to the build command.
	//
	CacheTo *DockerCacheOption `field:"optional" json:"cacheTo" yaml:"cacheTo"`
	// Path to the Dockerfile (relative to the directory).
	// Default: 'Dockerfile'.
	//
	File *string `field:"optional" json:"file" yaml:"file"`
	// Options to control which parameters are used to invalidate the asset hash.
	// Default: - hash all parameters.
	//
	Invalidation *DockerImageAssetInvalidationOptions `field:"optional" json:"invalidation" yaml:"invalidation"`
	// Networking mode for the RUN commands during build.
	//
	// Support docker API 1.25+.
	// Default: - no networking mode specified (the default networking mode `NetworkMode.DEFAULT` will be used)
	//
	NetworkMode NetworkMode `field:"optional" json:"networkMode" yaml:"networkMode"`
	// Outputs to pass to the `docker build` command.
	// See: https://docs.docker.com/engine/reference/commandline/build/#custom-build-outputs
	//
	// Default: - no outputs are passed to the build command (default outputs are used).
	//
	Outputs *[]*string `field:"optional" json:"outputs" yaml:"outputs"`
	// Platform to build for.
	//
	// _Requires Docker Buildx_.
	// Default: - no platform specified (the current machine architecture will be used).
	//
	Platform Platform `field:"optional" json:"platform" yaml:"platform"`
	// Docker target to build to.
	// Default: - no target.
	//
	Target *string `field:"optional" json:"target" yaml:"target"`
	// 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
	Directory *string `field:"required" json:"directory" yaml:"directory"`
}

Props for DockerImageAssets.

Example:

import "github.com/aws/aws-cdk-go/awscdk"

asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
	BuildArgs: map[string]*string{
		"HTTP_PROXY": jsii.String("http://10.20.30.2:1234"),
	},
	Invalidation: &DockerImageAssetInvalidationOptions{
		BuildArgs: jsii.Boolean(false),
	},
})

type NetworkMode added in v2.11.0

type NetworkMode interface {
	// The networking mode to use for docker build.
	Mode() *string
}

networking mode on build time supported by docker.

Example:

import "github.com/aws/aws-cdk-go/awscdk"

asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
	NetworkMode: awscdk.NetworkMode_HOST(),
})

func NetworkMode_Custom added in v2.11.0

func NetworkMode_Custom(mode *string) NetworkMode

Used to specify a custom networking mode Use this if the networking mode name is not yet supported by the CDK.

func NetworkMode_DEFAULT added in v2.11.0

func NetworkMode_DEFAULT() NetworkMode

func NetworkMode_FromContainer added in v2.11.0

func NetworkMode_FromContainer(containerId *string) NetworkMode

Reuse another container's network stack.

func NetworkMode_HOST added in v2.11.0

func NetworkMode_HOST() NetworkMode

func NetworkMode_NONE added in v2.11.0

func NetworkMode_NONE() NetworkMode

type Platform added in v2.26.0

type Platform interface {
	// The platform to use for docker build.
	Platform() *string
}

platform supported by docker.

Example:

import "github.com/aws/aws-cdk-go/awscdk"

asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
	Directory: path.join(__dirname, jsii.String("my-image")),
	Platform: awscdk.Platform_LINUX_ARM64(),
})

func Platform_Custom added in v2.26.0

func Platform_Custom(platform *string) Platform

Used to specify a custom platform Use this if the platform name is not yet supported by the CDK.

func Platform_LINUX_AMD64 added in v2.26.0

func Platform_LINUX_AMD64() Platform

func Platform_LINUX_ARM64 added in v2.26.0

func Platform_LINUX_ARM64() Platform

type TarballImageAsset

type TarballImageAsset interface {
	constructs.Construct
	// 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.
	AssetHash() *string
	// 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.
	ImageTag() *string
	// The full URI of the image (including a tag).
	//
	// Use this reference to pull
	// the asset.
	ImageUri() *string
	SetImageUri(val *string)
	// The tree node.
	Node() constructs.Node
	// Repository where the image is stored.
	Repository() awsecr.IRepository
	SetRepository(val awsecr.IRepository)
	// Returns a string representation of this construct.
	ToString() *string
}

An asset that represents a Docker image.

The image will loaded from an existing tarball and uploaded to an ECR repository.

Example:

import "github.com/aws/aws-cdk-go/awscdk"

asset := awscdk.NewTarballImageAsset(this, jsii.String("MyBuildImage"), &TarballImageAssetProps{
	TarballFile: jsii.String("local-image.tar"),
})

func NewTarballImageAsset

func NewTarballImageAsset(scope constructs.Construct, id *string, props *TarballImageAssetProps) TarballImageAsset

type TarballImageAssetProps

type TarballImageAssetProps struct {
	// Absolute path to the tarball.
	//
	// It is recommended to to use the script running directory (e.g. `__dirname`
	// in Node.js projects or dirname of `__file__` in Python) if your tarball
	// is located as a resource inside your project.
	TarballFile *string `field:"required" json:"tarballFile" yaml:"tarballFile"`
}

Options for TarballImageAsset.

Example:

import "github.com/aws/aws-cdk-go/awscdk"

asset := awscdk.NewTarballImageAsset(this, jsii.String("MyBuildImage"), &TarballImageAssetProps{
	TarballFile: jsii.String("local-image.tar"),
})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL