Skip to content

Commit

Permalink
[BE] chore: prod 환경의 CD 스크립트 무중단배포 구축 (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
takoyakimchi authored Oct 22, 2024
1 parent 9144898 commit d6a9005
Showing 1 changed file with 6 additions and 67 deletions.
73 changes: 6 additions & 67 deletions .github/workflows/backend-cd-workflow-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,55 +43,12 @@ jobs:
run: |
sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/2024-friendogly
- name: Find Java Application PID And Kill PID
id: find_pid
- name: Deploy prod-a
run: |
sudo pgrep -f friendogly-0.0.1-SNAPSHOT.jar | xargs sudo kill -9 | true
- name: Check if WAS is running on port 8080 after stop
run: |
PID=$(lsof -t -i:8080 || true)
if [ -n "$PID" ]; then
echo "Server is still running with PID: $PID"
exit 1
else
echo "Server successfully stopped."
fi
- name: Start server
run: |
cd backend/build/libs
echo "File creation time(KR-09:00):"
ls -l --time=ctime friendogly-0.0.1-SNAPSHOT.jar
sudo nohup java -jar friendogly-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod --jwt.secret-key=${{ secrets.JWT_SECRET_KEY }} --jwt.access-expiration-time=${{ secrets.JWT_ACCESS_EXPIRATION_TIME }} --jwt.refresh-expiration-time=${{ secrets.JWT_REFRESH_EXPIRATION_TIME }} --kakao.admin-key=${{ secrets.KAKAO_ADMIN_KEY }} --spring.datasource.writer.hikari.jdbc-url=${{ secrets.MYSQL_RDS_WRITER_URL }} --spring.datasource.writer.hikari.username=${{ secrets.MYSQL_RDS_USERNAME }} --spring.datasource.writer.hikari.password=${{ secrets.MYSQL_RDS_PASSWORD }} --spring.datasource.reader.hikari.jdbc-url=${{ secrets.MYSQL_RDS_READER_URL }} --spring.datasource.reader.hikari.username=${{ secrets.MYSQL_RDS_USERNAME }} --spring.datasource.reader.hikari.password=${{ secrets.MYSQL_PASSWORD }} &
echo "start backend server"
- name: Wait until WAS being started
run: |
URL="http://localhost:8080/healthchecktestapi"
wait_time=0
while true; do
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$URL" | true)
if [[ $HTTP_STATUS =~ ^[0-9]+$ ]] && [ "$HTTP_STATUS" -eq 404 ]; then
echo "WAS has started"
break
fi
if [ $wait_time -ge 120 ]; then
echo "WAS has not started, waited too long"
break
fi
echo "WAS has not yet started"
sleep 3
wait_time=$((wait_time + 3))
done
sudo chmod +x /home/ubuntu/deploy/deploy.sh
sudo /home/ubuntu/deploy/deploy.sh
build-b:
needs: deploy-a
runs-on: self-hosted-prod-b

steps:
Expand Down Expand Up @@ -127,25 +84,7 @@ jobs:
run: |
sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/2024-friendogly
- name: Find Java Application PID And Kill PID
id: find_pid
run: |
sudo pgrep -f friendogly-0.0.1-SNAPSHOT.jar | xargs sudo kill -9 | true
- name: Check if WAS is running on port 8080 after stop
run: |
PID=$(lsof -t -i:8080 || true)
if [ -n "$PID" ]; then
echo "Server is still running with PID: $PID"
exit 1
else
echo "Server successfully stopped."
fi
- name: Start server
- name: Deploy prod-b
run: |
cd backend/build/libs
echo "File creation time(KR-09:00):"
ls -l --time=ctime friendogly-0.0.1-SNAPSHOT.jar
sudo nohup java -jar friendogly-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod --jwt.secret-key=${{ secrets.JWT_SECRET_KEY }} --jwt.access-expiration-time=${{ secrets.JWT_ACCESS_EXPIRATION_TIME }} --jwt.refresh-expiration-time=${{ secrets.JWT_REFRESH_EXPIRATION_TIME }} --kakao.admin-key=${{ secrets.KAKAO_ADMIN_KEY }} --spring.datasource.writer.hikari.jdbc-url=${{ secrets.MYSQL_RDS_WRITER_URL }} --spring.datasource.writer.hikari.username=${{ secrets.MYSQL_RDS_USERNAME }} --spring.datasource.writer.hikari.password=${{ secrets.MYSQL_RDS_PASSWORD }} --spring.datasource.reader.hikari.jdbc-url=${{ secrets.MYSQL_RDS_READER_URL }} --spring.datasource.reader.hikari.username=${{ secrets.MYSQL_RDS_USERNAME }} --spring.datasource.reader.hikari.password=${{ secrets.MYSQL_PASSWORD }} &
echo "start backend server"
sudo chmod +x /home/ubuntu/deploy/deploy.sh
sudo /home/ubuntu/deploy/deploy.sh

0 comments on commit d6a9005

Please sign in to comment.