软件包推广

软件包推广是 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 extensions 仓库 包含 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 等现代软件包服务器中,软件包工件是去重的,也就是说,它们在复制到不同的位置(包括不同的仓库)时不会占用额外的存储空间。 去重是基于校验和的,因此系统也可以智能地避免重新上传现有工件。 这对于“推广”机制非常重要:该机制仅复制一些元数据,因此可以非常快速且节省存储空间。 流水线可以定义尽可能多的仓库和推广,而无需担心存储成本。

  • 也可以使用 Release Bundles 在 JFrog 平台上进行推广。 Conan extensions 仓库 也包含一个命令来生成发布包(可以使用 Artifatory API 进行推广)。