Skip to content

Merge branch 'main' into stage #129

Merge branch 'main' into stage

Merge branch 'main' into stage #129

Workflow file for this run

# This workflow will build and push a new container image to Amazon ECR,
# and then will deploy a new task definition to Amazon ECS, when there is a push to the "staging" branch.
name: Deploy to Stage Environment
# Stop any pending jobs
concurrency:
group: staging
cancel-in-progress: true
on:
push:
branches: [ "stage" ]
env:
AWS_REGION: us-east-1
ECR_REPOSITORY: appointments
ECS_SERVICE: appointments-service
ECS_CLUSTER: appointments
ECS_TASK_DEFINITION: .aws/task-definition.json
CONTAINER_FRONTEND: frontend
CONTAINER_BACKEND: backend
permissions:
contents: read
jobs:
deploy:
name: Build & Deploy
runs-on: ubuntu-latest
environment:
name: staging
url: https://stage.appointment.day
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push backend to Amazon ECR
id: build-backend
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: backend-${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./backend -f ./backend/deploy.dockerfile
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image_backend=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Build, tag, and push frontend to Amazon ECR
id: build-frontend
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: frontend-${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./frontend -f ./frontend/deploy.dockerfile
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image_frontend=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new backend image ID in the Amazon ECS task definition
id: task-def-backend
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_BACKEND }}
image: ${{ steps.build-backend.outputs.image_backend }}
- name: Fill in the new frontend image ID in the Amazon ECS task definition
id: task-def-frontend
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ steps.task-def-backend.outputs.task-definition }}
container-name: ${{ env.CONTAINER_FRONTEND }}
image: ${{ steps.build-frontend.outputs.image_frontend }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def-frontend.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true