Skip to content

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

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

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

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