ci(spider-base-image): 优化基础镜像构建流程并简化脚本逻辑

- 重命名流水线名称为 spider-base-image
- 合并检查变更和构建步骤为一个步骤
- 精简检测 kami-spider-monorepo 变更的脚本逻辑
- 只需检测关键文件 build-base-image.sh 和 Dockerfile.base
- 在构建前校验文件存在性,缺失则退出
- 登录 Docker 注册表执行构建,完成后登出
- 移除冗余的构建步骤和文件检查
- 明确输出构建成功或跳过构建信息
This commit is contained in:
danial
2025-11-09 15:15:02 +08:00
parent 6f274a3e2e
commit f1b1509089

View File

@@ -1,7 +1,7 @@
---
kind: pipeline
type: ssh
name: spider-base-image-builder
name: spider-base-image
server:
host: 38.38.251.113:34156
@@ -13,98 +13,57 @@ clone:
depth: 50
steps:
- name: check-spider-changes
- name: build-spider-base
commands:
- echo "🔍 Checking for changes in kami-spider-monorepo directory..."
- echo "🔍 Checking changes in kami-spider-monorepo..."
- |
BUILD_REQUIRED=false
SPIDER_DIR="kami-spider-monorepo"
echo "Build event: $DRONE_BUILD_EVENT"
echo "Branch: $DRONE_COMMIT_BRANCH"
# 检查是否有 spider 项目变更
if [ "$DRONE_BUILD_EVENT" = "push" ]; then
if git rev-parse --verify HEAD~1 >/dev/null 2>&1; then
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
echo "Changed files:"
echo "$CHANGED_FILES"
SPIDER_CHANGED=$(echo "$CHANGED_FILES" | grep -E "^${SPIDER_DIR}/" || true)
if [ -n "$SPIDER_CHANGED" ]; then
echo "✅ Changes detected in ${SPIDER_DIR}:"
echo "$SPIDER_CHANGED"
BUILD_REQUIRED=true
CHANGED=$(git diff --name-only HEAD~1 HEAD | grep "^kami-spider-monorepo/" || echo "")
if [ -n "$CHANGED" ]; then
echo "✅ Changes detected:"
echo "$CHANGED"
BUILD=true
else
echo "❌ No changes in ${SPIDER_DIR}"
echo "❌ No changes in kami-spider-monorepo"
BUILD=false
fi
else
echo "First commit detected, building..."
BUILD_REQUIRED=true
echo "First commit, building..."
BUILD=true
fi
else
echo "Non-push event, building..."
BUILD_REQUIRED=true
BUILD=true
fi
echo "$BUILD_REQUIRED" > /tmp/build_status
echo "Build required: $BUILD_REQUIRED"
# 如果有变更则构建
if [ "$BUILD" = "true" ]; then
echo "🏗️ Building base image..."
- name: build-spider-base-image
commands:
- |
if [ -f /tmp/build_status ] && [ "$(cat /tmp/build_status)" = "true" ]; then
echo "🏗️ Building spider base image..."
cd kami-spider-monorepo
if [ -d "kami-spider-monorepo" ]; then
cd kami-spider-monorepo
echo "Changed to: $(pwd)"
ls -la
# 检查文件
if [ -f "build-base-image.sh" ] && [ -f "Dockerfile.base" ]; then
chmod +x build-base-image.sh
# 检查所有必需的构建文件
REQUIRED_FILES=("build-base-image.sh" "Dockerfile.base" "pyproject.toml" "uv.lock")
ALL_FILES_EXIST=true
# 设置环境变量并构建
export DOCKER_REGISTRY="git.oceanpay.cc/danial"
export VERSION="latest"
for file in "${REQUIRED_FILES[@]}"; do
if [ ! -f "$file" ]; then
echo "❌ Required file not found: $file"
ALL_FILES_EXIST=false
fi
done
docker login git.oceanpay.cc -u $DOCKER_LOGIN -p $DOCKER_TOKEN
./build-base-image.sh
docker logout git.oceanpay.cc
if [ "$ALL_FILES_EXIST" = "true" ]; then
echo "✅ All required build files found"
chmod +x build-base-image.sh
# 设置环境变量并构建
export DOCKER_REGISTRY="git.oceanpay.cc/danial"
export VERSION="latest"
docker login git.oceanpay.cc -u $DOCKER_LOGIN -p $DOCKER_TOKEN
./build-base-image.sh
# 验证镜像构建成功
if docker images | grep "kami-spider-base" | grep "latest"; then
echo "✅ Spider base image built successfully"
echo "📊 Image details:"
docker images | grep kami-spider-base
else
echo "❌ Base image build failed - image not found"
exit 1
fi
docker logout git.oceanpay.cc
else
echo "❌ Missing required build files!"
echo "Current directory contents:"
ls -la
exit 1
fi
echo "✅ Base image built successfully"
else
echo "❌ kami-spider-monorepo directory not found!"
echo "❌ Build files not found!"
ls -la
exit 1
fi
else
echo "⏭️ Skipping build - no spider changes"
echo "⏭️ Skipping build"
fi
environment:
DOCKER_LOGIN:
@@ -120,4 +79,4 @@ trigger:
- production
when:
event:
- push
- push