Skip to content

Fix env

Fix env #45

name: Deploy 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-frontend-proxy-ecr-repo:latest
- name: Build and push frontend Docker image
id: build-frontend-image
uses: docker/build-push-action@v4
with:
context: .
file: ./deploy/nuxt/Dockerfile
push: true
tags: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/realworld-example-staging-frontend-app-ecr-repo:latest
build-args: |
API_BASE_URL=${{ secrets.API_BASE_URL }}
- 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-frontend-proxy-ecr-repo:latest
APP_IMAGE_URI: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/realworld-example-staging-frontend-app-ecr-repo:latest
PROJECT: realworld-example
APP_ENV: staging
- name: Register ECS task definition
id: register-task-def
run: |
TASK_DEF_ARN=$(aws ecs register-task-definition \
--family realworld-example-staging-frontend-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-frontend-ecs-service --task-definition ${{ env.TASK_DEF_ARN }} --force-new-deployment