Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: 무중단 배포 Workflow 전략 수정 #565 #568

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/backend-ci-cd-multi-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Backend CI/CD multi prod

on:
pull_request:
paths: [ 'backend/**', '.github/**' ]
branches: [ "develop" ]

jobs:
ci:
runs-on: [ self-hosted, dev ]

defaults:
run:
shell: bash
working-directory: ./backend

permissions:
contents: read

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Setup with Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

- name: Build with Gradle
run: ./gradlew clean build

- name: Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_DEPLOY_USERNAME }}
password: ${{ secrets.DOCKERHUB_DEPLOY_TOKEN }}

- name: Docker Image Build
run: |
sudo docker build --platform linux/arm64 -t staccato/staccato:dev -f Dockerfile.dev .

- name: Docker Hub Push
run: |
sudo docker login --username ${{ secrets.DOCKERHUB_DEPLOY_USERNAME }} --password ${{ secrets.DOCKERHUB_DEPLOY_TOKEN }}
sudo docker push staccato/staccato:dev

cd:
needs: ci
runs-on: [ self-hosted, dev ]

steps:
- name: Run deploy script
id: run_deploy
run: bash /home/ubuntu/staccato/deploy.sh
# 스크립트가 exit 1이면 여기서 스텝 실패

- name: Check result # 여기서 롤백전략
if: steps.run_deploy.conclusion == 'failure'
run: bash /home/ubuntu/staccato/rollback.sh

port_switch:
needs: cd
runs-on: [ self-hosted, dev ]
if: ${{ success() }} # cd job의 matrix 모두 성공해야 success -> 현재는 matrix 지정은 하지 않은 상태
steps:
- name: Switch Nginx Ports
run: bash /home/ubuntu/staccato/switch.sh