Skip to content

Update deploy-stage.yml #3

Update deploy-stage.yml

Update deploy-stage.yml #3

Workflow file for this run

name: Stage Deployment
on:
push:
branches:
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# Step 1: 检出代码
- name: Checkout code
uses: actions/checkout@v3
# Step 2: 安装 Node.js 和 pnpm 环境
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Install pnpm
run: npm install -g pnpm
# Step 3: 构建前端代码
- name: Build frontend
working-directory: ./osgraph-web
run: |
pnpm install --no-frozen-lockfile
pnpm run build
# Step 4: 安装 sshpass
- name: Install sshpass
run: sudo apt-get update && sudo apt-get install -y sshpass
# Step 5: 上传前端构建产物到服务器
- name: Deploy frontend
env:
DEPLOY_SERVER: ${{ secrets.DEPLOY_SERVER }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PASSWORD: ${{ secrets.DEPLOY_PASSWORD }}
DEPLOY_PATH_FRONTEND: ${{ secrets.DEPLOY_PATH_FRONTEND }}
run: |
timeout 300 sshpass -p "$DEPLOY_PASSWORD" scp -o StrictHostKeyChecking=no -r ./osgraph-web/dist/* $DEPLOY_USER@$DEPLOY_SERVER:$DEPLOY_PATH_FRONTEND
# Step 6: 更新后端代码并重启服务
- name: Deploy backend
env:
DEPLOY_SERVER: ${{ secrets.DEPLOY_SERVER }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PASSWORD: ${{ secrets.DEPLOY_PASSWORD }}
DEPLOY_PATH_BACKEND: ${{ secrets.DEPLOY_PATH_BACKEND }}
run: |
timeout 300 sshpass -p "$DEPLOY_PASSWORD" scp -o StrictHostKeyChecking=no -r ./osgraph-service/* $DEPLOY_USER@$DEPLOY_SERVER:$DEPLOY_PATH_BACKEND
sshpass -p "$DEPLOY_PASSWORD" ssh -o StrictHostKeyChecking=no $DEPLOY_USER@$DEPLOY_SERVER << EOF
set -e
source ~/.bashrc
source /root/osgraph/myenv/bin/activate
cd $DEPLOY_PATH_BACKEND
if [ -f ./poetry.lock ]; then
rm ./poetry.lock
fi
poetry install --no-dev --only main
lsof -ti:8000 | xargs kill -9 || true
nohup poetry run gunicorn -w 4 -b 0.0.0.0:8000 server:app > gunicorn.log 2>&1 &
EOF