Deploy docker image to Fargate

<> Back to Announcements
February 18, 2022
Vespucci is an analytics solution designed to help your find the insights you’re not looking for. We can help with things like user engagement, UI optimisations and more. You can take a look at it here.

At Vespucci, we wanted to Dockerize most of our infrastructure components. We have a main node js server, and a few other node js server handling specific tasks, and we tend towards a microservices architecture.

While doing our researches, we found out about AWS Copilot. They introduced it in June 2020 but we never heard of it.

Why should you use Copilot ?

A few key benefits of using Copilot :

  • No VPC to handle
  • No IAM accounts to handle
  • No API Gateway, Router, … to handle
  • Automated upload of your docker image
  • Load balancer set up
  • Auto scale rules easy to set up

We found all of those benefits super handy at Vespucci, and it let us focus on our core business rather than infrastructure deployments and management.

Set up your production-ready infrastructure

  1. Install Copilot

brew install aws/tap/copilot-cli

2. Create your Docker image

The code below is a classic node js backend running on node 14, exposing port 8080 and having index.js as main file, which is in the /src directory.

FROM mhart/alpine-node:14
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . .
RUN npm install
CMD [ "node", "src/index.js" ]

3. Deploy your infrastructure

In one command line, Copilot will handle everything by itself. This command will create a test environment, using the Dockerfile in your local directory.

copilot init -a "NAME_OF_YOUR_APP" -d ./Dockerfile --deploy -t "Load Balanced Web Service" --name "NAME_OF_YOUR_SERVICE"

As you would like to have multiple environment running, you can create a production environment using that command

copilot env init --prod -n prod --default-config

To check all your running environments :

copilot env ls

At this point, you have a complete infrastructure, with a production and a dev environment.

4. Test your http endpoint

You can test it with the following command in any terminal :

ab -n 10000 -c 25 http://YOUR_LOAD_BALANCER_URL/ping

5. Explore Copilot

To learn more about the copilot commands, checkout the documentation.

How to deploy an update to your infrastructure ?

You have 2 possibilities.

  1. Automate it using copilot pipelines

You can set up CI/CD pipelines using Copilot where it will watch for a specific branch, on a specific repository and deploy your updated code to the specified environment.

A classic usage would be to have a dev pipeline on the ‘develop’ branch that will deploy to the dev environment.

Learn more about Copilot pipelines here.

2. Have more control and deploy using one command: copilot deploy.

The copilot deploy will help you deploy your current folder to the specified infrastructure.You can then follow the progress on both your terminal and the AWS console.For those 2 approaches, ECS is smart enough to not deploy a new version that is not working.

It checks the health status of your new instance and will not propagate it further if it sees it is not healthy. It is a life saver feature to avoid breaking everything !

How to set up auto scaling policies ?

By editing your Service, inside the AWS ECS console, you can add scaling policies based on CPU, Memory or Number of requests.

Your Fargate infrastructure will automatically scale your resources to handle the load.

Copilot at Vespucci

Copilot truly helped us move faster to our Dockerization. It also helps our developers focus on writing efficient code rather than spending hours deploying an update.

With automated tests written for our NodeJS backend, every deployment is safe and automated, and we ship new features with confidence.

To learn more about what we do at Vespucci, visit our website, and if you are interested, we are always hiring talented people! Feel free to check open positions here.