Skip to content

Latest commit

 

History

History
628 lines (376 loc) · 19.5 KB

API.md

File metadata and controls

628 lines (376 loc) · 19.5 KB

CDK Docker Image Deployment

This module allows you to copy docker image assets to a repository you control. This can be necessary if you want to build a Docker image in one CDK app and consume it in a different app or outside the CDK, or if you want to apply a lifecycle policy to all images of a part of your application.

Getting Started

Below is a basic example for how to use the DockerImageDeployment API:

import * as ecr from 'aws-cdk-lib/aws-ecr';
import * as imagedeploy from 'cdk-docker-image-deployment';

const repo = new ecr.Repository.fromRepositoryName(this, 'MyRepository', 'myrepository');

new imagedeploy.DockerImageDeployment(this, 'ExampleImageDeploymentWithTag', {
  source: imagedeploy.Source.directory('path/to/directory'),
  destination: imagedeploy.Destination.ecr(repo, {
    tag: 'myspecialtag',
  }),
});

Currently Supported Sources

  • Source.directory(): Supply a path to a local docker image as source.

Don't see a source listed? See if there is an open issue or PR already. If not, please open an issue asking for it or better yet, submit a contribution!

Currently Supported Destinations

  • Destination.ecr(repo, options): Send your docker image to an ECR repository in your stack's account.

Don't see a destination listed? See if there is an open issue or PR already. If not, please open an issue asking for it or better yet, submit a contribution!

Under the Hood

  1. When this stack is deployed (either via cdk deploy or via CI/CD), the contents of the local Docker image will be archived and uploaded to an intermediary assets ECR Repository using the cdk-assets mechanism.

  2. The DockerImageDeployment construct synthesizes a CodeBuild Project which uses docker to pull the image from the intermediary repository, tag the image if a tag is provided, and push the image to the destination repository.

  3. The deployment will wait until the CodeBuild Project completes successfully before finishing.

The architecture of this construct can be seen here:

Construct-Architecture

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

API Reference

Constructs

DockerImageDeployment

DockerImageDeployment pushes an image from a local or external source to a specified external destination.

Initializers

import { DockerImageDeployment } from 'cdk-docker-image-deployment'

new DockerImageDeployment(scope: Construct, id: string, props: DockerImageDeploymentProps)
Name Type Description
scope constructs.Construct No description.
id string No description.
props DockerImageDeploymentProps No description.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsRequired

Methods

Name Description
toString Returns a string representation of this construct.

toString
public toString(): string

Returns a string representation of this construct.

Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { DockerImageDeployment } from 'cdk-docker-image-deployment'

DockerImageDeployment.isConstruct(x: any)

Checks if x is a construct.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


Structs

DestinationConfig

Destination information.

Initializer

import { DestinationConfig } from 'cdk-docker-image-deployment'

const destinationConfig: DestinationConfig = { ... }

Properties

Name Type Description
destinationUri string The URI of the destination repository to deploy to.
loginConfig LoginConfig The login command and region.
destinationTag string The tag of the deployed image.

destinationUriRequired
public readonly destinationUri: string;
  • Type: string

The URI of the destination repository to deploy to.


loginConfigRequired
public readonly loginConfig: LoginConfig;

The login command and region.


destinationTagOptional
public readonly destinationTag: string;
  • Type: string
  • Default: the tag of the source

The tag of the deployed image.


DockerImageDeploymentProps

Initializer

import { DockerImageDeploymentProps } from 'cdk-docker-image-deployment'

const dockerImageDeploymentProps: DockerImageDeploymentProps = { ... }

Properties

Name Type Description
destination Destination Destination repository to deploy the image to.
source Source Source of the image to deploy.

destinationRequired
public readonly destination: Destination;

Destination repository to deploy the image to.


sourceRequired
public readonly source: Source;

Source of the image to deploy.


EcrSourceOptions

Properties needed for Source.ecr.

Initializer

import { EcrSourceOptions } from 'cdk-docker-image-deployment'

const ecrSourceOptions: EcrSourceOptions = { ... }

Properties

Name Type Description
tag string Tag of deployed image.

tagOptional
public readonly tag: string;
  • Type: string
  • Default: tag of source

Tag of deployed image.


LoginConfig

Login commands for specified registry.

Initializer

import { LoginConfig } from 'cdk-docker-image-deployment'

const loginConfig: LoginConfig = { ... }

Properties

Name Type Description
loginCommand string Command to run in codebuild to login.
region string Region of ECR repository.

loginCommandRequired
public readonly loginCommand: string;
  • Type: string

Command to run in codebuild to login.

Formatted docker login ....


regionOptional
public readonly region: string;
  • Type: string
  • Default: undefined if not an ECR repository

Region of ECR repository.


SourceConfig

Source information.

Initializer

import { SourceConfig } from 'cdk-docker-image-deployment'

const sourceConfig: SourceConfig = { ... }

Properties

Name Type Description
imageTag string The source tag.
imageUri string The source image URI.
loginConfig LoginConfig The login command and region.

imageTagRequired
public readonly imageTag: string;
  • Type: string

The source tag.


imageUriRequired
public readonly imageUri: string;
  • Type: string

The source image URI.


loginConfigRequired
public readonly loginConfig: LoginConfig;

The login command and region.


SourceContext

Bind context for Source.

Initializer

import { SourceContext } from 'cdk-docker-image-deployment'

const sourceContext: SourceContext = { ... }

Properties

Name Type Description
handlerRole aws-cdk-lib.aws_iam.IRole The role for the handler.

handlerRoleRequired
public readonly handlerRole: IRole;
  • Type: aws-cdk-lib.aws_iam.IRole

The role for the handler.


Classes

Destination

Specifies docker image deployment destination.

Usage:

declare const repo: ecr.IRepository;
const destinationEcr = dockerDeploy.Destination.ecr(repository, {
   tag: 'tag',
});

Initializers

import { Destination } from 'cdk-docker-image-deployment'

new Destination()
Name Type Description

Methods

Name Description
bind Bind grants the CodeBuild role permissions to pull and push to a repository if necessary.

bind
public bind(role: IGrantable): DestinationConfig

Bind grants the CodeBuild role permissions to pull and push to a repository if necessary.

Bind should be invoked by the caller to get the DestinationConfig.

roleRequired
  • Type: aws-cdk-lib.aws_iam.IGrantable

Static Functions

Name Description
ecr Uses an ECR repository in the same account as the stack as the destination for the image.

ecr
import { Destination } from 'cdk-docker-image-deployment'

Destination.ecr(repository: IRepository, options?: EcrSourceOptions)

Uses an ECR repository in the same account as the stack as the destination for the image.

repositoryRequired
  • Type: aws-cdk-lib.aws_ecr.IRepository

optionsOptional

Source

Specifies docker image deployment source.

Usage:

import * as path from 'path';
const path = path.join(__dirname, 'path/to/directory');
const sourceDirectory = Source.directory(path);

or with additional assetOptions

import * as path from 'path';
const path = path.join(__dirname, 'path/to/directory');
const sourceDirectory = Source.directory(path, {
   file: 'Dockerfile.api',
   buildArgs: {
     HTTP_PROXY: 'http://10.20.30.2:1234'
   }
})

Initializers

import { Source } from 'cdk-docker-image-deployment'

new Source()
Name Type Description

Methods

Name Description
bind Bind grants the CodeBuild role permissions to pull from a repository if necessary.

bind
public bind(scope: Construct, context: SourceContext): SourceConfig

Bind grants the CodeBuild role permissions to pull from a repository if necessary.

Bind should be invoked by the caller to get the SourceConfig.

scopeRequired
  • Type: constructs.Construct

contextRequired

Static Functions

Name Description
directory Uses a local image built from a Dockerfile in a local directory as the source.

directory
import { Source } from 'cdk-docker-image-deployment'

Source.directory(path: string, assetOptions?: DockerImageAssetOptions)

Uses a local image built from a Dockerfile in a local directory as the source.

pathRequired
  • Type: string

path to the directory containing your Dockerfile (not a path to a file).


assetOptionsOptional
  • Type: aws-cdk-lib.aws_ecr_assets.DockerImageAssetOptions

specify any additional DockerImageAssetOptions (except path).