CDK construct to deploy docker image to Amazon ECR
Project description
cdk-ecr-deployment
CDK construct to synchronize single docker image between docker registries.
Only use v3 of this package
⚠️ Version 2.* is no longer supported, as the Go.1.x runtime is no longer supported in AWS Lambda.
⚠️ Version 1.* is no longer supported, as CDK v1 has reached the end-of-life
stage.
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
.
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
Built Distribution
Hashes for cdk_ecr_deployment-3.0.126.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1a583a4812dab73d7ac52c1398948174a80b92f8d0bd14590322b0634965203 |
|
MD5 | 97255123d9b3e709cb57878ff95e195e |
|
BLAKE2b-256 | 0ae4c27807320de5a176baae9d9ec68ba2a85b97c7964fecc376273099f309ab |
Hashes for cdk_ecr_deployment-3.0.126-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0195e684db4404c728c119bd81c21c8b18f25960857fb99ff092ec17f8e7d77 |
|
MD5 | 313c0a2c76ecc03d383489cd3d2c2eb2 |
|
BLAKE2b-256 | a7bbc87ccf72c16525f7c649d7f3935af6456d6bf6b01a0e16c81a69fd5ba0a0 |