Amazon ECR Images

Deploying a Docker Image from AWS Elastic Container Registry (ECR)

This guide will walk you through deploying a Docker image from the AWS Elastic Container Registry (ECR).

We'll use Flightcontrol to deploy a Docker image from the AWS Elastic Container Registry to AWS Elastic Container Service (ECS) Fargate. Flightcontrol also supports using the Docker Hub image registry for pre-built images.

The steps we will follow will be:

Let's get started!

Prerequisites

You'll need the following before you begin:

Adding an AWS ECR Image Registry to Flightcontrol

We'll need to setup our AWS ECR image registry in the Flightcontrol dashboard. Choose Image Registries from the sidebar.

Add an Image Registry

Click the Add an Image Registry button to add a new image registry.

Add an Image Registry to Flightcontrol

Choose the Elastic Container Registry Type

When you add a new image registry, you'll need to choose the registry type. We'll pick Elastic Container Registry.

New Image Registry page on Flightcontrol

Use your Elastic Container Registry URI

With the Elastic Container Registry type, you'll need to provide your registry URI. You can find your registry URI in the AWS ECR console. You can also provide a name for this registry that you will remember, such as "AWS ECR Registry".

ECR Registry URI input field for an ECR Image Registry

The AWS account that you link this project to in Flightcontrol will need to have access to this image registry, and the image you want to deploy. If this is the same AWS account, everything should work. With different accounts, you may need to do some configuration on the AWS ECR side.

Once you have your AWS ECR image registry added to Flightcontrol, you can deploy your Docker images.

Creating a Flightcontrol Project

To setup the deployment process, create a Flightcontrol project in the dashboard. Choose a Github repository for the project - you may need to authorize the Flightcontrol Ops GitHub app to access your repository.

Flightcontrol won't use the source code to produce a build, but it is possible to use the flightcontrol.json file in the repository for configuration instead of the dashboard. In this Getting Started guide, we are using the dashboard for all configuration.

Adding a Web Server Service

Add a Web Server service to your new project with the Add Web Server (Fargate) button.

Add a Web Server service

Provide a name for the web server service, such as "Node Server".

The default build type for the Web Server is Nixpacks, so we will need to change the build type to Pull from Image Registry.

After the build type is changed, you'll see a new set of configuration options. You will need to select the AWS ECR image registry you just created. You need to know the name of the Docker image in that registry, and the tag to deploy, such as latest.

Configuring the Image Registry Build Type for ECR

You also need to provide a descriptive name for your web server service - in the above screenshot, the name is "Flask Web".

Configuring AWS and Deploying the Project

Flightcontrol needs to know which AWS account to use. You can have multiple AWS accounts linked, but the same account will be used to both pull from your image registry and deploy your project.

Flightcontrol can deploy to any AWS region, so choose one (such as us-east-1 or us-west-2).

Any environment variables or secrets your project needs can be configured in the dashboard.

Once you've selected an AWS account and region, you can create your project with the Create Project button.

Configuring AWS and Environment Variables

Flightcontrol will provision a new ECS Fargate cluster for your project with your selected ECR image. This may take a few minutes.

The next step will be to make this process fully automated to turn this into a continuous delivery (CD) pipeline.

Automating the Deployment Process

To integrate Flightcontrol's deployment process into your build pipeline, we can use the Flightcontrol API. In particular, you can create webhooks to trigger a deployment with Flightcontrol. These webhooks are called Deploy Hooks (opens in a new tab) on the Flightcontrol platform.

Creating a Deploy Hook

To create a deploy hook for our project, use the Trigger Deploy Hooks section in the Flightcontrol dashboard for your environment. Name your hook, and then click on the Create Deploy Hook button.

Create Deploy Hook

Flightcontrol creates a unique URL that triggers a new deployment when called.

After Deploy Hook was created, showing deployment URL

This deploy hook URL is similar to a password - anyone with the URL can trigger a deployment with Flightcontrol. To revoke access to the deploy hook URL, delete the deploy hook. You can create as many deploy hooks as you need.

Triggering a Deployment

To use a deploy hook, make an HTTP GET request to the URL Flightcontrol provided. This could be using a tool like curl or Postman, or simply in your web browser.

After calling that URL, the deployment appears in the Deployments section of the envrionment dashboard.

Deployments tab after triggering a deployment

Your successful HTTP request will return a JSON response with the deployment ID from Flightcontrol.

{
  "success": true,
  "deploymentId": "clijekhhm0j9krxxxxxxxxxzz"
}

This deployment ID gets used to check the status of the deployment with the Get Deployment API. You will need an API Key to use the Get Deployment API.

Conclusion

This guide showed you how to create a continuous delivery (CD) pipeline with Flightcontrol to deploy a Docker image from AWS ECR to AWS ECS Fargate. Using the build process you already have, Flightcontrol can manage your AWS infrastructure and deployments.