Setup Amazon ECR

If you want to create a continuous pipeline, we first need to create an ECR (Elastic Container Repository) for storing the docker images we build. This is quite easy to do and similar like create a git repository on Github. For the next steps you should have an user (with persgroep profile) with programmatic access and ECRPowerUser policy. If you have try to log in with the following command:

aws ecr get-login-password \
    --region eu-west-1 \
    --profile persgroep \
| docker login \
    --username AWS \
    --password-stdin 952653322924.dkr.ecr.eu-west-1.amazonaws.com

Let's start building the docker image with the correct tags:

REPOSITORY_URI=<INSERT ECR REPOSITORY LINK>
docker build -t $REPOSITORY_URI:test .
docker build -t $REPOSITORY_URI:production .
docker tag $REPOSITORY_URI:test $REPOSITORY_URI:production

If you did the following steps successfully you should see the images with the correct tags in the list of images on your machine. Try the command docker images to see the list.

The next step would be to push them to the ECR repository:

docker push $REPOSITORY_URI:test
docker push $REPOSITORY_URI:production

After the docker push is finished you should navigate to the AWS ECR repository and check if the images are there.

Lifecycle policies

Now the images are being stored, however when the development continues we want to delete the images without the tags test and productions when they are older than 60 days. We can achieve this with a lifecycle policy.

Last Updated: 6/1/2020, 10:06:32 AM