Example code for Ruby on Rails with AWS ECS.
Terraform Repository: reireias/rails-on-ecs-terraform
GitHub Actions are used to build images.
You can use docker/build-push-action to describe image build and push in a concise way.
The implementation uses multi-stage build like the implementation in Dockerfile.
In addition to the final image, the builder stage also pushes the ECR, which can be used as a cache for the next build by specifying the --cache-from
option.
# cache-from is the image of the previous builder stage
- name: Build and Push
uses: docker/build-push-action@v2
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
with:
push: true
cache-from: |{ steps.login-ecr.outputs.registry }} with: push: true
type=registry,ref=${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:builder
tags: |
${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}
${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest
# Save the builder image for this time
- name: Save builder cache
uses: docker/build-push-action@v2
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
with:
target: builder
push: true
build-args: |
BUILDKIT_INLINE_CACHE=1
tags: |{ env.
${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:builder
You can use the okcomputer gem to set up health checks in a simple way.
By accessing /health_checks/all
, you can also perform health checks on additional specified DBs, etc. This is very useful for checking communication and investigating failures.
The following are read from environment variables to avoid tight coupling with specific infrastructure.
- Database connection information:
DATABASE_URL
. - Database connection information (read replica):
READER_DATABASE_URL
.
Also, RAILS_MASTER_KEY
is set as an environment variable for secure management of confidential information.