97 lines
3.1 KiB
YAML
97 lines
3.1 KiB
YAML
name: Deploy VConnect API
|
||
|
||
on:
|
||
push:
|
||
branches:
|
||
- main
|
||
workflow_dispatch:
|
||
|
||
jobs:
|
||
test:
|
||
name: Test Build
|
||
runs-on: ubuntu-latest
|
||
# Node 포함 컨테이너 (act_runner + Gitea Actions 환경 호환용)
|
||
container: node:18-bullseye
|
||
steps:
|
||
# 1️⃣ 내부 네트워크로 직접 Clone
|
||
- name: Checkout repository (internal)
|
||
run: |
|
||
echo "📥 Internal git clone start"
|
||
git clone --depth 1 https://gitea.mouse84.com/Kim.KANGHEE/vconnect-api.git .
|
||
echo "📥 Clone done"
|
||
|
||
# 2️⃣ Python 설치
|
||
- name: Install Python
|
||
run: |
|
||
apt-get update
|
||
apt-get install -y python3 python3-pip
|
||
python3 --version
|
||
pip3 --version
|
||
|
||
# 3️⃣ 의존성 설치 및 테스트 준비
|
||
- name: Install dependencies
|
||
run: |
|
||
pip3 install --upgrade pip
|
||
if [ -f requirements.txt ]; then
|
||
pip3 install -r requirements.txt
|
||
fi
|
||
|
||
# 4️⃣ 기본 테스트
|
||
- name: Run basic tests
|
||
run: |
|
||
echo "✅ Code checkout success"
|
||
echo "✅ Python ready"
|
||
echo "✅ Dependencies installed"
|
||
# 추후 pytest 등으로 실제 테스트 명령어를 여기에 추가
|
||
|
||
deploy:
|
||
name: Deploy to Server
|
||
runs-on: ubuntu-latest
|
||
needs: test
|
||
if: github.ref == 'refs/heads/main'
|
||
steps:
|
||
- name: Deploy via SSH
|
||
run: |
|
||
set -e
|
||
echo "🔐 SSH key setup"
|
||
mkdir -p ~/.ssh
|
||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||
chmod 600 ~/.ssh/id_rsa
|
||
# 호스트 키 스캔 (접속 확인 질문 방지)
|
||
ssh-keyscan -H 192.168.0.97 >> ~/.ssh/known_hosts
|
||
|
||
echo "🚀 Deploy start"
|
||
ssh kdesk84@192.168.0.97 << 'EOF'
|
||
set -e
|
||
echo "📂 Move to project directory"
|
||
cd /data/vconnect-api
|
||
|
||
echo "🔄 Git Force Sync (Fetch & Reset)"
|
||
# [핵심] 기존 로컬 변경 사항(충돌)을 무시하고 리포지토리 상태로 강제 동기화
|
||
# 단, .gitignore에 등록된 파일(DB, venv 등)은 삭제되지 않고 안전하게 유지됨
|
||
git fetch --all
|
||
git reset --hard origin/main
|
||
|
||
echo "🐍 Activate virtualenv"
|
||
# 가상환경 폴더가 없으면 생성 (안전장치)
|
||
if [ ! -d "venv" ]; then
|
||
echo "venv not found, creating..."
|
||
python3 -m venv venv
|
||
fi
|
||
source venv/bin/activate
|
||
|
||
echo "📦 Install dependencies"
|
||
pip install -r requirements.txt
|
||
|
||
echo "🔄 Restart service"
|
||
# sudo 비밀번호 없이 실행 가능하도록 visudo 설정이 되어 있어야 함
|
||
sudo systemctl restart vconnect-api
|
||
|
||
echo "📋 Service status"
|
||
sudo systemctl status vconnect-api --no-pager -l
|
||
|
||
echo "✅ Deploy finished"
|
||
EOF
|
||
|
||
- name: Deployment Complete
|
||
run: echo "🎉 VConnect API deployment completed!" |