Skip to content

롤백 성공 시 알림 테스트 #84

롤백 성공 시 알림 테스트

롤백 성공 시 알림 테스트 #84

Workflow file for this run

name: Backend None Stop CD
on:
workflow_dispatch:
push:
branches:
- none_stop_deploy
paths:
- backend/**
jobs:
findPreviousImageVersion:
name: 🔎Find Previous Docker Image Version
runs-on: [ self-hosted, devel-up-prod-a ]
outputs:
previousImageVersion: ${{steps.find_version.outputs.name}}
steps:
- id: find_version
run: |
PREVIOUS_IMAGE_NAME=$(docker ps --format "{{.Image}}")
echo "name=$PREVIOUS_IMAGE_NAME" >> $GITHUB_OUTPUT
echo $PREVIOUS_IMAGE_NAME
build:
name: 🏗️ Build Jar and Upload Docker Image
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
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, findPreviousImageVersion]
if: failure()
runs-on: [ self-hosted, devel-up-prod-a ]
defaults:
run:
working-directory: backend
env:
BACKEND_APP_IMAGE_NAME: ${{ needs.findPreviousImageVersion.outputs.previousImageVersion }}
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
healthCheckAAfterRollBack:
name: 🙏 Server A Health Check After RollBack
needs: rollBackA
if : ${{always() && needs.rollBackA.result != 'skipped'}}
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: ${{needs.healthCheckA.result == '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
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
deploySuccessNotifiy:
name: 📢Send Deploy Success Notification
runs-on: ubuntu-latest
needs:
- healthCheckA
- healthCheckB
if: ${{needs.healthCheckA.result == 'success' && needs.healthCheckB.result == '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 }}
deployToBFailNotifiy:
name: 📢Send Deploy To Server B Fail Notification
runs-on: ubuntu-latest
needs:
- healthCheckB
if: ${{failure() && needs.healthCheckB.result == '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 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 • 🔴 Server B Deploy Fail \n\t • 🏷️ 관련 Commit: <${{ github.event.head_commit.url }}|${{ env.COMMIT_TITLE }}>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
rollBackSuccessNotifiy:
name: 📢Send Server A RollBack Success Notification
runs-on: ubuntu-latest
needs:
- healthCheckAAfterRollBack
if: ${{needs.healthCheckAAfterRollBack.result == '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 • 🟠 Server A RollBack Success \n\t • 🏷️ 관련 Commit: <${{ github.event.head_commit.url }}|${{ env.COMMIT_TITLE }}>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
rollBackFailNotifiy:
name: 📢Send Server A RollBack Fail Notification
runs-on: ubuntu-latest
needs:
- healthCheckAAfterRollBack
if: ${{failure() && needs.healthCheckAAfterRollBack.result == '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 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 • 🔴Server A RollBack Fail \n\t • 🏷️ 관련 Commit: <${{ github.event.head_commit.url }}|${{ env.COMMIT_TITLE }}>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.BOT_TOKEN }}