Files
docker-registry/kami-spider-monorepo/Makefile
danial 716a72b8ab feat(ci): 添加 Spider Base 镜像构建和部署流水线
- 新增 .drone.yml 配置,实现基于 SSH 的自动构建和推送 Spider Base 镜像
- 检测 kami-spider-monorepo 目录代码变动,变动时触发基础镜像构建
- 基础镜像包含系统依赖、Python 环境、Playwright 及所有项目依赖
- 优化 Dockerfile,将应用镜像基于该预构建基础镜像构建,显著提升构建速度
- 新增 Makefile,标准化基础镜像和应用镜像的构建、测试、推送及清理流程
- 增加详细的 README,指导开发者快速上手构建和使用基础镜像
- 添加构建脚本 build-base-image.sh,实现基础镜像的统一构建及推送
- 引入生产环境入口脚本 docker-entrypoint.sh,优化启动流程和信号处理
- 统一依赖管理(pyproject.toml、uv.lock),确保基础镜像依赖完整一致
- 设定健康检查,提升容器运行稳定性和可监控性
2025-11-09 15:08:38 +08:00

102 lines
3.7 KiB
Makefile
Executable File

# Makefile for kami-spider Docker image management
.PHONY: help build-base build clean test push-base push-app
# Default variables
VERSION ?= latest
REGISTRY ?= localhost:5000
USE_PROXY ?= 0
help: ## Show this help message
@echo "Available commands:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
build-base: ## Build base image with all dependencies
@echo "🏗️ Building base image..."
./build-base-image.sh
build-base-with-proxy: ## Build base image using proxy
@echo "🏗️ Building base image with proxy..."
USE_PROXY=1 ./build-base-image.sh
build: ## Build application image using pre-built base image
@echo "🚀 Building application image..."
docker build \
-t kami-spider:$(VERSION) \
--build-arg DOCKER_REGISTRY=$(REGISTRY) \
--build-arg USE_PROXY=$(USE_PROXY) \
.
build-all: build-base build ## Build everything (base image + application)
clean: ## Clean up Docker images
@echo "🧹 Cleaning up Docker images..."
docker rmi kami-spider-base:latest 2>/dev/null || true
docker rmi kami-spider-base:$(VERSION) 2>/dev/null || true
docker rmi kami-spider:$(VERSION) 2>/dev/null || true
docker image prune -f
test-base: ## Test base image
@echo "🧪 Testing base image..."
docker run --rm kami-spider-base:latest python --version
docker run --rm kami-spider-base:latest python -c "import fastapi; print('✅ FastAPI available')"
docker run --rm kami-spider-base:latest python -c "import playwright; print('✅ Playwright available')"
test: ## Test application image
@echo "🧪 Testing application image..."
docker run --rm -p 8001:8000 -d --name test-app kami-spider:$(VERSION)
sleep 5
curl -f http://localhost:8001/health || (echo "❌ Health check failed" && docker stop test-app && exit 1)
docker stop test-app
@echo "✅ Application test passed"
test-all: test-base test ## Run all tests
push-base: ## Push base image to registry
@echo "📤 Pushing base image to registry..."
docker tag kami-spider-base:latest $(REGISTRY)/kami-spider-base:$(VERSION)
docker push $(REGISTRY)/kami-spider-base:$(VERSION)
@echo "✅ Base image pushed successfully"
push-app: ## Push application image to registry
@echo "📤 Pushing application image to registry..."
docker tag kami-spider:$(VERSION) $(REGISTRY)/kami-spider:$(VERSION)
docker push $(REGISTRY)/kami-spider:$(VERSION)
@echo "✅ Application image pushed successfully"
push-all: push-base push-app ## Push all images to registry
dev: ## Build image for development
@echo "🔧 Building development image..."
make build
@echo "🔧 Development image built: kami-spider:$(VERSION)"
prod: VERSION=$(shell date +%Y%m%d-%H%M%S)
prod: ## Build production image with timestamp
@echo "🏭 Building production image..."
make build
@echo "🏭 Production image built: kami-spider:$(VERSION)"
# Quick start commands
quick-start: ## Quick start for local development
@echo "🚀 Quick starting kami-spider..."
make build
docker run -d --name kami-spider -p 8000:8000 kami-spider:latest
@echo "✅ Application started on http://localhost:8000"
stop: ## Stop and remove running container
docker stop kami-spider 2>/dev/null || true
docker rm kami-spider 2>/dev/null || true
@echo "🛑 Application stopped"
logs: ## Show application logs
docker logs -f kami-spider 2>/dev/null || echo "❌ No running container found"
# Performance comparison
compare-builds: ## Compare build times between original and optimized
@echo "⏱️ Comparing build times..."
@echo "Building original Dockerfile..."
time make build-original
@echo "Building optimized Dockerfile..."
time make build-optimized
@echo "✅ Build comparison completed"