Files
xiaoxia-saas/scripts/ci/rebuild-api-base-image.sh
T
xiaoxia 7c0b9b3aaf
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 40s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Failing after 47s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m40s
AI Code Review / AI Code Review (pull_request) Successful in 1m59s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m0s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 3m30s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m31s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 3m36s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 7m32s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 10m46s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 5m22s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 12m53s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Failing after 46s
perf: 删除 psycopg2-binary 依赖 + 预构建 API 基础镜像
子任务 2.1 - 删除重复 PostgreSQL 驱动:
- health.py: psycopg2 → psycopg (psycopg3 迁移,3处修改)
- requirements-base.txt: 删除 psycopg2-binary==2.9.9
- 项目已全面使用 psycopg3,仅 health.py 遗留 psycopg2

子任务 2.2 - 预构建 API 基础镜像:
- 新增 infra/docker/api-base.Dockerfile (系统依赖+Python依赖预装)
- 简化 infra/docker/api.Dockerfile (从基础镜像开始,仅叠加业务代码)
- 新增 .gitea/workflows/api-base-image.yml (自动构建基础镜像)
- 新增 scripts/ci/rebuild-api-base-image.sh (手动重建脚本)

预期效果:
- API Image 构建时间从 15-20 分钟降至 3-5 分钟
- 消除 psycopg2 和 psycopg3 重复安装(减少包体积)
2026-08-18 14:50:35 +08:00

41 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# ============================================================
# 重建 API 基础镜像脚本
# 用途:当 requirements-base.txt 或 requirements.txt 变更时手动触发
# 前提:需要在已登录 ACR 的构建服务器上执行
# ============================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
REGISTRY="xiaoxia-registry.cn-hangzhou.cr.aliyuncs.com/xiaoxiakeji"
IMAGE_NAME="saas-api-base"
TAG="latest"
FULL_TAG="${REGISTRY}/${IMAGE_NAME}:${TAG}"
echo "========================================="
echo "🔨 Rebuilding API base image"
echo " Registry: ${REGISTRY}"
echo " Image: ${FULL_TAG}"
echo " Context: ${REPO_ROOT}"
echo "========================================="
cd "$REPO_ROOT"
# 构建并推送
docker buildx build \
--platform linux/amd64 \
--tag "${FULL_TAG}" \
--push \
-f infra/docker/api-base.Dockerfile \
.
echo ""
echo "✅ API base image pushed: ${FULL_TAG}"
# 显示镜像大小
docker pull "${FULL_TAG}" > /dev/null 2>&1
docker images "${FULL_TAG}" --format "table {{.Repository}}:{{.Tag}}\t{{.Size}}"