Skip to content

Fix an registry name #6

Fix an registry name

Fix an registry name #6

name: Deploy Backend to Staging
on:
push:
branches:
- main
workflow_dispatch: null
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
actions: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4.0.2
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/realworld-example-github-actions-role
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to AWS ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push Nginx Docker image
id: build-nginx-image
uses: docker/build-push-action@v4
with:
context: ./deploy/nginx
push: true
tags: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/realworld-example-staging-backend-proxy-ecr-repo:latest
- name: Build and push backend Docker image
id: build-backend-image
uses: docker/build-push-action@v4
with:
context: .
file: ./deploy/go/Dockerfile
push: true
tags: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/realworld-example-staging-backend-app-ecr-repo:latest
- name: Render task definition from template
id: render-task-def
run: envsubst < deploy/taskdef-template.json > taskdef.json
env:
PROXY_IMAGE_URI: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/realworld-example-staging-backend-proxy-ecr-repo:latest
APP_IMAGE_URI: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/realworld-example-staging-backend-app-ecr-repo:latest
PROJECT: realworld-example
APP_ENV: staging
DB_HOST: ${{ secrets.DB_HOST }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_NAME: ${{ secrets.DB_NAME }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
ALLOWED_ORIGINS: ${{ secrets.ALLOWED_ORIGINS }}
- name: Register ECS task definition
id: register-task-def
run: |
TASK_DEF_ARN=$(aws ecs register-task-definition \
--family realworld-example-staging-backend-ecs-task \
--execution-role-arn arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/realworld-example-staging-ecs-task-execution-role \
--task-role-arn arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/realworld-example-staging-ecs-task-role \
--cli-input-json file://taskdef.json \
--query 'taskDefinition.taskDefinitionArn' \
--output text)
echo "TASK_DEF_ARN=$TASK_DEF_ARN" >> $GITHUB_ENV
- name: Update ECS service
run: |
aws ecs update-service --cluster realworld-example-staging-ecs-cluster --service realworld-example-staging-backend-ecs-service --task-definition ${{ env.TASK_DEF_ARN }} --force-new-deployment