包升级

包升级是推荐的 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 进行升级)。