Files
sb-front/.gitea/workflows/deploy.yaml
T
sb 902b213f60
Deploy / deploy (push) Failing after 15m35s
ci: setup 캐시 제거 — 'Save cache' 후처리 hang 회피
Gitea 캐시 서버 미연결 시 setup-node cache:npm 의 저장 후처리가 수 분 hang →
'job succeeded 인데 계속 실행중 → 타임아웃 가짜 실패' 유발. 캐시 제거로 즉시 종료.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-05 09:55:57 +09:00

67 lines
2.5 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 제거: Gitea 캐시 서버 미연결 시 'Save cache' 후처리가 수 분 hang → '가짜 실패' 유발
- 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 "✅ 배포 완료"