Angular refactor #18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy Backend and Frontend | |
on: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: read | |
env: | |
CLUSTER_NAME: calendar-app-v2 | |
jobs: | |
build-backend: | |
name: Build backend and push to ECR | |
runs-on: ubuntu-latest | |
environment: build-backend | |
permissions: | |
id-token: write | |
contents: read | |
outputs: | |
image: ${{ steps.build-image.outputs.image }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
audience: sts.amazonaws.com | |
aws-region: ${{ vars.AWS_REGION }} | |
role-to-assume: ${{ vars.AWS_ROLE }} | |
- name: Log in to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build, tag, and push backend Docker image | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: calendar-app-backend | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./backend | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
build-frontend: | |
name: Build frontend and push to ECR | |
runs-on: ubuntu-latest | |
environment: build-frontend | |
permissions: | |
id-token: write | |
contents: read | |
outputs: | |
image: ${{ steps.build-image.outputs.image }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
audience: sts.amazonaws.com | |
aws-region: ${{ vars.AWS_REGION }} | |
role-to-assume: ${{ vars.AWS_ROLE }} | |
- name: Log in to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build, tag, and push frontend Docker image | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: calendar-app-frontend | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./frontend | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
deploy-backend: | |
name: Deploy Backend to ECS | |
runs-on: ubuntu-latest | |
environment: deploy-backend | |
needs: build-backend | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
audience: sts.amazonaws.com | |
aws-region: ${{ vars.AWS_REGION }} | |
role-to-assume: ${{ vars.AWS_ROLE }} | |
- name: Download backend task definition | |
run: | | |
aws ecs describe-task-definition --task-definition calendar-app-backend --query taskDefinition > backend-task-def.json | |
- name: Render Amazon ECS backend task definition | |
id: render-backend | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: backend-task-def.json | |
container-name: backend | |
image: ${{ needs.build-backend.outputs.image }} | |
- name: Deploy Amazon ECS backend task definition | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
with: | |
task-definition: ${{ steps.render-backend.outputs.task-definition }} | |
service: backend-service | |
cluster: ${{ env.CLUSTER_NAME }} | |
wait-for-service-stability: true | |
deploy-frontend: | |
name: Deploy Frontend to ECS | |
runs-on: ubuntu-latest | |
environment: deploy-frontend | |
needs: build-frontend | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
audience: sts.amazonaws.com | |
aws-region: ${{ vars.AWS_REGION }} | |
role-to-assume: ${{ vars.AWS_ROLE }} | |
- name: Download frontend task definition | |
run: | | |
aws ecs describe-task-definition --task-definition calendar-app-frontend --query taskDefinition > frontend-task-def.json | |
- name: Render Amazon ECS frontend task definition | |
id: render-frontend | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: frontend-task-def.json | |
container-name: frontend | |
image: ${{ needs.build-frontend.outputs.image }} | |
- name: Deploy Amazon ECS frontend task definition | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
with: | |
task-definition: ${{ steps.render-frontend.outputs.task-definition }} | |
service: frontend-service | |
cluster: ${{ env.CLUSTER_NAME }} | |
wait-for-service-stability: true |