包提升

包提升是推荐的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提升)的命令。