使用 OCI Artifacts 和 ORAS 标准化软件交付
传统软件交付中,容器镜像存储在 OCI Registry(如 Harbor),而 Helm Charts、制品包、配置文件等分散在不同系统。ORAS(OCI Registry As Storage)将 OCI Registry 作为通用的制品存储方案,统一管理所有类型的软件制品。
OCI Artifacts 是 OCI 规范的扩展,允许在 OCI Registry 中存储任意类型的制品,不限于容器镜像。每个制品由一个 Manifest 和若干 Blob(层)组成。
ORAS 是 OCI Artifacts 的 CLI 客户端,提供类似 docker push/pull 的体验来管理非容器制品。
# macOSbrew install oras
# Linuxcurl -LO https://github.com/oras-project/oras/releases/latest/download/oras_linux_amd64.tar.gztar xzf oras_linux_amd64.tar.gz -C /usr/local/bin oras
# 验证oras version# 推送单个文件oras push harbor.example.com/artifacts/my-config:v1 config.yaml
# 推送多个文件oras push harbor.example.com/artifacts/my-chart:v1 \ Chart.yaml values.yaml templates/
# 推送 Helm Chart(OCI 格式)helm package mychart/helm push mychart-0.1.0.tgz oci://harbor.example.com/helm-charts# 拉取到当前目录oras pull harbor.example.com/artifacts/my-config:v1
# 仅下载特定文件oras pull harbor.example.com/artifacts/my-config:v1 --output config.yaml
# 拉取 Helm Charthelm pull oci://harbor.example.com/helm-charts/mychart --version 0.1.0# 查看制品信息oras manifest fetch harbor.example.com/artifacts/my-config:v1
# 查看仓库中的 Tagsoras repo tags harbor.example.com/artifacts/my-config
# 删除 Tagoras manifest delete harbor.example.com/artifacts/my-config:v1实际应用场景
Section titled “实际应用场景”场景 1:Helm Charts 统一管理
Section titled “场景 1:Helm Charts 统一管理”将 Helm Charts 以 OCI 格式推送到 Harbor,与容器镜像共用同一 Registry:
# 登录helm registry login harbor.example.com
# 推送helm push myapp-1.0.0.tgz oci://harbor.example.com/helm-charts
# 在 Argo CD 中引用 OCI Helm Chart# argocd app create myapp --repo harbor.example.com --helm-chart oci://harbor.example.com/helm-charts/myapp场景 2:配置文件版本化管理
Section titled “场景 2:配置文件版本化管理”将环境配置、证书等以 OCI Artifact 形式管理,享受 Registry 的 Tag、签名、不可变性等特性:
# 推送环境配置oras push harbor.example.com/configs/prod:v1.2.3 \ application.yml \ keystore.jks \ truststore.jks
# CI/CD 中拉取oras pull harbor.example.com/configs/prod:v1.2.3 -o /app/config/场景 3:通用制品分发
Section titled “场景 3:通用制品分发”将编译产物(JAR、WAR、二进制)托管到 OCI Registry,简化制品分发链路:
# Maven/Gradle 构建后推送oras push harbor.example.com/artifacts/myapp:build-123 \ target/myapp.jar \ target/dependency/*.jar
# 部署时拉取oras pull harbor.example.com/artifacts/myapp:build-123 -o /opt/app/使用 skopeo 搬运镜像
Section titled “使用 skopeo 搬运镜像”skopeo 是容器镜像搬运工具,可无缝配合 ORAS 使用。
# 从 Docker Hub 搬运到自建 Harborskopeo copy --multi-arch=all \ docker://docker.io/nginx:1.25 \ docker://harbor.example.com/library/nginx:1.25
# OCI 格式的 Helm Chart 也可搬运skopeo copy \ docker://harbor-a.example.com/helm/myapp:v1 \ docker://harbor-b.example.com/helm/myapp:v1# 按 YAML 配置批量同步skopeo sync \ --src yaml --dest docker \ sync-config.yaml \ harbor.example.comsync-config.yaml 示例:
docker.io: images: nginx: [1.25, 1.26] redis: [7.2] tls-verify: truequay.io: images: prometheus/prometheus: [v2.51.0]Harbor 配置
Section titled “Harbor 配置”Harbor 2.x 原生支持 OCI Artifacts:
- 创建项目时选择 “Proxy Cache” 或普通项目。
- 确保项目开启了 OCI 支持(默认开启)。
- Harbor 的 Robot Account 可以像操作镜像一样操作 OCI Artifacts。
在 Harbor 2.8+ 中,Helm Charts 以 OCI 格式存储,旧的 Chartmuseum 方式已被废弃。
CI/CD 集成
Section titled “CI/CD 集成”# GitHub Actions 示例- name: Push config artifact run: | oras push ${{ env.REGISTRY }}/configs/${{ env.ENV }}:${{ github.sha }} \ k8s/deployment.yaml \ k8s/configmap.yaml- OCI Artifacts 不支持
docker pull——必须用oras或helmCLI 操作。 - Harbor 的垃圾回收(GC)同样适用于 OCI Artifacts,删除 Tag 后需等待 GC 周期才能释放存储。
- 大文件(>500MB)推送时注意 Registry 的请求体大小限制——Harbor 默认
client_max_body_size为 0(无限制),但前置 Nginx/Ingress 可能有自己的限制。