Skip to content

Commit

Permalink
ci: 배포 스크립트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingyum-Kim committed Aug 6, 2023
1 parent f484fe0 commit b7d86e3
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 75 deletions.
23 changes: 7 additions & 16 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
version: 0.0

# Deploy 대상 서버의 운영체제를 표시
os: linux

# 코드 파일 전송과 관련된 설정
files:
# 코드 파일의 소스 경로
- source: /
# 코드 파일의 대상 경로 -> /home/ubuntu/app 디렉토리로 파일을 복사한다.
destination: /home/ubuntu/app
# 대상 경로에 이미 파일이 존재하는 경우, 덮어쓰기를 허용할지 여부
overwrite: yes

# 파일 및 디렉토리 권한에 관련된 설정
permissions:
# 권한을 설정할 대상 경로
- object: /
# 모든 파일 및 디렉토리를 의미
pattern: "**"
# 파일 및 디렉토리의 소유자를 ubuntu로 설정
owner: ubuntu
# 파일 및 디렉토리의 그룹을 ubuntu로 설정
group: ubuntu

# Deploy 전후에 실행할 스크립트 또는 명령에 관련된 설정
hooks:
# 애플리케이션 시작시 실행할 스크립트 또는 명령에 관련된 설정
ApplicationStart:
# 실행할 스크립트 또는 명령의 위치
- location: deploy.sh
# 스크립트 또는 명령 실행의 제한 시간을 설정
- location: scripts/run_new_was.sh
timeout: 180
# CodeDeploy 중 실행되는 스크립트 또는 명령을 실행할 사용자를 지정
runas: ubuntu
- location: scripts/health_check.sh
timeout: 180
runas: ubuntu
- location: scripts/switch.sh
timeout: 180
runas: ubuntu
35 changes: 0 additions & 35 deletions deploy.sh

This file was deleted.

2 changes: 0 additions & 2 deletions docker/.env

This file was deleted.

8 changes: 0 additions & 8 deletions docker/Dockerfile

This file was deleted.

7 changes: 0 additions & 7 deletions docker/docker-compose.blue.yml

This file was deleted.

7 changes: 0 additions & 7 deletions docker/docker-compose.green.yml

This file was deleted.

35 changes: 35 additions & 0 deletions scripts/health_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# health_check.sh

#!/bin/bash

# Crawl current connected port of WAS
CURRENT_PORT=$(cat /home/ubuntu/service_url.inc | grep -Po '[0-9]+' | tail -1)
TARGET_PORT=0

# Toggle port Number
if [ ${CURRENT_PORT} -eq 8081 ]; then
TARGET_PORT=8082
elif [ ${CURRENT_PORT} -eq 8082 ]; then
TARGET_PORT=8081
else
echo "> No WAS is connected to nginx"
exit 1
fi


echo "> Start health check of WAS at 'http://127.0.0.1:${TARGET_PORT}' ..."

for RETRY_COUNT in 1 2 3 4 5 6 7 8 9 10
do
echo "> #${RETRY_COUNT} trying..."
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${TARGET_PORT}/health)

if [ ${RESPONSE_CODE} -eq 200 ]; then
echo "> New WAS successfully running"
exit 0
elif [ ${RETRY_COUNT} -eq 10 ]; then
echo "> Health check failed."
exit 1
fi
sleep 10
done
27 changes: 27 additions & 0 deletions scripts/run_new_was.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# run_new_was.sh

#!/bin/bash

CURRENT_PORT=$(cat /home/ubuntu/service_url.inc | grep -Po '[0-9]+' | tail -1)
TARGET_PORT=0

echo "> Current port of running WAS is ${CURRENT_PORT}."

if [ ${CURRENT_PORT} -eq 8081 ]; then
TARGET_PORT=8082
elif [ ${CURRENT_PORT} -eq 8082 ]; then
TARGET_PORT=8081
else
echo "> No WAS is connected to nginx"
fi

TARGET_PID=$(lsof -Fp -i TCP:${TARGET_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+')

if [ ! -z ${TARGET_PID} ]; then
echo "> Kill WAS running at ${TARGET_PORT}."
sudo kill ${TARGET_PID}
fi

nohup java -jar -Dserver.port=${TARGET_PORT} /home/ubuntu/playground-logging/build/libs/* > /home/ubuntu/nohup.out 2>&1 &
echo "> Now new WAS runs at ${TARGET_PORT}."
exit 0
29 changes: 29 additions & 0 deletions scripts/switch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# switch.sh

#!/bin/bash

# Crawl current connected port of WAS
CURRENT_PORT=$(cat /home/ubuntu/service_url.inc | grep -Po '[0-9]+' | tail -1)
TARGET_PORT=0

echo "> Nginx currently proxies to ${CURRENT_PORT}."

# Toggle port number
if [ ${CURRENT_PORT} -eq 8081 ]; then
TARGET_PORT=8082
elif [ ${CURRENT_PORT} -eq 8082 ]; then
TARGET_PORT=8081
else
echo "> No WAS is connected to nginx"
exit 1
fi

# Change proxying port into target port
echo "set \$service_url http://127.0.0.1:${TARGET_PORT};" | tee /home/ubuntu/service_url.inc

echo "> Now Nginx proxies to ${TARGET_PORT}."

# Reload nginx
sudo service nginx reload

echo "> Nginx reloaded."

0 comments on commit b7d86e3

Please sign in to comment.