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: Build run: | npm ci 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" > ~/.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 "✅ 배포 완료"