Amazon provides a hosted private registry for Docker images called EC2 Container Registry (ECR) as part of its container focused suite of services. Many of our customers seem to love the ECR and ECS (EC2 Container Service) combination to store and run their applications. Amazon ECR can be accessed by going to your AWS Management Console, selecting EC2 Container Service, and clicking on Repositories in the left sidebar.
In this blog post, I will go through a simple scenario with a sample project where we enable a project for CI, build a docker image as part of the workflow, test the image, and then push it to Amazon ECR. In the next blog, we will then set up the rest of the Continuous Delivery pipeline for the sample application.
If you want to follow along with the step by step tutorial you can fork the sample used in this tutorial, sign in to Shippable, and set up the CI/CD workflow as described.
Let's get started.
Fork the demo projects from GitHub
1. sample-docker-push-registry repository contains code for the sample application.
Create necessary integrations
2. Add an Amazon ECR integration by following instructions in the Adding an Account Integration section on the Amazon ECR integration page
Set up Continuous Integration
Before you get started with setting up your deployments, let's set up CI for your sample application.
3. Enable your forked sample application for CI.
- From the Shippable dashboard, select your subscription from the
Subscriptionsdropdown at the top left of the dashboard. This should be the subscription where you forked the repository.
- On the Subscription page, click on
Enable Projectin the left sidebar. If you have not enabled any projects on Shippable, you will be directly be taken to a page with a list of your repositories.
- Find the forked repository and click on the
- If the repo is not shown in the list, click on the
Syncbutton next to the Search box. This syncs your Shippable subscription with your Source Control. Find the samplenod project and enable it.
4. Take a look at the config file
shippable.yml at the root of your forked sample app. The config is very simple- build a Docker image and push it to ECR. Make the following changes to
- Update the ecr integration with the Amazon ECR integration you created in step 2.
- integrationName: #your ECR integration name
- Update IMAGE_NAME with your fully qualified repository name where you want to push the image. Please make sure the image repository you're pushing to exists on ECR.
- echo 'CI Running'
- export IMAGE_NAME= #e.g. 027746667844.dkr.ecr.us-east-1.amazonaws.com/sample-shipdemo
Commit and push the changes.
Run the build
Pushing the changes should trigger your build automatically. It will build the Docker image and push it to ECR.
You will find the image in your Amazon ECR Repositories list as shown below:
Read the next blog in this series: Continuously deploy your app from GitHub to Amazon ECS. This will complete the rest of your DevOps workflow by setting up Continuous Delivery for this image, i.e. set up deployment into a series of environments like Dev, Test, Prod, create releases, and promote the versioned image through those environments.