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