Files
vconnect-api/.gitea/workflows/deploy.yml
Kim.KANGHEE c22150f693
Some checks failed
Deploy VConnect API / Test Build (push) Successful in 23s
Deploy VConnect API / Deploy to Server (push) Failing after 8s
Update .gitea/workflows/deploy.yml
2025-12-14 13:24:20 +09:00

90 lines
2.7 KiB
YAML

name: Deploy VConnect API
on:
push:
branches:
- main
workflow_dispatch:
jobs:
test:
name: Test Build
runs-on: ubuntu-latest
container: node:18-bullseye
steps:
- 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"
- name: Install Python
run: |
apt-get update
apt-get install -y python3 python3-pip
- name: Install dependencies
run: |
pip3 install --upgrade pip
if [ -f requirements.txt ]; then
pip3 install -r requirements.txt
fi
- name: Run basic tests
run: |
echo "✅ Basic tests passed"
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"
git fetch --all
git reset --hard origin/main
echo "🐍 Checking Virtual Environment..."
# [중요 수정] venv/bin/activate 파일이 없으면 가상환경을 새로 생성함
if [ ! -f "venv/bin/activate" ]; then
echo "⚠️ venv not found or broken. Creating new virtual environment..."
# Ubuntu 24.04에서는 python3-venv 패키지가 필요할 수 있음 (없으면 에러 날 수 있으니 아래 참고)
python3 -m venv venv
echo "✅ venv created."
fi
echo "🐍 Activate virtualenv"
source venv/bin/activate
echo "🔄 stop service"
sudo systemctl stop vconnect-api
echo "📦 Install dependencies"
pip install -r requirements.txt
echo "🔄 Restart service"
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!"