[Part 1] How to deploy Docker containers and static files with CircleCI + ECS + ECR + CloudFront


I set up CircleCI, Amazon ECS, and ECR in an environment where Docker containers are continuously deployed, put Assets files (CSS, JS) in a bucket of s3, and sent them to CloudFront for deployment. I would like to briefly summarize the series of steps.

Rough procedure

ECS + ECR side setup

  1. Create an ECS cluster
  2. Create a container instance (I chose EC2 this time)
  3. Create an ECR repository
  4. Create an ECS task definition
  5. Create ALB
  6. Create an ECS service

S3 + CloudFront setup

  1. Create an S3 bucket
  2. Create a CloudFront account
  3. Specify the S3 bucket for CloudFront's Orign Name
  4. Specify Alternate Domain Names (CNAMEs)
  5. Tuning CloudFront

Overall view

スクリーンショット 2020-12-19 23.39.23.png

About setup on the ECS + ECR side

1. Create an ECS cluster

What is ECS in the first place?

スクリーンショット 2020-12-20 0.21.43.png


スクリーンショット 2020-12-20 0.22.57.png

--Select EC2 Linux + Networking for cluster template --Enter the cluster name ex) sample-cluster --Create an empty cluster --Do not set the instance here スクリーンショット 2020-12-19 23.45.03.png

2. Create a container instance (I chose EC2 this time)


--Select amzn2-ami-ecs-hvm-2.0 for AMI --Select t2.micro for the instance size --Select a network (vpc) --Select a subnet --Select the role (created) of Instance of ecs in IAM role --Enter user data as follows --Enter the cluster name in place of YOUR_CLUSTER_NAME

echo ECS_CLUSTER=YOUR_CLUSTER_NAME >> /etc/ecs/ecs.config


--Create a new security group --Create a key pair

3. Create an ECR repository

What is ECR in the first place?

スクリーンショット 2020-12-20 0.27.31.png

--Choose private --Enter the repository name ex) sample-repository スクリーンショット 2020-12-19 23.54.00.png

4. Create an ECS task definition

--Select EC2 as the type --Enter the definition name ex) sample-task --Select ecsTaskExecutionRole for the role --Select bridge for network --If you want to know about the network, please refer to this site. --Do not select the task size here, select the size in the container --Enter the container name ex) sample-app --Enter the image with a tag attached to the ECR URI created earlier ex) xxxxxxxxxxxxx.com/sample-repository:latest --Insert memory limit --At first, 300-500 may be fine --I want the port to be dynamic port mapping, so set the host to 0 and the container to 80.

Screenshot 2020-12-20 0.05.02.png

5. Create ALB

--Enter the ALB name ex) alb-sample --Insert listener ex) HTTP, HTTPS --Enter the Availability Zone and select the same vpc as when you created the EC2 instance. --Select a subnet --Choose a server certificate --Select the security group created when creating the EC2 instance --Create a new target group --Select an instance as the target type

スクリーンショット 2020-12-20 0.11.35.png

6. Create an ECS service

--Select EC2 as the startup type --Select the task created earlier ex) sample-task --Select the cluster created earlier ex) sample-cluster --Enter the service name ex) sample-service --Select 1 for the number of tasks for now --ALB chooses the one you selected earlier --Select the target group you created earlier

Amazon-ECS (4).png

The above is a rough ECS and ECR setup procedure.

S3 + CloudFront setup

I will summarize this in the next article! !!

Recommended Posts

[Part 1] How to deploy Docker containers and static files with CircleCI + ECS + ECR + CloudFront
[Part 2] Automatically test and deploy WEB services created with Rails + Nuxt + MySQL + Docker with ECS / ECR / CircleCI to make them terraform
How to share files with Docker Toolbox
[Part 1] WEB service created with Rails + Nuxt + MySQL + Docker is automatically tested and deployed with ECS / ECR / CircleCI and converted to terraform.
How to deploy to AWS using NUXTJS official S3 and CloudFront? With docker-compose
[AWS] How to automatically deploy a Web application created with Rails 6 to ECR / ECS using CircleCI ① Preparation [Container deployment]
Run Rubocop and RSpec on CircleCI and deploy to ECS
How to check CircleCI code and automatically deploy to Heroku
[AWS] What are ECR and ECS? About each difference and how to operate Docker on AWS.
How to start Camunda with Docker
Enable Docker build cache on GitHub Action and deploy to Amazon ECS
How to use args :, environment :, env_file: and .env files with docker-compose command
[Node.js express Docker] How to define Docker environment variables and load them with node.js
[Rails] How to use rails console with docker
Deploy to heroku with Docker (Rails 6, MySQL)
[Java] How to output and write files!
Note: [Docker] How to start and stop
How to run Blazor (C #) with Docker
How to build Rails 6 environment with Docker
[For super beginners (more screenshots)] Automatically deploy to AWS ECR / ECS with Ruby2.6 x Rails6 x CircleCi [Hands-on format]
How to use ToolBar with super margin Part1 Set characters and change colors
How to update pre-built files in docker container
Deploy Rails to ECS Fargate with AWS Copilot
How to give your image to someone with docker
How to use docker compose with NVIDIA Jetson
How to get resource files out with spring-boot
How to use nginx-ingress-controller with Docker for Mac
[Rails] How to build an environment with Docker
How to build parquet-tools and merge Parquet files
[Rails] [Docker] Copy and paste is OK! How to build a Rails development environment with Docker
[Docker] How to update using a container on Heroku and how to deal with Migrate Error
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
How to deploy
[Introduction to Docker x ECS] ECS deployment with docker compose up
How to deploy to Heroku from a local docker image
How to build docker environment with Gradle for intelliJ
How to deploy Java to AWS Lambda with Serverless Framework
How to make an almost static page with rails
[Docker environment] How to deal with ActiveSupport :: MessageEncryptor :: InvalidMessage
How to delete untagged images in bulk with Docker
How to serialize and deserialize LocalDateTime type with GSON
How to make Laravel faster with Docker for Mac
How to handle TSV files and CSV files in Ruby
How to use RealSense with ubuntu 20.04 and ROS Noetic
How to install Gradle and Kotlin with SDKMAN (Mac)
Common problems with WSL and how to deal with them
[Docker + Rails] How to deal with Rails server startup failure
How to launch Swagger UI and Swagger Editor in Docker
How to develop in a container with --privileged and / sbin / init passed in VSCode Remote Containers
How to add another project as Maven library with CircleCI and use it for build