ci: speed up Docker build checks (#1820)

* ci: speed up docker build checks

* test: align Dockerfile cache assertion
This commit is contained in:
zhulinsen
2026-06-27 22:35:44 +08:00
committed by GitHub
parent ef9371003c
commit d0ab0663b8
4 changed files with 49 additions and 14 deletions

View File

@@ -3,11 +3,19 @@ __pycache__/
*.py[cod]
*$py.class
*.so
.pytest_cache/
.mypy_cache/
.ruff_cache/
.coverage
htmlcov/
# 忽略虚拟环境
venv/
.venv/
env/
.env
.env.*
!.env.example
.env.local
# 忽略 IDE
@@ -16,15 +24,30 @@ env/
*.swp
*.swo
# 忽略数据文件(可选,如果想持久化就注释掉)
# data/
# logs/
# reports/
# 忽略本地仓库、CI 元数据和运行产物
.git/
.github/
.claude/reviews/
data/
logs/
reports/
*.log
# 忽略测试文件
# 忽略测试和文档
tests/
test_*.py
*_test.py
# 忽略文档
docs/
*.md
!README.md
# 忽略不参与 Docker 镜像构建的前端/桌面端产物
apps/dsa-desktop/
node_modules/
dist/
build/
coverage/
apps/dsa-web/node_modules/
apps/dsa-web/dist/
apps/dsa-web/build/
apps/dsa-web/coverage/

View File

@@ -79,14 +79,23 @@ jobs:
docker-build:
name: docker-build
runs-on: ubuntu-latest
needs: [backend-gate]
needs: [ai-governance]
steps:
- name: 📥 Checkout
uses: actions/checkout@v5
- name: 🛠️ Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 🐳 Build image
run: |
docker build -t stock-analysis:test -f docker/Dockerfile .
docker run --rm stock-analysis:test python -c "print('✅ Docker OK')"
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile
tags: stock-analysis:test
load: true
cache-from: type=gha,scope=stock-analysis-ci-docker
cache-to: type=gha,mode=max,scope=stock-analysis-ci-docker,ignore-error=true
- name: 🐳 Docker smoke
run: docker run --rm stock-analysis:test python -c "print('✅ Docker OK')"
- name: 🔍 Docker smoke imports
run: |
docker run --rm stock-analysis:test python -c "

View File

@@ -1,3 +1,5 @@
# syntax=docker/dockerfile:1.7
# ===================================
# A股自选股智能分析系统 - Docker 镜像
# ===================================
@@ -8,7 +10,7 @@ FROM node:20-slim AS web-builder
WORKDIR /app/apps/dsa-web
COPY apps/dsa-web/package.json apps/dsa-web/package-lock.json ./
RUN npm ci
RUN --mount=type=cache,target=/root/.npm npm ci
COPY apps/dsa-web/ ./
RUN npm run build
@@ -44,7 +46,7 @@ RUN groupadd -g 1000 dsa && \
COPY requirements.txt .
# 安装 Python 依赖
RUN pip install --no-cache-dir -r requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
# 复制应用代码
COPY *.py ./

View File

@@ -30,7 +30,8 @@ def test_dockerfile_bundles_default_alphasift_adapter() -> None:
assert "git \\" in dockerfile
assert "git+https://github.com/ZhuLinsen/alphasift.git@377049857cc04175dc3cca62121ee41adec6cdb8#egg=alphasift" in requirements
assert "pip install --no-cache-dir -r requirements.txt" in dockerfile
assert "pip install -r requirements.txt" in dockerfile
assert "--mount=type=cache,target=/root/.cache/pip" in dockerfile
assert "import alphasift.dsa_adapter" in dockerfile