Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 1.46 KB

README.md

File metadata and controls

42 lines (30 loc) · 1.46 KB

CDK ECR Sync

An CDK Construct to synchronizes Docker images from Docker Hub to ECR.

Why should you use it?

  1. Avoid DockerHub throttling
  2. Better availability (ECR: 99.9%, DockerHub: "as is")
  3. Possible less data transfer costs (ECS pulls from ECR in same region are free)

See also my blog post: https://garbe.io/blog/2020/04/22/cdk-ecr-sync/

How to use it

In your CDK application, run npm install @pgarbe/cdk-ecr-sync and add the following construct:

const ecrSync = new EcrSync(this, 'ecrSync', {
  repoPrefix: 'dockerhub-mirror', // optional prefix
  dockerImages: [
    {
      imageName: 'datadog/agent',
      excludeTags: [  // Use RegEx expressions to exclude specific tags
        'latest',
        '^1.0'
      ],
    }
  ],
  lifcecyleRule: {...} // Optional lifecycle rule for ECR repos
});

// Allow all accounts in your organization to pull
ecrSync.grantPull(new iam.OrganizationalPrincipal('o-123456'));

See also examples folder.

Trigger the sync manually

Look up for a lambda called *ecrSync*%*, add an empty test event, and execute it. The lambda will check which images needs to be synced and trigger a CodePipeline.