Files
012-kaopeilian/.drone.yml
111 998211c483 feat: 初始化考培练系统项目
- 从服务器拉取完整代码
- 按框架规范整理项目结构
- 配置 Drone CI 测试环境部署
- 包含后端(FastAPI)、前端(Vue3)、管理端

技术栈: Vue3 + TypeScript + FastAPI + MySQL
2026-01-24 19:33:28 +08:00

143 lines
3.8 KiB
YAML

---
kind: pipeline
type: docker
name: test-deploy
# 仅在 test 分支触发测试环境部署
trigger:
branch:
- test
event:
- push
steps:
# Step 1: 构建后端镜像
- name: build-backend
image: plugins/docker
settings:
registry: registry.cn-shenzhen.aliyuncs.com
repo: registry.cn-shenzhen.aliyuncs.com/ruimeiyun/kaopeilian-backend
username:
from_secret: docker_username
password:
from_secret: docker_password
dockerfile: backend/Dockerfile
context: backend
tags:
- test
- ${DRONE_COMMIT_SHA:0:8}
# Step 2: 构建前端镜像
- name: build-frontend
image: plugins/docker
settings:
registry: registry.cn-shenzhen.aliyuncs.com
repo: registry.cn-shenzhen.aliyuncs.com/ruimeiyun/kaopeilian-frontend
username:
from_secret: docker_username
password:
from_secret: docker_password
dockerfile: frontend/Dockerfile
context: frontend
tags:
- test
- ${DRONE_COMMIT_SHA:0:8}
# Step 3: 部署到测试服务器
- name: deploy-test
image: appleboy/drone-ssh
settings:
host: 47.107.172.23
username: root
password:
from_secret: ssh_password
port: 22
script:
- echo "=== 部署考培练系统测试环境 ==="
- cd /data/kaopeilian-test || mkdir -p /data/kaopeilian-test
- |
cat > docker-compose.yml << 'EOF'
version: '3.8'
services:
backend:
image: registry.cn-shenzhen.aliyuncs.com/ruimeiyun/kaopeilian-backend:test
container_name: kaopeilian-backend-test
restart: always
ports:
- "18000:8000"
environment:
- DATABASE_URL=${DATABASE_URL}
- REDIS_HOST=${REDIS_HOST}
- REDIS_PORT=${REDIS_PORT}
- REDIS_PASSWORD=${REDIS_PASSWORD}
networks:
- kaopeilian-net
frontend:
image: registry.cn-shenzhen.aliyuncs.com/ruimeiyun/kaopeilian-frontend:test
container_name: kaopeilian-frontend-test
restart: always
ports:
- "13001:80"
depends_on:
- backend
networks:
- kaopeilian-net
networks:
kaopeilian-net:
driver: bridge
EOF
- docker-compose pull
- docker-compose up -d
- docker ps | grep kaopeilian
- echo "=== 部署完成 ==="
# Step 4: 通知部署结果
- name: notify
image: plugins/webhook
settings:
urls:
from_secret: webhook_url
content_type: application/json
template: |
{
"msgtype": "text",
"text": {
"content": "🚀 考培练系统测试环境部署完成\n分支: ${DRONE_BRANCH}\n提交: ${DRONE_COMMIT_SHA:0:8}\n作者: ${DRONE_COMMIT_AUTHOR}"
}
}
when:
status:
- success
- failure
---
kind: pipeline
type: docker
name: code-check
# 所有分支推送时进行代码检查
trigger:
event:
- push
- pull_request
steps:
# Python 代码检查
- name: python-lint
image: python:3.9-slim
commands:
- cd backend
- pip install flake8 -q
- flake8 app --count --select=E9,F63,F7,F82 --show-source --statistics || true
- echo "Python lint completed"
# Node.js 代码检查
- name: frontend-lint
image: node:18-alpine
commands:
- cd frontend
- npm install -q 2>/dev/null || true
- npm run lint 2>/dev/null || echo "Frontend lint completed"