Files
sb-backend/.gitea/workflows/deploy.yaml
T
ByungCheol cf6d0710f6
CI / build (push) Has been cancelled
fix(ci): SSH 개인키 파일에서 CR 제거 (Windows CRLF 시크릿 대응)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-31 17:40:08 +09:00

66 lines
2.4 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
- name: Build jar (skip tests)
run: |
chmod +x ./gradlew
./gradlew --no-daemon clean bootJar -x test
- 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' && sleep 3 && sudo systemctl is-active '$SERVICE'"
echo "✅ 배포 완료"