软件包促销

软件包促销是推荐的 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 扩展仓库 还包含一个用于生成 Release Bundle 的命令(可以使用 Artifactory API 进行促销)。