AWS ECR pull-through cache with Pulumi
a Pulumi program that creates ECR repositories with pull-through cache rules for Docker Hub and Google Container Registry.
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set aws-ts-ecr-cachecd pulumi-examples/aws-ts-ecr-cacheThis Pulumi project creates AWS Elastic Container Registry (ECR) repositories with pull-through cache rules for Docker Hub, GitHub Container Registry, and GitLab Container Registry. It also sets up AWS Secrets Manager secrets to store credentials for Docker Hub, GitHub, and GitLab.
Prerequisites#
Deploying the example#
-
Create a new stack:
Terminal window pulumi stack init dev -
Set the AWS region to deploy into:
Terminal window pulumi config set aws:region <your-aws-region> -
Configure credentials for each registry you want to cache. Each registry is optional; a cache rule is created only for the registries whose username is set.
Docker Hub — to get your access token, log in to Docker Hub, navigate to Account Settings, and create a new access token:
Terminal window pulumi config set dockerHubUsername <your-docker-hub-username>pulumi config set --secret dockerHubAccessToken <your-docker-hub-access-token>GitHub — to get your access token, log in to GitHub, navigate to Developer settings, and create a new personal access token with the
read:packagesscope:Terminal window pulumi config set gitHubUsername <your-github-username>pulumi config set --secret gitHubAccessToken <your-github-access-token>GitLab — to get your access token, log in to GitLab, navigate to Access Tokens, and create a new personal access token with the
read_registryscope:Terminal window pulumi config set gitLabUsername <your-gitlab-username>pulumi config set --secret gitLabAccessToken <your-gitlab-access-token> -
Install dependencies:
Terminal window npm install -
Deploy the stack:
Terminal window pulumi up
Resources created#
-
ECR Repositories:
pullThroughCacheECR: ECR repository for pull-through cache.
-
Pull-Through Cache Rules:
dockerHubCacheRule: Pull-through cache rule for Docker Hub (ifdockerHubUsernameis set).githubCacheRule: Pull-through cache rule for GitHub Container Registry (ifgitHubUsernameis set).gitLabCacheRule: Pull-through cache rule for GitLab Container Registry (ifgitLabUsernameis set).
-
Secrets Manager Secrets:
ecrPullThroughCacheDockerHubSecret: Secret for Docker Hub credentials (ifdockerHubUsernameis set).ecrPullThroughCacheGitHubSecret: Secret for GitHub credentials (ifgitHubUsernameis set).ecrPullThroughCacheGitLabSecret: Secret for GitLab credentials (ifgitLabUsernameis set).
Outputs#
pullThroughCacheECRRepositoryUrl: URL of the ECR repository.ecrRepositoryPrefixes: Prefixes for the ECR repositories.
Cleaning up#
Once you’re finished experimenting, destroy your stack and remove it to avoid incurring further charges:
pulumi destroypulumi stack rm