apache/superset-cacheApache Superset Buildx 缓存镜像是专为加速 Apache Superset 镜像构建过程设计的辅助镜像。其核心功能是通过 Docker Buildx 的缓存机制,持久化存储 Superset 构建过程中的依赖项(如 Python 包、前端资源等),避免重复下载和编译,从而显著缩短构建时间。该镜像适用于开发环境、CI/CD 流水线及多团队协作场景,尤其适合需要频繁构建 Superset 镜像的场景。
pip 依赖、Node.js npm 前端依赖及编译产物,避免重复拉取。--cache-from 和 --cache-to 机制无缝对接,无需额外工具链。docker buildx install)。创建缓存目录结构
在项目根目录下创建缓存配置文件(如 cache.Dockerfile),定义缓存路径:
dockerfile# cache.Dockerfile FROM scratch # 定义 Superset 构建依赖的缓存路径 VOLUME ["/root/.cache/pip", "/app/frontend/node_modules", "/app/frontend/.npm"]
构建缓存镜像
使用 Buildx 构建并推送缓存镜像至仓库:
bashdocker buildx build \ -f cache.Dockerfile \ --tag <registry>/superset-build-cache:latest \ --push .
--cache-from:指定缓存源(即已构建的缓存镜像)。--cache-to:指定缓存目标(构建后更新缓存镜像)。在构建 Superset 主镜像时,通过 Buildx 参数关联缓存:
bashdocker buildx build \ -f Dockerfile.superset \ # Superset 官方或自定义 Dockerfile --tag <registry>/superset:latest \ --cache-from=type=registry,ref=<registry>/superset-build-cache:latest \ # 从缓存镜像拉取缓存 --cache-to=type=registry,ref=<registry>/superset-build-cache:latest,mode=max \ # 构建后更新缓存 --push .
| 参数 | 类型 | 描述 | 默认值 |
|---|---|---|---|
CACHE_REGISTRY | 环境变量 | 缓存镜像存储的仓库地址(如 localhost:5000 或 mycompany-registry) | 无(需手动指定) |
CACHE_TAG | 环境变量 | 缓存镜像的标签(用于版本控制,如 v1.4.0) | latest |
PIP_CACHE_PATH | 路径 | Python pip 缓存目录 | /root/.cache/pip |
NPM_CACHE_PATH | 路径 | Node.js npm 缓存目录 | /app/frontend/.npm |
NODE_MODULES_PATH | 路径 | 前端依赖安装目录(编译产物缓存) | /app/frontend/node_modules |
在 GitHub Actions 或 GitLab CI 中集成缓存,示例 workflow 片段:
yaml# .github/workflows/build-superset.yml (GitHub Actions) jobs: build: runs-on: ubuntu-latest steps: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Login to Registry uses: docker/login-action@v2 with: registry: ${{ secrets.REGISTRY_URL }} username: ${{ secrets.REGISTRY_USER }} password: ${{ secrets.REGISTRY_PWD }} - name: Build and push Superset with cache uses: docker/build-push-action@v4 with: context: . file: ./Dockerfile.superset push: true tags: ${{ secrets.REGISTRY_URL }}/superset:${{ github.sha }} cache-from: type=registry,ref=${{ secrets.REGISTRY_URL }}/superset-build-cache:latest cache-to: type=registry,ref=${{ secrets.REGISTRY_URL }}/superset-build-cache:latest,mode=max
在 docker-compose.yml 中配置 Buildx 缓存,加速本地构建:
yaml# docker-compose.yml version: '3.8' services: superset: build: context: . dockerfile: Dockerfile.superset x-bake: # Buildx 扩展配置(需配合 docker compose bake 使用) cache-from: - type=registry,ref=localhost:5000/superset-build-cache:latest cache-to: - type=registry,ref=localhost:5000/superset-build-cache:latest,mode=max image: localhost:5000/superset:dev
使用方式:
bash# 启动并构建(需本地 registry 运行) docker compose up --build
buildx build 中添加 --platform linux/amd64,linux/arm64 参数,并确保缓存镜像支持多平台(可通过 docker buildx imagetools inspect 验证)。docker login 凭证)。docker buildx prune 命令清理本地无效缓存,或在仓库中配置镜像生命周期规则(如自动删除 30 天未使用的缓存镜像)。
manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务