Skip to content

Merge pull request #95 from givery-bootcamp/bug-fix/delete-post #65

Merge pull request #95 from givery-bootcamp/bug-fix/delete-post

Merge pull request #95 from givery-bootcamp/bug-fix/delete-post #65

Workflow file for this run

name: Deploy
on:
push:
branches: main
env:
AWS_REGION: ap-northeast-1
REPOSITORY_NAME_BACKEND: dena-training-2024-team-10-backend
REPOSITORY_NAME_FRONTEND: dena-training-2024-team-10-frontend
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
ECS_CLUSTER: dena-training-2024
ECS_SERVICE: dena-training-2024-team-10
BUCKET_PREFIX: team-10
VITE_API_ENDPOINT_PATH: https://team-0_bk.member0005.track-bootcamp.run
jobs:
# backendをbuildしてartifactに保存する
backend-build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.22'
- name: Build
working-directory: ./backend
run: go build -o myapp
- name: Archive production artifacts
uses: actions/upload-artifact@v4
with:
name: backend-bin
path: |
backend/myapp
docker/backend-ci.Dockerfile
# frontendをbuildしてartifactに保存する
frontend-build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
working-directory: ./frontend
run: npm install
- name: Build
working-directory: ./frontend
run: npm run build
- name: Archive production artifacts
uses: actions/upload-artifact@v4
with:
name: frontend-bin
path: |
frontend
docker/frontend-ci.Dockerfile
# backendのdeploy(ECR更新とサービスのdeploy)
backend-ecr-push:
runs-on: ubuntu-latest
needs: [backend-build]
steps:
- name: Download backend build artifacts
uses: actions/download-artifact@v4
with:
name: backend-bin
- 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: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
- name: Log in to Amazon ECR
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push Docker image
run: |
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
IMAGE_TAG=latest
docker build -f docker/backend-ci.Dockerfile -t $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPOSITORY_NAME_BACKEND:$IMAGE_TAG .
docker push $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPOSITORY_NAME_BACKEND:$IMAGE_TAG
# frontend-ecr-pushを使用する場合はそちらでupdateするのでこちらはコメントアウトする
- name: Update ECS service to force new deployment
run: |
aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --force-new-deployment
# frontendのdeploy(s3へのpush)
# frontend-ecr-pushを使用する場合はこちらはコメントアウトする
# frontend-s3-push:
# runs-on: ubuntu-latest
# needs: [frontend-build]
# if: github.ref == 'refs/heads/deploy'
# steps:
# - name: Download frontend build artifacts
# uses: actions/download-artifact@v4
# with:
# name: frontend-bin
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v4
# with:
# aws-region: ${{ env.AWS_REGION }}
# aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
# - name: Sync files to S3
# run: aws s3 sync frontend/dist s3://dena-training-2024/$BUCKET_PREFIX --delete
# frontendのdeploy(ecrへのpushとサービスのdeploy)
# frontend-s3-pushを使用する場合はこちらはコメントアウトする
frontend-ecr-push:
runs-on: ubuntu-latest
needs: [frontend-build, backend-ecr-push]
steps:
- name: Checkout code
uses: actions/checkout@v2
- 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: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
- name: Log in to Amazon ECR
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push Docker image
run: |
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
IMAGE_TAG=latest
docker build -f docker/frontend-ci.Dockerfile -t $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPOSITORY_NAME_FRONTEND:$IMAGE_TAG .
docker push $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPOSITORY_NAME_FRONTEND:$IMAGE_TAG
- name: Update ECS service to force new deployment
run: |
aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --force-new-deployment