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 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 post, we will then set up the rest of the Continuous Delivery pipeline for the sample application.
Let's get started.
1. Fork the Demo Projects From GitHub
The sample-docker-push-registry repository contains the code for the sample application.
2. Create Necessary Integrations
Add an Amazon ECR integration by following the instructions in the Adding an Account Integration section on the Amazon ECR integration page.
3. Set Up Continuous Integration
Before you get started with setting up your deployments, let's set up CI for your sample application.
Enable your forked sample application for CI.
From the Shippable dashboard, select your subscription from the Subscriptions drop-down at the top left of the dashboard. This should be the subscription where you forked the repository.
On the Subscription page, click on Enable Project on 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 Enable button.
If the repo is not shown in the list, click on the Sync button next to the search box. This syncs your Shippable subscription with your source control. Find the samplenod project and enable it.
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:
integrations: hub: - integrationName: #your ECR integration name type: ecr
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.
build: ci: - echo 'CI Running' - export IMAGE_NAME= #e.g. 027746667844.dkr.ecr.us-east-1.amazonaws.com/sample-shipdemo
Commit and push the changes.
4. 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:
In my next post, we will see how to set 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.