Merge pull request #40 from Team-BomBomBom/feat/coupon_issuance_page#β¦ #28
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: Deploy NextJs To ECR | ||
on: | ||
push: | ||
branches: ['develop'] | ||
workflow_dispatch: | ||
jobs: | ||
deploy: | ||
if: ${{ secrets.ENABLE_CD == 'true' }} | ||
Check failure on line 10 in .github/workflows/deploy.yml GitHub Actions / Deploy NextJs To ECRInvalid workflow file
|
||
env: | ||
AWS_REGION: ap-northeast-2 | ||
ECR_REPOSITORY: devs-nextjs | ||
ECS_SERVICE: devs-nextjs-service | ||
ECS_CLUSTER: devs-nextjs-cluster | ||
ECS_TASK_DEFINITION: ./devs-nextjs-task.json | ||
CONTAINER_NAME: nextjs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20' | ||
cache: 'npm' | ||
- name: Restore cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
.next/cache | ||
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} | ||
restore-keys: | | ||
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Build with Next.js | ||
env: | ||
NEXT_PUBLIC_API_SERVER_URL: https://api.dev-study.com | ||
run: npm run build | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.ECR_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.ECR_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
- name: Build and Push Image to Amazon ECR | ||
uses: docker/build-push-action@v3 | ||
id: build-and-push | ||
env: | ||
ECR: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }} | ||
with: | ||
context: . | ||
push: true | ||
provenance: false | ||
tags: ${{ env.ECR }}:${{ github.sha }} | ||
platforms: linux/arm64 | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
- name: Fill in the new image ID in the Amazon ECS task definition | ||
id: task-def | ||
uses: aws-actions/amazon-ecs-render-task-definition@v1 | ||
with: | ||
task-definition: ${{ env.ECS_TASK_DEFINITION }} | ||
container-name: ${{ env.CONTAINER_NAME }} | ||
image: ${{ fromJSON(steps.build-and-push.outputs.metadata)['image.name'] }} | ||
- 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: ${{ env.ECS_SERVICE }} | ||
cluster: ${{ env.ECS_CLUSTER }} | ||
wait-for-service-stability: true |