软件包晋升

软件包晋升是处理不同技术中软件包质量、成熟度或阶段的推荐 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 “软件包列表”从一个服务器仓库晋升到另一个仓库。

如果我们有一个软件包列表 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

从“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 进行晋升)。