Skip to content

Commit

Permalink
add: added deploy script for prod
Browse files Browse the repository at this point in the history
  • Loading branch information
thguss committed Dec 4, 2024
1 parent d05f2e4 commit 057ed68
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
cd ~
# deploy.sh 파일 다운로드
wget https://raw.githubusercontent.com/Team-Smeme/Smeme-server-renewal/main/script/deploy.sh -O deploy.sh
wget https://raw.githubusercontent.com/Team-Smeme/Smeme-server-renewal/main/script/prod/deploy.sh -O deploy.sh
chmod +x deploy.sh
# 기존 .env 파일 삭제 및 새로 생성
Expand Down
64 changes: 64 additions & 0 deletions script/prod/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash
source .env

REGISTRY_URL=${REGISTRY_URL}
IMAGE_NAME=${IMAGE_NAME}
SECRET_MANAGER_TOKEN=${SECRET_MANAGER_TOKEN}
SECRET_MANAGER_WORKSPACE_ID=${SECRET_MANAGER_WORKSPACE_ID}
TAG="latest"
CONTAINER_NAME="smeem"
HEALTH_CHECK_URI="/actuator/health"

echo "> Stop old version"
if [ "$(sudo docker ps -a -q -f name=${CONTAINER_NAME})" ]; then
docker stop ${CONTAINER_NAME}
docker rm ${CONTAINER_NAME}
fi

echo "----------------------------------------------------------------------"

# 도커 이미지 풀 받기
echo "> Pull Docker Image"
sudo docker pull "${REGISTRY_URL}"/"${IMAGE_NAME}":"${TAG}"

# 서버 실행
echo "> Run Docker"

docker run -d --name ${CONTAINER_NAME} -p 80:8080 \
-e SECRET_MANAGER_TOKEN="${SECRET_MANAGER_TOKEN}" \
-e SECRET_MANAGER_WORKSPACE_ID="${SECRET_MANAGER_WORKSPACE_ID}" \
"${REGISTRY_URL}"/"${IMAGE_NAME}":${TAG}

echo "----------------------------------------------------------------------"

# green_port 서버 실행 확인
sleep 15

for retry_count in {1..15}
do
echo "> Health check"

response=$(curl -s http://localhost${HEALTH_CHECK_URI})
# shellcheck disable=SC2126
up_count=$(echo "${response}" | grep 'UP' | wc -l)

if [ "${up_count}" -ge 1 ]
then
echo "> SUCCESS"
break
else
echo "> Not run yet"
echo "> Response: ${response}"
fi

if [ "${retry_count}" -eq 15 ]
then
echo "> Failed to running server"
docker rm -f ${CONTAINER_NAME}
exit 1
fi

sleep 2
done

echo "----------------------------------------------------------------------"

0 comments on commit 057ed68

Please sign in to comment.