Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 새로운 AWS 계정에서 Dev 환경 CI/CD 구축 #419

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사소한 의견) 이것만 해도 잘 작동 합니다~

Suggested change
runs-on: [ dev, X64, Linux ]
runs-on: dev

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

dev가 2개 있어서 환경 구분하려고 일부로 레이블 설정을 전부 해두었습니다~
이런 문제가 앞으로도 있을 것 같은데 동일하게 prod에서도 레이블을 상세 구분하면 어떨까요?


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" &