Skip to content

Commit

Permalink
[MERGE] dev, prod code deploy 설정 수정
Browse files Browse the repository at this point in the history
[ENV] dev, prod code deploy 설정 수정
  • Loading branch information
05AM authored Oct 3, 2023
2 parents 0e037c5 + a26bc08 commit d766fe4
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/cicd_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ jobs:
- name: Copy Jar
run: cp ./server/build/libs/*.jar ./deploy

- name: Copy appspec.yml
run: cp appspec.yml ./deploy
- name: Copy appspec_dev.yml
run: cp appspec_dev.yml ./deploy

- name: Copy script
run: cp ./scripts/deploy.sh ./deploy
run: cp ./scripts/deploy_dev.sh ./deploy

- name: Make zip file
run: zip -r ./tattour_server_dev.zip ./deploy
Expand All @@ -72,7 +72,7 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_CODEDEPLOY_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_CODEDEPLOY_SECRET_ACCESS_KEY }}
run:
aws deploy create-deployment
aws deploy create-deployment
--application-name tattour-codeDepoly-test
--deployment-group-name tattour-codeDepoly-test-group
--file-exists-behavior OVERWRITE
Expand Down
19 changes: 19 additions & 0 deletions appspec_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 0.0
os: linux

files:
- source: /
destination: /home/ubuntu/app
overwrite: yes

permissions:
- object: /
pattern: "**"
owner: ubuntu
group: ubuntu

hooks:
AfterInstall:
- location: deploy_dev.sh
timeout: 100
runas: ubuntu
4 changes: 2 additions & 2 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DEPLOY_PATH=/home/ubuntu/app/nonstop/jar/
cp $BUILD_PATH $DEPLOY_PATH

echo "> 현재 구동중인 Set 확인"
CURRENT_PROFILE=$(curl -s https://dev.tattour.shop/profile)
CURRENT_PROFILE=$(curl -s https://api.tattour.shop/profile)
echo "> $CURRENT_PROFILE"

# 쉬고 있는 set 찾기: set1이 사용중이면 set2가 쉬고 있고, 반대면 set1이 쉬고 있음
Expand Down Expand Up @@ -46,7 +46,7 @@ else
fi

echo "> $IDLE_PROFILE 배포"
echo "> nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=$IDLE_PROFILE $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 & "
# echo "> nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=$IDLE_PROFILE $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 & "
nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=$IDLE_PROFILE $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 &

echo "> $IDLE_PROFILE 10초 후 Health check 시작"
Expand Down
83 changes: 83 additions & 0 deletions scripts/deploy_dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash
BUILD_PATH=$(ls /home/ubuntu/app/server-0.0.1-SNAPSHOT.jar)
JAR_NAME=$(basename $BUILD_PATH)
echo "> build 파일명: $JAR_NAME"

echo "> build 파일 복사"
DEPLOY_PATH=/home/ubuntu/app/nonstop/jar/
cp $BUILD_PATH $DEPLOY_PATH

echo "> 현재 구동중인 Set 확인"
CURRENT_PROFILE=$(curl -s https://dev.tattour.shop/profile)
echo "> $CURRENT_PROFILE"

# 쉬고 있는 set 찾기: set1이 사용중이면 set2가 쉬고 있고, 반대면 set1이 쉬고 있음
if [ $CURRENT_PROFILE == set1 ]
then
IDLE_PROFILE=set2
IDLE_PORT=8082
elif [ $CURRENT_PROFILE == set2 ]
then
IDLE_PROFILE=set1
IDLE_PORT=8081
else
echo "> 일치하는 Profile이 없습니다. Profile: $CURRENT_PROFILE"
echo "> set1을 할당합니다. IDLE_PROFILE: set1"
IDLE_PROFILE=set1
IDLE_PORT=8081
fi

echo "> application.jar 교체"
IDLE_APPLICATION=$IDLE_PROFILE-Tattour.jar
IDLE_APPLICATION_PATH=$DEPLOY_PATH$IDLE_APPLICATION

ln -Tfs $DEPLOY_PATH$JAR_NAME $IDLE_APPLICATION_PATH

echo "> $IDLE_PROFILE 에서 구동중인 애플리케이션 pid 확인"
IDLE_PID=$(pgrep -f $IDLE_APPLICATION)

if [ -z $IDLE_PID ]
then
echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다."
else
echo "> kill -15 $IDLE_PID"
kill -15 $IDLE_PID
sleep 5
fi

echo "> $IDLE_PROFILE 배포"
echo "> nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=$IDLE_PROFILE $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 & "
nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=$IDLE_PROFILE $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 &

echo "> $IDLE_PROFILE 10초 후 Health check 시작"
echo "> curl -s http://localhost:$IDLE_PORT/actuator/health "
sleep 10

for retry_count in {1..10}
do
response=$(curl -s http://localhost:$IDLE_PORT/actuator/health)
up_count=$(echo $response | grep 'UP' | wc -l)

if [ $up_count -ge 1 ]
then # $up_count >= 1 ("UP" 문자열이 있는지 검증)
echo "> Health check 성공"
break
else
echo "> Health check의 응답을 알 수 없거나 혹은 status가 UP이 아닙니다."
echo "> Health check: ${response}"
fi

if [ $retry_count -eq 10 ]
then
echo "> Health check 실패. "
echo "> Nginx에 연결하지 않고 배포를 종료합니다."
exit 1
fi

echo "> Health check 연결 실패. 재시도..."
sleep 10
done

echo "> 스위칭"
sleep 10
/home/ubuntu/app/nonstop/switch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ public ReadCustomRes updateCustom(UpdateCustomReq updateCustomReq) {
}
if (custom.getIsCompleted()) {
discordMessageService.sendCustomApplyMessage(custom);
// Todo : user point 관리자 페이지에서 관리할 수 있도록 하기
// userService.updateUserPoint(custom.getUser(), -custom.getPrice());
userService.updateUserPoint(custom.getUser(), -custom.getPrice());
}
return ReadCustomRes.from(custom);
}
Expand Down

0 comments on commit d766fe4

Please sign in to comment.