Skip to content

Commit

Permalink
Merge pull request #352 from Team-Smeme/develop
Browse files Browse the repository at this point in the history
deploy for production
  • Loading branch information
thguss authored Dec 4, 2024
2 parents 5754c9d + 057ed68 commit 23d1b54
Show file tree
Hide file tree
Showing 3 changed files with 66 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 "----------------------------------------------------------------------"
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public Diary toDomain(Member member) {

public Diary toDomain(Diary originDiary) {
return Diary.builder()
.id(originDiary.getId())
.content(content)
.targetLang(originDiary.getTargetLang())
.topicId(topicId)
Expand Down

0 comments on commit 23d1b54

Please sign in to comment.