Skip to content

Deploy to Amazon ECS #62

Deploy to Amazon ECS

Deploy to Amazon ECS #62

Workflow file for this run

name: Deploy to Amazon ECS
on:
workflow_run:
workflows: ["Run Tests (Frontend)"]
branches: [main]
types:
- completed
env:
AWS_REGION: us-east-1 # AWS region
ECR_REPOSITORY_BACKEND: atlas-backend
ECR_REPOSITORY_FRONTEND: atlas-frontend
ECS_SERVICE: atlas-multi-service # Amazon ECS service name
ECS_CLUSTER: atlas-dev # Amazon ECS cluster name
ECS_TASK_DEFINITION: .aws/task-definition.json # Amazon ECS task definition
CONTAINER_NAME_BACKEND: backend
CONTAINER_NAME_FRONTEND: frontend
CONTAINER_NAME_CELERY: celery
permissions:
id-token: write
contents: read
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_PROD_ID }}
aws-secret-access-key: ${{ secrets.AWS_PROD_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build, tag, and push backend image to Amazon ECR
id: build-backend-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY_BACKEND:$IMAGE_TAG -f Dockerfile.server .
docker push $ECR_REGISTRY/$ECR_REPOSITORY_BACKEND:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY_BACKEND:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Build, tag, and push frontend image to Amazon ECR
id: build-front-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY_FRONTEND:$IMAGE_TAG -f Dockerfile.client .
docker push $ECR_REGISTRY/$ECR_REPOSITORY_FRONTEND:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY_FRONTEND:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition for backend
id: render-backend-container
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME_BACKEND }}
image: ${{ steps.build-backend-image.outputs.image }}
- name: Fill in the new image ID in the Amazon ECS task definition for backend
id: render-celery-container
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ steps.render-backend-container.outputs.task-definition }}
container-name: ${{ env.CONTAINER_NAME_CELERY }}
image: ${{ steps.build-backend-image.outputs.image }}
- name: Fill in the new image ID in the Amazon ECS task definition for frontend
id: render-frontend-container
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ steps.render-celery-container.outputs.task-definition }}
container-name: ${{ env.CONTAINER_NAME_FRONTEND }}
image: ${{ steps.build-front-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.render-frontend-container.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true