ci: 운영(prod) 자동배포 워크플로 추가 (main push → api 컨테이너)
CI / build (push) Failing after 16m2s
Deploy (dev) / deploy (push) Failing after 15m47s

dev 와 동일한 jar 방식. 운영 jar 경로는 DEPLOY_JAR_PATH_PROD.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
sb
2026-07-11 17:24:41 +09:00
parent de8b5dac19
commit f6a54d9f33
+62
View File
@@ -0,0 +1,62 @@
name: Deploy (prod)
# main 브랜치 push 시: CI 에서 jar 빌드 → 서버로 scp → 운영(api) 컨테이너 재기동
# dev 와 동일한 jar 방식. 운영 전용 jar 경로(DEPLOY_JAR_PATH_PROD)만 다르다.
#
# 저장소 Settings > Actions > Secrets:
# DEPLOY_HOST / DEPLOY_USER / DEPLOY_SSH_KEY / COMPOSE_FILE / DEPLOY_PORT (dev 와 공용)
# DEPLOY_JAR_PATH_PROD 운영 jar 경로 (compose 볼륨과 일치, 예: /opt/dognation/prod/app.jar)
on:
push:
branches: [main]
workflow_dispatch: {}
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
- name: Build jar (테스트 제외)
run: |
chmod +x ./gradlew
./gradlew --no-daemon clean bootJar
- name: Deploy jar (scp + docker restart)
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
DEPLOY_JAR_PATH: ${{ secrets.DEPLOY_JAR_PATH_PROD }}
COMPOSE_FILE: ${{ secrets.COMPOSE_FILE }}
run: |
set -euo pipefail
PORT="${DEPLOY_PORT:-22}"
if [ -z "${DEPLOY_JAR_PATH:-}" ] || [ -z "${COMPOSE_FILE:-}" ]; then
echo "::error::DEPLOY_JAR_PATH_PROD / COMPOSE_FILE 시크릿이 필요합니다."; exit 1
fi
mkdir -p ~/.ssh && chmod 700 ~/.ssh
printf '%s\n' "$DEPLOY_SSH_KEY" | tr -d '\r' > ~/.ssh/id_deploy
chmod 600 ~/.ssh/id_deploy
ssh-keyscan -p "$PORT" "$DEPLOY_HOST" >> ~/.ssh/known_hosts 2>/dev/null
SSH="ssh -p $PORT -i $HOME/.ssh/id_deploy -o StrictHostKeyChecking=yes"
JAR=$(ls build/libs/*.jar | grep -v -- '-plain.jar' | head -n1)
echo "▶ [PROD] $JAR → $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_JAR_PATH"
$SSH "$DEPLOY_USER@$DEPLOY_HOST" "mkdir -p \"\$(dirname '$DEPLOY_JAR_PATH')\""
scp -P "$PORT" -i "$HOME/.ssh/id_deploy" "$JAR" "$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_JAR_PATH.new"
$SSH "$DEPLOY_USER@$DEPLOY_HOST" "\
mv -f '$DEPLOY_JAR_PATH.new' '$DEPLOY_JAR_PATH'; \
docker compose -f '$COMPOSE_FILE' up -d --force-recreate api; \
docker compose -f '$COMPOSE_FILE' ps api"
echo "✅ 운영(api) 재기동 완료"