Files
sb-front/.gitea/workflows/deploy.yaml
T
ByungCheol 43e2de6c3c
CI / build (push) Failing after 11m1s
ci: 배포 워크플로에 테스트 게이트 추가 — 실패 시 배포 중단
- 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>
2026-06-06 14:27:37 +09:00

67 lines
2.4 KiB
YAML

name: Deploy
# main 푸시 시 자동 배포: dist 빌드 → 서버 Nginx 루트로 업로드 → nginx reload
#
# 저장소 Settings > Actions > Secrets 에 등록:
# DEPLOY_HOST 배포 서버 호스트/IP
# DEPLOY_USER SSH 계정 (nginx reload 무비밀번호 sudo 필요 — deploy/README.md 참고)
# DEPLOY_SSH_KEY SSH 개인키 (PEM 전체)
# DEPLOY_PATH Nginx 웹 루트 (예: /var/www/sb-front)
# DEPLOY_PORT SSH 포트 (선택, 기본 22)
on:
push:
branches: [main]
workflow_dispatch: {}
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: Install
run: npm ci
# 테스트 게이트 — 실패 시 이후 빌드/배포 스텝이 실행되지 않음
- name: Test
run: npm test
- name: Build
run: npm run build
- name: Deploy to Nginx (SSH)
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 }}
run: |
set -euo pipefail
PORT="${DEPLOY_PORT:-22}"
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"
echo "Deploy dist/ -> $DEPLOY_USER@$DEPLOY_HOST:$DEST"
$SSH "$DEPLOY_USER@$DEPLOY_HOST" "mkdir -p '$DEST'"
# 기존 파일 정리 후 새 빌드 업로드 (tar 파이프 — 추가 의존성 없음)
tar -czf - -C dist . | $SSH "$DEPLOY_USER@$DEPLOY_HOST" "find '$DEST' -mindepth 1 -delete && tar -xzf - -C '$DEST'"
# Nginx 설정 검증 후 reload (실패해도 배포 자체는 유지)
$SSH "$DEPLOY_USER@$DEPLOY_HOST" "sudo nginx -t && sudo nginx -s reload" || echo "nginx reload 생략됨"
echo "✅ 배포 완료"