b748f7d48d
CI / build (push) Failing after 15m25s
- deploy.yaml 은 CI와 별개로 push:[main]에 트리거되며 테스트를 건너뛰고 있었음 (백엔드 bootJar -x test, 프론트 테스트 스텝 없음) → 게이트 무력 - 배포 잡 안에서 테스트를 먼저 실행하도록 변경(Gitea는 워크플로 간 needs 불안정) · 백엔드: clean bootJar -x test → clean build (test 포함) · 프론트: Install → Test(npm test) → Build 순으로 분리 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
69 lines
2.9 KiB
YAML
69 lines
2.9 KiB
YAML
name: Deploy
|
|
|
|
# main 푸시 시 자동 배포: jar 빌드 → 서버로 scp → systemd 재시작
|
|
#
|
|
# 저장소 Settings > Actions > Secrets 에 등록:
|
|
# DEPLOY_HOST 배포 서버 호스트/IP
|
|
# DEPLOY_USER SSH 계정 (systemctl 무비밀번호 sudo 필요 — deploy/README.md 참고)
|
|
# DEPLOY_SSH_KEY SSH 개인키 (PEM 전체)
|
|
# DEPLOY_PATH jar 배치 디렉터리 (예: /opt/sb-backend)
|
|
# DEPLOY_PORT SSH 포트 (선택, 기본 22)
|
|
# SERVICE_NAME systemd 유닛명 (선택, 기본 sb-backend)
|
|
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'
|
|
cache: gradle
|
|
|
|
# clean build 는 test 를 포함 — 테스트 실패 시 jar 가 생성되지 않아 배포 중단(게이트)
|
|
- name: Build jar (테스트 포함)
|
|
run: |
|
|
chmod +x ./gradlew
|
|
./gradlew --no-daemon clean build
|
|
|
|
- name: Deploy (SSH + systemd)
|
|
env:
|
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
|
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
|
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
|
|
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
|
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
|
|
SERVICE_NAME: ${{ secrets.SERVICE_NAME }}
|
|
run: |
|
|
set -euo pipefail
|
|
PORT="${DEPLOY_PORT:-22}"
|
|
SERVICE="${SERVICE_NAME:-sb-backend}"
|
|
DEST="${DEPLOY_PATH:-}"
|
|
if [ -z "$DEST" ] || [ "$DEST" = "/" ]; then
|
|
echo "::error::DEPLOY_PATH 시크릿이 비어 있거나 잘못되었습니다."; 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 "Deploy $JAR -> $DEPLOY_USER@$DEPLOY_HOST:$DEST/app.jar"
|
|
|
|
$SSH "$DEPLOY_USER@$DEPLOY_HOST" "mkdir -p '$DEST'"
|
|
scp -P "$PORT" -i "$HOME/.ssh/id_deploy" "$JAR" "$DEPLOY_USER@$DEPLOY_HOST:$DEST/app.jar"
|
|
$SSH "$DEPLOY_USER@$DEPLOY_HOST" "sudo systemctl restart '$SERVICE'"
|
|
# 기동 대기: 최대 ~40초 폴링, 안 뜨면 상태 덤프 후 실패
|
|
$SSH "$DEPLOY_USER@$DEPLOY_HOST" "for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do systemctl is-active --quiet '$SERVICE' && echo 'service active' && exit 0; sleep 2; done; echo '서비스가 active 상태가 아닙니다:'; systemctl --no-pager -l status '$SERVICE' | tail -30; exit 1"
|
|
echo "✅ 배포 완료"
|