Steps for deploying a basic Rails project using AWS Fargate
- Dockerize the project
- Create an Amazon ECR Repository
- Push the Docker image to Amazon ECR
- Create a Task Definition
- Create a Cluster
- Create a Service
- Create a Task
- In the AWS Console go to ECS Task Definitions and click 'Create a new task definition'.
- Under 'Launch Type' check 'AWS Fargate'.
- Under 'Operating system/Architecture' select 'Linux/ARM64'
- Set desired CPU and Memory.
- Under 'Container', enter a container name and your ECR repository URI. Then click 'Docker configuration' and under 'Command' enter
bundle,exec,rails,server
. - Click 'Create'
- In the AWS Console go to ECS Clusters and click 'Create cluster'.
- Under 'Infrastructure' check 'AWS Fargate (serverless)'
- Click 'Create'
- In the 'Services' tab click 'Create'.
- Under 'Networking' select default VPC.
- Under 'Subnets' select one of the default subnets.
- Click 'Create'.
- Go back to your cluster (ECS Clusters and click on your cluster name.)
- In the 'Tasks' tab click 'Run new task'.
-
Cluster is a logical way to group services and task definition.
-
Services are used to run load balancers in front of group of tasks. This is also where you specify how many instances of task should be running.
-
Tasks are the running instances of a task definition.
Update the Dockerfile.
Run
docker build . -t retrofit
docker run -p 3000:3000 retrofit
Check it's up and running at http://localhost:3000
.
In the AWS console go to ECR Private Repositories, click 'Create Repository' to create a new private repository.
(See AWS documentation)
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.<region>.amazonaws.com
Run docker images
to get the image id.
Get the ECR repository URI from the AWC ECR console.
Tag the docker image:
docker tag <image_id> <repository_uri>:<optional_tag>
docker push <repository_uri>:<optional_tag>
(See AWS documentation)
In ECS Clusters click on your cluster name.
TBC!