Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ”§ Blue-Green 배포λ₯Ό μœ„ν•œ deploy script μˆ˜μ • #154

Merged
merged 5 commits into from
Aug 24, 2024
Merged
50 changes: 49 additions & 1 deletion .github/workflows/deploy-external-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,52 @@ jobs:
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker system prune -a -f
docker pull pennyway/pennyway-was
docker-compose up -d

# ν˜„μž¬ ν™œμ„± 포트 확인
CURRENT_PORT=$(docker-compose ps | grep "was" | grep -oP "0.0.0.0:\K\d+")

if [ "$CURRENT_PORT" == "8080" ]; then
NEW_PORT="8081"
else
NEW_PORT="8080"
fi

# docker-compose.yml 파일 μ—…λ°μ΄νŠΈ
sed -i "s/WAS_PORT=.*/WAS_PORT=$NEW_PORT/" .env
sed -i "s/WAS_VERSION=.*/WAS_VERSION=${{ steps.get_version.outputs.VERSION }}/" .env

# μƒˆ 버전 배포
docker-compose up -d was

# μƒˆ 버전 ν—¬μŠ€ 체크
for i in {1..30}; do
if curl -s http://localhost:$NEW_PORT/health | grep -q "UP"; then
echo "New version is healthy"

# 이전 버전 μ’…λ£Œ
if [ -n "$CURRENT_PORT" ]; then
docker-compose stop was
docker-compose rm -f was
fi

echo "Deployment successful"
exit 0
fi
sleep 10
done

echo "New version failed health check. Rolling back."
docker-compose stop was
docker-compose rm -f was
sed -i "s/WAS_PORT=.*/WAS_PORT=$CURRENT_PORT/" .env
sed -i "s/WAS_VERSION=.*/$CURRENT_VERSION/" .env
docker-compose up -d was
exit 1

# 8. 배포 κ²°κ³Ό 확인
- name: Check deployment result
if: failure()
run: |
echo "Deployment failed. Please check the logs and take necessary actions."
exit 1

Loading