Skip to content

Commit

Permalink
merge: 새로운 AWS 계정에서 Dev 환경 CI/CD 구축 #416
Browse files Browse the repository at this point in the history
  • Loading branch information
PgmJun authored Nov 28, 2024
2 parents 8f4a94b + b747628 commit 37b7eef
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 4 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/be-cd-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/be-ci-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
build:
timeout-minutes: 4
runs-on: [ self-hosted, linux, ARM64, dev ]
runs-on: ubuntu-latest

defaults:
run:
Expand Down
32 changes: 32 additions & 0 deletions backend/scripts/dev/health-check.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions backend/scripts/dev/kill-application.sh
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions backend/scripts/dev/replace-new-version.sh
Original file line number Diff line number Diff line change
@@ -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" &

0 comments on commit 37b7eef

Please sign in to comment.