Build and Deploy 56/merge by seheon99 #2
Workflow file for this run
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: Deployment | |
run-name: Build and Deploy ${{ github.ref_name }} by ${{ github.actor }} | |
on: | |
push: | |
branches: | |
- dev | |
pull_request: | |
branches: | |
- dev | |
permissions: | |
id-token: write | |
contents: read | |
env: | |
ECR_IMAGE_LATEST: ${{ secrets.ECR_REGISTRY_URI }}:latest | |
ECR_IMAGE_SHA: ${{ secrets.ECR_REGISTRY_URI }}:${{ github.sha }} | |
TASK_DEFINITION: task-def.json | |
PERFORMANCE_BUDGET: budget.json | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: ap-northeast-2 | |
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }} | |
role-session-name: GHA-ECR-Build | |
- name: Login to Amazon ECR | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: ${{ env.ECR_IMAGE_LATEST }}, ${{ env.ECR_IMAGE_SHA }} | |
create-github-deployment: | |
name: Create GitHub Deployment | |
runs-on: ubuntu-latest | |
needs: build | |
environment: development | |
outputs: | |
DEPLOYMENT_ID: ${{ steps.create-deployment.outputs.result }} | |
steps: | |
- name: Create GitHub Deployment | |
uses: actions/github-script@v7 | |
id: create-deployment | |
with: | |
script: | | |
const deployment = await github.rest.repos.createDeployment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: ${{ github.ref }}, | |
environment: 'development', | |
description: `Deployed ${{ github.ref_name }} by ${{ github.actor }}`, | |
}); | |
return deployment.data.id; | |
- name: Update GitHub Deployment Status | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
github.rest.repos.createDeploymentStatus({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
deployment_id: ${{ steps.create-deployment.outputs.result }}, | |
state: 'in_progress', | |
environment: 'development', | |
description: `Deployed ${{ github.ref_name }} by ${{ github.actor }}`, | |
}) | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
needs: create-github-deployment | |
environment: development | |
steps: | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: ap-northeast-2 | |
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }} | |
role-session-name: GHA-ECS-Deploy | |
- name: Add task definition | |
run: | | |
echo '${{ vars.TASK_DEFINITION }}' > ${{ env.TASK_DEFINITION }} | |
- name: Render Amazon ECS task definition | |
id: task-def | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: ${{ env.TASK_DEFINITION }} | |
container-name: ${{ vars.ECS_CONTAINER_NAME }} | |
image: ${{ env.ECR_IMAGE_SHA }} | |
- name: Deploy Amazon ECS task definition | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
with: | |
task-definition: ${{ steps.task-def.outputs.task-definition }} | |
service: ${{ vars.ECS_SERVICE_NAME }} | |
cluster: ${{ vars.ECS_CLUSTER_NAME }} | |
wait-for-service-stability: true | |
update-github-deployment-status: | |
name: Update GitHub Deployment Status | |
runs-on: ubuntu-latest | |
needs: | |
- create-github-deployment | |
- deploy | |
environment: development | |
steps: | |
- name: Update GitHub Deployment Status | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
github.rest.repos.createDeploymentStatus({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
deployment_id: ${{ needs.create-github-deployment.outputs.DEPLOYMENT_ID }}, | |
state: 'success', | |
environment: 'development', | |
description: `Deployed ${{ github.ref_name }} by ${{ github.actor }}`, | |
}) |