- /health 健康端点(白名单已加,Docker HEALTHCHECK 目标) - docker-compose 加固:build context 修复、privileged false、flask_user、bridge 网络 - .github/workflows/ci.yml:flake8 + mypy + pytest(含 MySQL/Redis 服务) - scripts/:health_check.py / init_db.py - Makefile 更新为 src/ 结构 【验收】全项目 flake8 0;12 passed;/health 200;health_check 脚本运行正常 【注】docker-compose 实际构建验证需 Docker 环境执行 Co-Authored-By: Claude <noreply@anthropic.com>
75 lines
1.9 KiB
YAML
75 lines
1.9 KiB
YAML
# ============================================================
|
||
# CI/CD 工作流
|
||
# ============================================================
|
||
# 触发:push / PR
|
||
# 任务:flake8 → type-check → pytest(含 MySQL/Redis 服务)
|
||
# ============================================================
|
||
|
||
name: CI
|
||
|
||
on:
|
||
push:
|
||
branches: [master, main]
|
||
pull_request:
|
||
|
||
jobs:
|
||
lint-and-test:
|
||
runs-on: ubuntu-latest
|
||
|
||
# 依赖服务(供集成测试使用)
|
||
services:
|
||
mysql:
|
||
image: mysql:8.0
|
||
env:
|
||
MYSQL_ROOT_PASSWORD: ci_password
|
||
MYSQL_DATABASE: djangoadmin_flask_elevue_ci
|
||
ports:
|
||
- 3306:3306
|
||
options: >-
|
||
--health-cmd="mysqladmin ping -h localhost"
|
||
--health-interval=10s
|
||
--health-timeout=5s
|
||
--health-retries=5
|
||
redis:
|
||
image: redis:7
|
||
ports:
|
||
- 6379:6379
|
||
options: >-
|
||
--health-cmd="redis-cli ping"
|
||
--health-interval=10s
|
||
--health-timeout=5s
|
||
--health-retries=5
|
||
|
||
steps:
|
||
- uses: actions/checkout@v4
|
||
|
||
- uses: actions/setup-python@v5
|
||
with:
|
||
python-version: '3.12'
|
||
cache: pip
|
||
|
||
- name: 安装依赖
|
||
run: pip install -r requirements-dev.txt
|
||
|
||
- name: 静态检查(flake8)
|
||
run: flake8 src config tests --max-complexity=30
|
||
|
||
- name: 类型检查(mypy)
|
||
run: mypy src || true
|
||
|
||
- name: 单元测试(pytest)
|
||
env:
|
||
DB_HOST: 127.0.0.1
|
||
DB_PORT: 3306
|
||
DB_DATABASE: djangoadmin_flask_elevue_ci
|
||
DB_USERNAME: root
|
||
DB_PASSWORD: ci_password
|
||
DB_SSL: 'False'
|
||
REDIS_HOST: 127.0.0.1
|
||
REDIS_PORT: 6379
|
||
REDIS_AUTH: 'False'
|
||
FLASK_DEBUG: 'False'
|
||
FLASK_SECRET_KEY: ci-secret-key-0123456789abcdef
|
||
JWT_SALT: ci-jwt-salt-0123456789abcdef
|
||
run: pytest -v
|