Skip to content

Commit

Permalink
[#80] fix: 각 jar파일 s3에 묶어 업로드 및 하나씩 실행
Browse files Browse the repository at this point in the history
  • Loading branch information
shinheekim committed Dec 27, 2024
1 parent 4226c57 commit b14fb6a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/itcast-build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ jobs:
run: docker-compose down

- name: Make Zip file
run: zip -r $GITHUB_SHA.zip build/libs/*.jar appspec.yml scripts/deploy.sh
run: zip -r $GITHUB_SHA.zip \
admin/build/libs/*.jar \
schedule/build/libs/*.jar \
b2c/build/libs/*.jar \
appspec.yml scripts/deploy.sh
shell: bash

- name: AWS credential setting
Expand Down
43 changes: 34 additions & 9 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ MODULES=(
["schedule"]="schedule"
)

declare -A PORTS
PORTS=(
["admin"]="8082"
["b2c"]="8080"
["schedule"]="8081"
)

echo "$(date) >>> 배포 시작" >> $LOG_PATH

for MODULE in "${!MODULES[@]}"
do
MODULE_NAME=${MODULES[$MODULE]}
MODULE_DEPLOY_PATH=$DEPLOY_BASE_PATH/$MODULE_NAME
PORT=${PORTS[$MODULE]}

echo ">>> $MODULE_NAME 배포 시작" >> $LOG_PATH

Expand All @@ -25,31 +33,48 @@ do
echo ">>> $MODULE_NAME 디렉토리 생성 완료" >> $LOG_PATH

# 빌드된 JAR 파일 찾기
BUILD_JAR=$(ls /home/ubuntu/itcast/$MODULE_NAME/build/libs/*.jar)
BUILD_JAR=$(ls /home/ubuntu/itcast/$MODULE_NAME/build/libs/*.jar 2>> $ERR_LOG_PATH)
if [ ! -f "$BUILD_JAR" ]; then
echo ">>> $MODULE_NAME JAR 파일을 찾을 수 없습니다. 배포 중단." >> $ERR_LOG_PATH
continue
fi
JAR_NAME=$(basename $BUILD_JAR)
echo ">>> $MODULE_NAME build 파일명: $JAR_NAME" >> $LOG_PATH

# JAR 파일 복사
echo ">>> $MODULE_NAME build 파일 복사" >> $LOG_PATH
cp $BUILD_JAR $MODULE_DEPLOY_PATH 2>> $ERR_LOG_PATH
if [ $? -ne 0 ]; then
echo ">>> $MODULE_NAME JAR 복사 실패. 배포 중단." >> $ERR_LOG_PATH
continue
fi
echo ">>> $MODULE_NAME build 파일 복사 완료" >> $LOG_PATH

# 실행 중인 애플리케이션 종료
echo ">>> $MODULE_NAME 실행 중인 애플리케이션 종료" >> $LOG_PATH
PID=$(ps -ef | grep $MODULE_NAME | grep java | awk '{print $2}')
PID=$(lsof -t -i:$PORT)
if [ -n "$PID" ]; then
kill -15 $PID
sleep 2 # 프로세스 종료 대기
echo ">>> $MODULE_NAME 기존 프로세스 종료 완료 (PID: $PID)" >> $LOG_PATH
sleep 5 # 프로세스 종료 대기
PID_CHECK=$(lsof -t -i:$PORT)
if [ -n "$PID_CHECK" ]; then
echo ">>> $MODULE_NAME 강제 종료 중 (PID: $PID_CHECK)" >> $LOG_PATH
kill -9 $PID_CHECK
fi
echo ">>> $MODULE_NAME 기존 프로세스 종료 완료" >> $LOG_PATH
else
echo ">>> $MODULE_NAME 실행 중인 프로세스 없음" >> $LOG_PATH
fi

# 새 JAR 실행
DEPLOY_JAR=$MODULE_DEPLOY_PATH/$JAR_NAME
echo ">>> $MODULE_NAME 새 JAR 실행: $DEPLOY_JAR" >> $LOG_PATH
nohup java -jar -Dspring.profiles.active=prod $DEPLOY_JAR >> $LOG_PATH 2>> $ERR_LOG_PATH &

echo ">>> $MODULE_NAME 배포 완료" >> $LOG_PATH
nohup java -jar -Dspring.profiles.active=prod \
-Dserver.port=$PORT $DEPLOY_JAR >> $MODULE_DEPLOY_PATH/deploy.log 2>> $MODULE_DEPLOY_PATH/deploy_err.log &
if [ $? -eq 0 ]; then
echo ">>> $MODULE_NAME 배포 완료 및 실행 성공" >> $LOG_PATH
else
echo ">>> $MODULE_NAME 실행 실패" >> $ERR_LOG_PATH
fi
done

echo ">>> 배포 완료" >> $LOG_PATH
echo "$(date) >>> 전체 배포 완료" >> $LOG_PATH

0 comments on commit b14fb6a

Please sign in to comment.