包提升

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

包提升的原则是定义多个服务器包仓库,并根据阶段在仓库之间上传和复制包。例如,我们可以有两个不同的服务器包仓库,分别称为“测试”和“发布”。

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 实践。

这些仓库之间会设置一些质量门禁。在我们的例子中,一些包将被放入“测试”仓库,供 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 团队测试并批准这些包后,可以将它们提升到“发布”仓库。基本上,提升是将包的所有构件(artifacts)和元数据从“测试”仓库复制到“发布”仓库。

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

如果我们有一个包列表 pkglist.json,其中包含上述 zlib/1.3.1openssl/3.2.2 包,那么命令会像这样

从 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

将包从“测试”仓库提升到“发布”仓库后,包会像这样

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 扩展仓库也包含一个用于生成发布包(release bundle)的命令(该包可以使用 Artifactory API 进行提升)。