- deploy.yaml: dist 빌드 → SSH(tar)로 웹 루트 교체 → nginx reload - deploy/nginx-sb-front.conf: SPA 폴백 + /api 프록시 샘플 - deploy/README.md: 시크릿·서버 준비 안내 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
name: Deploy (manual)
|
||||
name: Deploy
|
||||
|
||||
# 배포 대상이 정해지면 아래 단계의 주석을 풀고 시크릿을 등록하세요.
|
||||
# 저장소 Settings > Actions > Secrets 에 등록 필요:
|
||||
# DEPLOY_HOST, DEPLOY_USER, DEPLOY_SSH_KEY, DEPLOY_PATH
|
||||
# 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: {}
|
||||
# push:
|
||||
# tags: ['v*']
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
@@ -26,17 +31,31 @@ jobs:
|
||||
npm ci
|
||||
npm run build
|
||||
|
||||
# ===== 배포 예시 (택1) — 사용 시 주석 해제 =====
|
||||
# 1) 정적 파일을 원격 서버로 rsync (Nginx 등 정적 호스팅)
|
||||
# - name: Deploy via SSH/rsync
|
||||
# uses: appleboy/scp-action@v0.1.7
|
||||
# with:
|
||||
# host: ${{ secrets.DEPLOY_HOST }}
|
||||
# username: ${{ secrets.DEPLOY_USER }}
|
||||
# key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
# source: "dist/*"
|
||||
# target: ${{ secrets.DEPLOY_PATH }}
|
||||
# strip_components: 1
|
||||
- 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
|
||||
|
||||
- name: Notice
|
||||
run: echo "dist 빌드 완료. 배포 대상 지정 후 위 단계를 활성화하세요."
|
||||
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 "✅ 배포 완료"
|
||||
|
||||
Reference in New Issue
Block a user