包晋级

包晋级是推荐的 DevOps 实践,用于处理不同技术中包的质量、成熟度或阶段,当然也适用于 Conan 包。

包晋级的原则是定义多个服务器包仓库,并根据阶段在这些仓库之间上传和复制包。例如,我们可以有两个不同的服务器包仓库,分别称为“testing”和“release”

digraph repositories { node [fillcolor="lightblue", style=filled, shape=box] rankdir="LR"; subgraph cluster_0 { style=filled; color=lightgrey; rankdir="LR"; label = "Packages server"; "testing\n repository" -> "release\n repository" [ label="promotion" ]; } }

注意

最佳实践

  • 强烈不建议使用不同的 user/channel 来表示成熟度。这种做法在多仓库可能性出现之前的早期 Conan 1 时代曾被描述过,但现在不应再使用。

  • 包在整个流水线和阶段中应完全不可变,包不能重命名或更改其 user/channel,并且从源代码重新构建以获得新的 user/channel 也是强烈不建议的 DevOps 实践。

在这些仓库之间会设置一些质量门禁。在我们的例子中,一些包将放入“testing”仓库供 QA 团队测试,例如 zlib/1.3.1openssl/3.2.2

digraph repositories { node [fillcolor="lightskyblue", style=filled, shape=box] rankdir="LR"; subgraph cluster_0 { label="Packages server"; style=filled; color=lightgrey; subgraph cluster_1 { label = "testing\n repository" shape = "box"; style=filled; color=lightblue; "zlib/1.3.1"; "openssl/3.2.2"; } subgraph cluster_2 { label = "release\n repository" shape = "box"; style=filled; color=lightblue; "release" [style=invis]; } { edge[style=invis]; "zlib/1.3.1" -> "release" ; rankdir="BT"; } } }

当 QA 团队测试并批准这些包后,它们可以被晋级到“release”仓库。本质上,晋级是将包(包括所有工件和元数据)从“testing”仓库复制到“release”仓库。

有多种方法可以实现和执行包晋级。Artifactory 提供了一些 API,可用于移动单个文件或文件夹。 Conan 扩展仓库 包含了 conan art:promote 命令,该命令可用于将 Conan“包列表”从一个服务器仓库晋级到另一个仓库。

如果我们有一个包含上述 zlib/1.3.1openssl/3.2.2 包的包列表 pkglist.json,那么命令将如下所示:

从 testing 晋级到 release
$ conan art:promote pkglist.json --from=testing --to=release --url=https://<url>/artifactory --user=<user> --password=<password>

请注意,conan art:promote 命令不适用于 ArtifactoryCE,需要 Artifactory 的 Pro 版本。在这些情况下,晋级功能可以通过简单的下载+上传流程实现。

从 testing 晋级到 release
# Promotion using Conan download/upload commands
# (slow, can be improved with art:promote custom command)
$ conan download --list=promote.json -r=testing --format=json > downloaded.json
$ conan upload --list=downloaded.json -r=release -c

将包从“testing”仓库晋级到“release”仓库后,包将如下所示:

digraph repositories { node [fillcolor="lightskyblue", style=filled, shape=box] rankdir="LR"; subgraph cluster_0 { label="Packages server"; style=filled; color=lightgrey; subgraph cluster_1 { label = "testing\n repository" shape = "box"; style=filled; color=lightblue; "zlib/1.3.1"; "openssl/3.2.2"; } subgraph cluster_2 { label = "release\n repository" shape = "box"; style=filled; color=lightblue; "zlibpromoted" [label="zlib/1.3.1"]; "opensslpromoted" [label="openssl/3.2.2"]; } { "zlib/1.3.1" -> "zlibpromoted"; "openssl/3.2.2" -> "opensslpromoted" [label="Promotion"]; } } }

注意

最佳实践

  • 在现代包服务器(例如 Artifactory)中,包工件是去重的,这意味着当它们被复制到不同位置(包括不同仓库)时,不会占用额外的存储空间。去重是基于校验和的,因此系统也很智能,可以避免重复上传现有工件。这对于“晋级”机制非常重要:该机制只复制一些元数据,因此它可以非常快速且节省存储空间。流水线可以根据需要定义任意数量的仓库和晋级,而无需担心存储成本。

  • 晋级也可以在 JFrog 平台中使用 Release Bundles 完成。 Conan 扩展仓库 也包含一个用于生成发布包(可以通过 Artifactory API 晋级)的命令。