CDK construct to synchronize single docker image between docker registries.
- Copy image from ECR/external registry to (another) ECR/external registry
- Copy an archive tarball image from s3 to ECR/external registry
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.
export FORCE_PREBUILT_LAMBDA=1
.
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'),
});
// Copy from cdk docker image asset to another ECR.
new ecrdeploy.ECRDeployment(this, 'DeployDockerImage1', {
src: new ecrdeploy.DockerImageName(image.imageUri),
dest: new ecrdeploy.DockerImageName(`${cdk.Aws.ACCOUNT_ID}.dkr.ecr.us-west-2.amazonaws.com/my-nginx:latest`),
});
// Copy from docker registry to ECR.
new ecrdeploy.ECRDeployment(this, 'DeployDockerImage2', {
src: new ecrdeploy.DockerImageName('nginx:latest'),
dest: new ecrdeploy.DockerImageName(`${cdk.Aws.ACCOUNT_ID}.dkr.ecr.us-west-2.amazonaws.com/my-nginx2:latest`),
});
// Copy from private docker registry to ECR.
new ecrdeploy.ECRDeployment(this, 'DeployDockerImage3', {
src: new ecrdeploy.DockerImageName('javacs3/nginx:latest', { plainText: 'username:password', }),
/* src: new ecrdeploy.DockerImageName('javacs3/nginx:latest', {
secretManager: {
secret: sm.Secret.fromSecretNameV2(this, 'SrcSecret', 'aws-secrets-manager-secret-name'),
},
}),
*/
/* src: new ecrdeploy.DockerImageName('javacs3/nginx:latest', {
secretManager: {
secret: sm.Secret.fromPartialArn(this, 'SrcSecret', 'arn:aws:secretsmanager:us-west-2:000000000000:secret:id'),
},
}),
*/,
/* src: new ecrdeploy.DockerImageName('javacs3/nginx:latest', {
secretManager: {
secret: sm.Secret.fromSecretNameV2(this, 'SrcSecret', 'aws-secrets-manager-secret-name'),
usernameKey: 'username',
passwordKey: 'password',
},
}),
*/
dest: new ecrdeploy.DockerImageName(`${cdk.Aws.ACCOUNT_ID}.dkr.ecr.us-west-2.amazonaws.com/my-nginx3:latest`),
});
Sample: test/integ.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/integ.ecr-deployment.ts"
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
.