Skip to main content

CDK construct to deploy docker image to Amazon ECR

Project description

cdk-ecr-deployment

Release npm version PyPI npm PyPI - Downloads

CDK construct to synchronize single docker image between docker registries.

⚠️ Version 1.* is no longer supported, as CDK v1 has reached the end-of-life stage. Please use only ^2.0.0.

Features

  • Copy image from ECR/external registry to (another) ECR/external registry
  • Copy an archive tarball image from s3 to ECR/external registry

Environment variables

Enable flags: true, 1. e.g. export CI=1

  • CI indicate if it's CI environment. This flag will enable building lambda from scratch.
  • NO_PREBUILT_LAMBDA disable using prebuilt lambda.
  • FORCE_PREBUILT_LAMBDA force using prebuilt lambda.

⚠️ If you want to force using prebuilt lambda in CI environment to reduce build time. Try export FORCE_PREBUILT_LAMBDA=1.

⚠️ The above flags are only available in cdk-ecr-deployment 2.x and 3.x.

Examples

from aws_cdk.aws_ecr_assets import DockerImageAsset


image = DockerImageAsset(self, "CDKDockerImage",
    directory=path.join(__dirname, "docker")
)

# Copy from cdk docker image asset to another ECR.
ecrdeploy.ECRDeployment(self, "DeployDockerImage1",
    src=ecrdeploy.DockerImageName(image.image_uri),
    dest=ecrdeploy.DockerImageName(f"{cdk.Aws.ACCOUNT_ID}.dkr.ecr.us-west-2.amazonaws.com/my-nginx:latest")
)

# Copy from docker registry to ECR.
ecrdeploy.ECRDeployment(self, "DeployDockerImage2",
    src=ecrdeploy.DockerImageName("nginx:latest"),
    dest=ecrdeploy.DockerImageName(f"{cdk.Aws.ACCOUNT_ID}.dkr.ecr.us-west-2.amazonaws.com/my-nginx2:latest")
)

# Copy from private docker registry to ECR.
# The format of secret in aws secrets manager must be plain text! e.g. <username>:<password>
ecrdeploy.ECRDeployment(self, "DeployDockerImage3",
    src=ecrdeploy.DockerImageName("javacs3/nginx:latest", "username:password"),
    # src: new ecrdeploy.DockerImageName('javacs3/nginx:latest', 'aws-secrets-manager-secret-name'),
    # src: new ecrdeploy.DockerImageName('javacs3/nginx:latest', 'arn:aws:secretsmanager:us-west-2:000000000000:secret:id'),
    dest=ecrdeploy.DockerImageName(f"{cdk.Aws.ACCOUNT_ID}.dkr.ecr.us-west-2.amazonaws.com/my-nginx3:latest")
).add_to_principal_policy(iam.PolicyStatement(
    effect=iam.Effect.ALLOW,
    actions=["secretsmanager:GetSecretValue"
    ],
    resources=["*"]
))

Sample: test/example.ecr-deployment.ts

# Run the following command to try the sample.
NO_PREBUILT_LAMBDA=1 npx cdk deploy -a "npx ts-node -P tsconfig.dev.json --prefer-ts-exts test/example.ecr-deployment.ts"

API

Tech Details & Contribution

The core of this project relies on containers/image which is used by Skopeo. Please take a look at those projects before contribution.

To support a new docker image source(like docker tarball in s3), you need to implement image transport interface. You could take a look at docker-archive transport for a good start.

To test the lambda folder, make test.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdk-ecr-deployment-3.0.39.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cdk_ecr_deployment-3.0.39-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file cdk-ecr-deployment-3.0.39.tar.gz.

File metadata

  • Download URL: cdk-ecr-deployment-3.0.39.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for cdk-ecr-deployment-3.0.39.tar.gz
Algorithm Hash digest
SHA256 7381683b01e9e4a0470af9b05600756e0cdc4ac37aa634ae5d9589b0a693255d
MD5 e7ed485a0ca9591997f94d29657486a7
BLAKE2b-256 c3bac4a2aa552a426ebe76e97ccc20e38b2fae0e7127d8a93d42dade06ba1d18

See more details on using hashes here.

File details

Details for the file cdk_ecr_deployment-3.0.39-py3-none-any.whl.

File metadata

File hashes

Hashes for cdk_ecr_deployment-3.0.39-py3-none-any.whl
Algorithm Hash digest
SHA256 4287e3522e721be038586747b4e78cbbcc46c26683f48c8a8596b2bff3e8acb9
MD5 6aec6484e7d2ec24628d7d98d704458e
BLAKE2b-256 4fdaa8f40173167d2196d943d606d54e94364ff675df88d0901a3e5546102b2e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page