采用deepseek的部署脚本
This commit is contained in:
65
.github/workflows/deploy.yml
vendored
65
.github/workflows/deploy.yml
vendored
@@ -1,49 +1,36 @@
|
||||
name: Deploy Django App
|
||||
name: Deploy Django
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main # 触发条件:当代码推送到 main 分支时
|
||||
branches: [ main ] # 触发分支
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest # 使用 GitHub 提供的 Ubuntu 环境
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# 步骤 1:检出代码
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# 步骤 2:设置 Python 环境
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.9' # 指定 Python 版本
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
|
||||
# 步骤 3:安装依赖
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
- name: Run tests
|
||||
run: python manage.py test
|
||||
|
||||
- name: Deploy to Server
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.SERVER_IP }}
|
||||
username: ${{ secrets.SSH_USER }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
script: |
|
||||
cd /var/www/your_project
|
||||
git pull origin main
|
||||
source venv/bin/activate
|
||||
pip install -r requirements.txt
|
||||
|
||||
# 步骤 4:运行测试(可选)
|
||||
- name: Run tests
|
||||
run: |
|
||||
python manage.py test
|
||||
|
||||
# 步骤 5:部署到生产服务器
|
||||
- name: Deploy to production
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.PRODUCTION_HOST }} # 生产服务器 IP 或域名
|
||||
username: ${{ secrets.PRODUCTION_USER }} # SSH 用户名
|
||||
key: ${{ secrets.PRODUCTION_SSH_KEY }} # SSH 私钥
|
||||
script: |
|
||||
cd /opt/myapp # 项目部署目录
|
||||
git pull origin main # 拉取最新代码
|
||||
source /opt/myenv/bin/activate # 激活虚拟环境
|
||||
pip install -r requirements.txt # 安装依赖
|
||||
python manage.py collectstatic --noinput # 收集静态文件
|
||||
python manage.py migrate --noinput # 执行数据库迁移
|
||||
sudo systemctl restart gunicorn # 重启 Gunicorn
|
||||
sudo systemctl restart nginx # 重启 Nginx
|
||||
python manage.py migrate
|
||||
python manage.py collectstatic --noinput
|
||||
sudo systemctl restart gunicorn
|
||||
sudo systemctl reload nginx
|
||||
Reference in New Issue
Block a user