Skip to content

Production Deployment #1

Production Deployment

Production Deployment #1

Workflow file for this run

name: Production Deployment
on:
workflow_dispatch:
jobs:
build-and-deploy-tag:
runs-on: ubuntu-latest
steps:
# 检出代码
- name: Checkout code
uses: actions/checkout@v3
# 安装 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
# 构建前端代码
- name: Build frontend
working-directory: ./osgraph-web
run: |
pnpm install --no-frozen-lockfile
pnpm run build
# 配置 SSH 密钥
- name: Configure SSH
uses: webfactory/ssh-agent@v0.5.3
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
# 上传前端构建产物到服务B
- name: Deploy frontend to Service B
env:
DEPLOY_SERVER: ${{ secrets.DEPLOY_SERVER_MASTER }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PATH_FRONTEND: ${{ secrets.DEPLOY_PATH_FRONTEND }}
run: |
timeout 300 scp -o StrictHostKeyChecking=no -r ./osgraph-web/dist/* $DEPLOY_USER@$DEPLOY_SERVER:$DEPLOY_PATH_FRONTEND
# 更新后端代码并重启服务B
- name: Deploy backend to Service B
env:
DEPLOY_SERVER: ${{ secrets.DEPLOY_SERVER_MASTER}}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PATH_BACKEND: ${{ secrets.DEPLOY_PATH_BACKEND }}
run: |
timeout 300 scp -o StrictHostKeyChecking=no -r ./osgraph-service/* $DEPLOY_USER@$DEPLOY_SERVER:$DEPLOY_PATH_BACKEND
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
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