Skip to content

chore: tweak

chore: tweak #6

Workflow file for this run

name: Application Deployment
on:
push:
branches:
- 'dev'
- 'staging'
- 'production'
env:
REGISTRY: ghcr.io
CONTAINER_NAME: dapp
CLUSTER_NAME: dapp-cluster
TASK_DEFINITION: .github/workflows/task-definition.json
jobs:
build-and-push:
runs-on: ubuntu-latest
environment: ${{ github.ref_name }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
build-args: APP_ENV=${{ github.ref_name }}
push: true
tags: ${{ env.REGISTRY }}/${{ github.repository }}:${{ github.ref_name }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: build-and-push
runs-on: ubuntu-latest
environment: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- 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: ${{ secrets.AWS_REGION }}
- name: Update ECS task definition
env:
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ secrets.AWS_REGION }}
APP_ENV: ${{ github.ref_name }}
IMAGE: ${{ env.REGISTRY }}/${{ github.repository }}:${{ github.ref_name }}
run: |
sed -i 's|${AWS_ACCOUNT_ID}|'"$AWS_ACCOUNT_ID"'|g' ${{ env.TASK_DEFINITION }}
sed -i 's|${AWS_REGION}|'"$AWS_REGION"'|g' ${{ env.TASK_DEFINITION }}
sed -i 's|${APP_ENV}|'"$APP_ENV"'|g' ${{ env.TASK_DEFINITION }}
sed -i 's|${IMAGE}|'"$IMAGE"'|g' ${{ env.TASK_DEFINITION }}
sed -i 's|${CONTAINER_NAME}|'"${{ env.CONTAINER_NAME }}"'|g' ${{ env.TASK_DEFINITION }}
sed -i 's|${CLUSTER_NAME}|'"${{ env.CLUSTER_NAME }}"'|g' ${{ env.TASK_DEFINITION }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ env.TASK_DEFINITION }}
service: ${{ env.CONTAINER_NAME }}-ecs-service
cluster: ${{ env.CLUSTER_NAME }}-${{ github.ref_name }}-ecs-cluster
wait-for-service-stability: true