软件包流水线:多配置

在上一节中,我们只构建了 1 种配置。本节将介绍需要构建多于 1 种配置的情况。为方便起见,我们将在这里使用 ReleaseDebug 配置,因为这样更容易理解,但在实际情况中,这些配置更像是针对不同架构的 Windows、Linux、OSX 构建,或者交叉构建等。

让我们开始清理我们的缓存

$ conan remove "*" -c  # Make sure no packages from last run

我们将在计算机上依次为这两种配置创建软件包,但请注意,这通常会在不同的计算机上运行,因此 CI 系统通常会并行启动不同配置的构建。

Release 构建
$ cd ai  # If you were not inside "ai" folder already
$ conan create . --build="missing:ai/*" -s build_type=Release --format=json > graph.json
$ conan list --graph=graph.json --graph-binaries=build --format=json > built.json

$ conan remote enable packages
$ conan upload -l=built.json -r=packages -c --format=json > uploaded_release.json
$ conan remote disable packages

我们做了一些更改和额外的步骤

  • 第一步与上一节中的类似,执行一个 conan create 命令,为了清晰起见,我们明确指定我们的配置 -s build_type=Release,并将 conan create 的输出捕获到 graph.json 文件中。

  • 第二步是从 graph.json 创建一个 built.json **软件包列表**文件,其中包含需要上传的软件包。在这种情况下,只有从源代码构建的软件包(--graph-binaries=build)将被上传。这样做是为了提高效率和加快上传速度。

  • 第三步是启用 packages 仓库。它之前未被启用,以确保所有可能的依赖项仅来自 develop 仓库。

  • 然后,我们将 built.json 软件包列表上传到 packages 仓库,创建 uploaded_release.json 软件包列表,其中包含软件包的新位置(服务器仓库)。

  • 最后,我们将再次禁用 packages 仓库

同样,Debug 构建也会执行相同的步骤

Debug 构建
$ conan create . --build="missing:ai/*" -s build_type=Debug --format=json > graph.json
$ conan list --graph=graph.json --graph-binaries=build --format=json > built.json

$ conan remote enable packages
$ conan upload -l=built.json -r=packages -c --format=json > uploaded_debug.json
$ conan remote disable packages

当 Release 和 Debug 配置都成功完成时,我们的仓库中将包含这些软件包

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 = "packages\n repository" shape = "box"; style=filled; color=lightblue; "packages" [style=invis]; "ai/1.1.0\n (Release)"; "ai/1.1.0\n (Debug)"; } subgraph cluster_2 { label = "products\n repository" shape = "box"; style=filled; color=lightblue; "products" [style=invis]; } subgraph cluster_3 { rankdir="BT"; shape = "box"; label = "develop repository"; color=lightblue; rankdir="BT"; node [fillcolor="lightskyblue", style=filled, shape=box] "game/1.0" -> "engine/1.0" -> "ai/1.0" -> "mathlib/1.0"; "engine/1.0" -> "graphics/1.0" -> "mathlib/1.0"; "mapviewer/1.0" -> "graphics/1.0"; "game/1.0" [fillcolor="lightgreen"]; "mapviewer/1.0" [fillcolor="lightgreen"]; } { edge[style=invis]; "packages" -> "products" -> "game/1.0" ; rankdir="BT"; } } }

ai/1.1.0 的所有不同二进制文件都正确构建后,软件包流水线 可以认为其任务成功并决定提升这些二进制文件。但是,还需要进一步的软件包构建和检查,因此 软件包流水线 可以将它们提升到 products 二进制仓库,而不是提升到 develop 仓库。由于所有其他开发人员和 CI 都使用 develop 仓库,因此在此阶段也不会破坏任何东西。

从 packages 提升到 product
# aggregate the package list
$ conan pkglist merge -l uploaded_release.json -l uploaded_debug.json --format=json > uploaded.json

$ conan remote enable packages
$ conan remote enable products
# Promotion using Conan download/upload commands
# (slow, can be improved with art:promote custom command)
$ conan download --list=uploaded.json -r=packages --format=json > promote.json
$ conan upload --list=promote.json -r=products -c
$ conan remote disable packages
$ conan remote disable products

第一步使用 conan pkglist merge 命令,将“Release”和“Debug”配置的软件包列表合并到一个 uploaded.json 软件包列表中。该列表将用于执行提升操作。

在本例中,我们使用了一个耗时的 conan download + conan upload 提升过程。使用 conan art:promote 扩展命令可以更高效。

运行提升后,服务器上将有以下软件包

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 = "packages\n repository" shape = "box"; style=filled; color=lightblue; "packages" [style=invis]; "ai/1.1.0\n (Release)"; "ai/1.1.0\n (Debug)"; } subgraph cluster_2 { label = "products\n repository" shape = "box"; style=filled; color=lightblue; "products" [style=invis]; "ai/promoted release" [label="ai/1.1.0\n (Release)"]; "ai/promoted debug" [label="ai/1.1.0\n (Debug)"]; } subgraph cluster_3 { rankdir="BT"; shape = "box"; label = "develop repository"; color=lightblue; rankdir="BT"; node [fillcolor="lightskyblue", style=filled, shape=box] "game/1.0" -> "engine/1.0" -> "ai/1.0" -> "mathlib/1.0"; "engine/1.0" -> "graphics/1.0" -> "mathlib/1.0"; "mapviewer/1.0" -> "graphics/1.0"; "game/1.0" [fillcolor="lightgreen"]; "mapviewer/1.0" [fillcolor="lightgreen"]; } { edge[style=invis]; "packages" -> "products" -> "game/1.0" ; rankdir="BT"; } } }

总结一下

  • 我们构建了 2 种不同的配置,ReleaseDebug(也可能是 Windows/Linux 或其他),并将它们上传到 packages 仓库。

  • 当所有配置的软件包二进制文件都成功构建后,我们将其从 packages 仓库提升到 products 仓库,以便为 products pipeline 提供可用性。

  • 在软件包创建过程中捕获了**软件包列表**,并将其合并成一个列表以执行提升操作。

我们还没有考虑一个方面,那就是 ai/1.1.0 的依赖项在构建过程中可能发生变化。请移至下一节,了解如何使用锁定文件来实现更一致的多配置构建。