Skip to content

fix: 롤백 시 이미지의 이전 버전을 제대로 불러오지 못하는 오류 수정 #71

fix: 롤백 시 이미지의 이전 버전을 제대로 불러오지 못하는 오류 수정

fix: 롤백 시 이미지의 이전 버전을 제대로 불러오지 못하는 오류 수정 #71

Workflow file for this run

name: Backend None Stop CD
on:
workflow_dispatch:
push:
branches:
- none_stop_deploy
paths:
- backend/**
jobs:
find_now_version:
runs-on: [ self-hosted, devel-up-prod-a ]
outputs:
prev_image_version: ${{steps.find_version.outputs.name}}
steps:
- id: find_version
run: |
PREVIOUS_IMAGE_NAME=$(docker ps --format "{{.Image}}")
echo "name=$PREVIOUS_IMAGE_NAME" >> $GITHUB_OUTPUT
build:
name: 🏗️ Build Jar and Upload Docker Image
needs: find_now_version
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.SUBMODULE_GITHUB_TOKEN }}
- name: 🏗️ Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: 21
- name: 🏗️ Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: 🏗️ Build with Gradle
run: ./gradlew clean bootJar
- name: 🐳 Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 🐳 Docker Image Build and Push
uses: docker/build-push-action@v6
with:
context: ./backend
push: true
tags: ${{ secrets.DOCKER_REPOSITORY_NAME }}:${{ github.sha }}
platforms: linux/arm64
deployToA:
name: 🚀 Server A Deployment
needs: build
runs-on: [ self-hosted, devel-up-prod-a ]
defaults:
run:
working-directory: backend
env:
BACKEND_APP_IMAGE_NAME: ${{ secrets.DOCKER_REPOSITORY_NAME }}:${{ github.sha }}
steps:
- uses: actions/checkout@v4
- name: 🐳 Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 🐳 Docker Compose up
run: docker compose -f compose.yml up -d
healthCheckA:
name: 🙏 Server A Health Check
needs: deployToA
if: success()
defaults:
run:
working-directory: backend
runs-on: [ self-hosted, devel-up-prod-a ] # 헬스 체크 방식 고민
steps:
- name: ♻️ Send Helth Check Request
run: chmod u+x ./scripts/healthcheck.sh && ./scripts/healthcheck.sh
rollBackA:
name: 🚀 Server A RollBack
needs: [healthCheckA, find_now_version]
if: failure()
runs-on: [ self-hosted, devel-up-prod-a ]
defaults:
run:
working-directory: backend
env:
BACKEND_APP_IMAGE_NAME: ${{ needs.find_now_version.outputs.prev_image_version }}
steps:
- run: |
echo ${{ needs.find_now_version.outputs.PREVIOUS_IMAGE_NAME }}
echo ${{env.BACKEND_APP_IMAGE_NAME}}
echo ${{env.name}}
- uses: actions/checkout@v4
- name: 🐳 Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 🐳 Docker Compose up
run: docker compose -f compose.yml up -d
healthCheckAAfterRollBack:
name: 🙏 Server A Health Check After RollBack
needs: rollBackA
if: success()
defaults:
run:
working-directory: backend
runs-on: [ self-hosted, devel-up-prod-a ] # 헬스 체크 방식 고민
steps:
- name: ♻️ Send Helth Check Request
run: chmod u+x ./scripts/healthcheck.sh && ./scripts/healthcheck.sh
deployToB:
name: 🚀 Server B Deployment
needs: healthCheckA
if: success()
runs-on: [ self-hosted, devel-up-prod-b ]
defaults:
run:
working-directory: backend
env:
BACKEND_APP_IMAGE_NAME: ${{ secrets.DOCKER_REPOSITORY_NAME }}:${{ github.sha }}
steps:
- uses: actions/checkout@v4
- name: 🐳 Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 🐳 Docker Compose up
run: docker compose -f compose.yml up -d
healthCheckB:
name: 🙏 Server B Health Check
needs: deployToB
if: success()
defaults:
run:
working-directory: backend
runs-on: [ self-hosted, devel-up-prod-b ] # 헬스 체크 방식 고민
steps:
- name: ♻️ Send Helth Check Request
run: chmod u+x ./scripts/healthcheck.sh && ./scripts/healthcheck.sh
# slack-notify_success:
# runs-on: ubuntu-latest
# needs:
# - build
# - deploy
# if: success()
# steps:
# - name: Extract Commit Title
# run: |
# COMMIT_TITLE=$(echo "${{ github.event.head_commit.message }}" | head -n 1)
# echo "COMMIT_TITLE=$COMMIT_TITLE" >> $GITHUB_ENV
#
# - name: Build and Deploy Success
# uses: slackapi/[email protected]
# with:
# channel-id: ${{ secrets.ISSUE_CHANNEL }}
# payload: |
# {
# "text": "Build and Deploy Status",
# "blocks": [
# {
# "type": "section",
# "text": {
# "type": "mrkdwn",
# "text": "<!channel> \n 📣 Server Build & Deploy 결과를 안내 드립니다. 📣 \n\t • 🚀 Build Success \n\t • 🟢 Deploy Success \n\t • 🏷️ 관련 Commit: <${{ github.event.head_commit.url }}|${{ env.COMMIT_TITLE }}>"
# }
# }
# ]
# }
# env:
# SLACK_BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
#
# slack-notify_build-fail:
# runs-on: ubuntu-latest
# needs:
# - build
# if: failure()
# steps:
# - name: Extract Commit Title
# run: |
# COMMIT_TITLE=$(echo "${{ github.event.head_commit.message }}" | head -n 1)
# echo "COMMIT_TITLE=$COMMIT_TITLE" >> $GITHUB_ENV
#
# - name: Build Fail
# uses: slackapi/[email protected]
# with:
# channel-id: ${{ secrets.ISSUE_CHANNEL }}
# payload: |
# {
# "text": "Build and Deploy Status",
# "blocks": [
# {
# "type": "section",
# "text": {
# "type": "mrkdwn",
# "text": "<!channel> \n 📣 Server Build & Deploy 결과를 안내 드립니다. 📣 \n\t • 🔴 Build Fail \n\t • 🏷️ 관련 Commit: <${{ github.event.head_commit.url }}|${{ env.COMMIT_TITLE }}>"
# }
# }
# ]
# }
# env:
# SLACK_BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
#
# slack-notify_deploy-fail:
# runs-on: ubuntu-latest
# needs:
# - deploy
# if: failure()
# steps:
# - name: Extract Commit Title
# run: |
# COMMIT_TITLE=$(echo "${{ github.event.head_commit.message }}" | head -n 1)
# echo "COMMIT_TITLE=$COMMIT_TITLE" >> $GITHUB_ENV
#
# - name: Deploy Fail
# uses: slackapi/[email protected]
# with:
# channel-id: ${{ secrets.ISSUE_CHANNEL }}
# payload: |
# {
# "text": "Build and Deploy Status",
# "blocks": [
# {
# "type": "section",
# "text": {
# "type": "mrkdwn",
# "text": "<!channel> \n 📣 Server Build & Deploy 결과를 안내 드립니다. 📣 \n\t • 🚀Build Success \n\t • 🔴Deploy Fail \n\t • 🏷️ 관련 Commit: <${{ github.event.head_commit.url }}|${{ env.COMMIT_TITLE }}>"
# }
# }
# ]
# }
# env:
# SLACK_BOT_TOKEN: ${{ secrets.BOT_TOKEN }}