diff --git a/.github/workflows/be-cd-dev.yml b/.github/workflows/be-cd-dev.yml index 77fd36091..aaaa5e030 100644 --- a/.github/workflows/be-cd-dev.yml +++ b/.github/workflows/be-cd-dev.yml @@ -42,11 +42,19 @@ jobs: with: name: app-artifact path: ./backend/build/libs/app.jar + if-no-files-found: error + + - name: Upload deploy scripts + uses: actions/upload-artifact@v4 + with: + name: deploy-scripts + path: ./backend/scripts/dev/ + if-no-files-found: error deploy: needs: build timeout-minutes: 2 - runs-on: [ self-hosted, linux, ARM64, dev ] + runs-on: [ dev, X64, Linux ] steps: - name: Download artifact file @@ -55,8 +63,14 @@ jobs: name: app-artifact path: ~/app + - name: Download deploy scripts + uses: actions/download-artifact@v4 + with: + name: deploy-scripts + path: ~/app/scripts + - name: Replace application to latest - run: sudo sh ~/scripts/replace-new-version.sh + run: sudo sh ~/app/scripts/replace-new-version.sh - name: Health check latest application - run: sudo sh ~/scripts/health-check.sh + run: sudo sh ~/app/scripts/health-check.sh diff --git a/.github/workflows/be-ci-dev.yml b/.github/workflows/be-ci-dev.yml index d388ac600..3d74d9a91 100644 --- a/.github/workflows/be-ci-dev.yml +++ b/.github/workflows/be-ci-dev.yml @@ -11,7 +11,7 @@ on: jobs: build: timeout-minutes: 4 - runs-on: [ self-hosted, linux, ARM64, dev ] + runs-on: ubuntu-latest defaults: run: diff --git a/backend/scripts/dev/health-check.sh b/backend/scripts/dev/health-check.sh new file mode 100644 index 000000000..960d62db9 --- /dev/null +++ b/backend/scripts/dev/health-check.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# 최대 반복 횟수 +MAX_RETRIES=60 + +# 성공 상태 코드와 요청 URL +SUCCESS_STATUS=200 +HEALTH_CHECK_URL="localhost:8080/actuator/health" + +# 반복 시작 +i=1 +while [ "$i" -le "$MAX_RETRIES" ]; do + # HTTP 요청 보내기 + RESPONSE_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$HEALTH_CHECK_URL") + echo "[TRY $i] StatusCode : $RESPONSE_STATUS " + # 상태 코드 확인 + if [ "$RESPONSE_STATUS" -eq "$SUCCESS_STATUS" ]; then + echo "Success: Received $SUCCESS_STATUS status code on attempt $i." + exit 0 + fi + + # 1초 대기 + sleep 1 + + # 반복 변수 증가 + i=$((i + 1)) +done + +# 실패 메시지 +echo "Failure: Did not receive $SUCCESS_STATUS status code within $MAX_RETRIES attempts." +sh kill-application.sh +exit 1 diff --git a/backend/scripts/dev/kill-application.sh b/backend/scripts/dev/kill-application.sh new file mode 100644 index 000000000..d87fdb3c1 --- /dev/null +++ b/backend/scripts/dev/kill-application.sh @@ -0,0 +1,9 @@ +PID=$(lsof -t -i:8080) + +# 프로세스 종료 +if [ -z "$PID" ]; then + echo "No process is using port 8080." +else + echo "Killing process with PID: $PID" + kill -15 "$PID" +fi diff --git a/backend/scripts/dev/replace-new-version.sh b/backend/scripts/dev/replace-new-version.sh new file mode 100644 index 000000000..c94ac3191 --- /dev/null +++ b/backend/scripts/dev/replace-new-version.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +PID=$(lsof -t -i:8080) + +# 프로세스 종료 +if [ -z "$PID" ]; then + echo "No process is using port 8080." +else + echo "Killing process with PID: $PID" + kill -15 "$PID" + + # 직전 명령(프로세스 종료 명령)이 정상 동작했는지 확인 + if [ $? -eq 0 ]; then + echo "Process $PID terminated successfully." + else + echo "Failed to terminate process $PID." + fi +fi + +JAR_FILE=$(ls /home/ubuntu/app/*.jar | head -n 1) + +nohup java -Dspring.profiles.active=dev -Duser.timezone=Asia/Seoul -Dserver.port=8080 -jar "$JAR_FILE" &