4.6.使用 Poudriere 构建软件包

poudriere 是一个基于 BSD 许可的软件,用于创建和测试 FreeBSD 软件包。它使用 FreeBSD jail 来设置隔离的编译环境。这些 jails 可用于为与安装它的系统不同版本的 FreeBSD 构建软件包,也可用于在宿主系统是 amd64 系统的情况下构建 i386 的软件包。构建完成后,这些软件包的布局与官方镜像完全相同。这些软件包可供 pkg(8) 和其他软件包管理工具使用。

使用 ports-mgmt/poudriere 软件包或 Port 安装 poudriere。安装包括一个示例配置文件 /usr/local/etc/poudriere.conf.sample。将此文件复制到 /usr/local/etc/poudriere.conf。编辑复制的文件以适应本地配置。

虽然在运行 poudriere 的系统上不需要 ZFS,但它是有益的。当使用 ZFS 时,必须在 /usr/local/etc/poudriere.conf 中指定 ZPOOL,并将 FREEBSD_HOST 设置为附近的镜像。定义 CCACHE_DIR 启用使用 devel/ccache 来缓存编译并减少频繁编译的代码的构建时间。将 poudriere 数据集放在一个在 /poudriere 挂载的隔离树中可能很方便。其他配置值的默认值是足够的。

检测到的处理器核心数用于定义将并行运行多少个构建。提供足够的虚拟内存,可以是 RAM 或交换空间。如果虚拟内存用尽,编译 jails 将停止并被拆除,导致奇怪的错误消息。

4.6.1. 初始化 Jail 和 Ports

配置完成后,初始化 poudriere 以安装一个带有所需 FreeBSD 和一个 Ports 的 jail。使用 -j 指定 jail 的名称,并使用 -v 指定 FreeBSD 版本。在运行 FreeBSD/amd64 的系统上,可以使用 -a 将架构设置为 i386amd64。默认值是 uname 显示的架构。

# poudriere jail -c -j 13amd64 -v 13.1-RELEASE
[00:00:00] Creating 13amd64 fs at /poudriere/jails/13amd64... done
[00:00:00] Using pre-distributed MANIFEST for FreeBSD 13.1-RELEASE amd64
[00:00:00] Fetching base for FreeBSD 13.1-RELEASE amd64
/poudriere/jails/13amd64/fromftp/base.txz              125 MB 4110 kBps    31s
[00:00:33] Extracting base... done
[00:00:54] Fetching src for FreeBSD 13.1-RELEASE amd64
/poudriere/jails/13amd64/fromftp/src.txz               154 MB 4178 kBps    38s
[00:01:33] Extracting src... done
[00:02:31] Fetching lib32 for FreeBSD 13.1-RELEASE amd64
/poudriere/jails/13amd64/fromftp/lib32.txz              24 MB 3969 kBps    06s
[00:02:38] Extracting lib32... done
[00:02:42] Cleaning up... done
[00:02:42] Recording filesystem state for clean... done
[00:02:42] Upgrading using ftp
/etc/resolv.conf -> /poudriere/jails/13amd64/etc/resolv.conf
Looking up update.FreeBSD.org mirrors... 3 mirrors found.
Fetching public key from update4.freebsd.org... done.
Fetching metadata signature for 13.1-RELEASE from update4.freebsd.org... done.
Fetching metadata index... done.
Fetching 2 metadata files... done.
Inspecting system... done.
Preparing to download files... done.
Fetching 124 patches.....10....20....30....40....50....60....70....80....90....100....110....120.. done.
Applying patches... done.
Fetching 6 files... done.
The following files will be added as part of updating to
13.1-RELEASE-p1:
/usr/src/contrib/unbound/.github
/usr/src/contrib/unbound/.github/FUNDING.yml
/usr/src/contrib/unbound/contrib/drop2rpz
/usr/src/contrib/unbound/contrib/unbound_portable.service.in
/usr/src/contrib/unbound/services/rpz.c
/usr/src/contrib/unbound/services/rpz.h
/usr/src/lib/libc/tests/gen/spawnp_enoexec.sh
The following files will be updated as part of updating to
13.1-RELEASE-p1:
[…]
Installing updates...Scanning //usr/share/certs/blacklisted for certificates...
Scanning //usr/share/certs/trusted for certificates...
 done.
13.1-RELEASE-p1
[00:04:06] Recording filesystem state for clean... done
[00:04:07] Jail 13amd64 13.1-RELEASE-p1 amd64 is ready to be used
# poudriere ports -c -p local -m git+https
[00:00:00] Creating local fs at /poudriere/ports/local... done
[00:00:00] Checking out the ports tree... done

在一台计算机上,poudriere 可以使用多个配置构建多个 jail、 Ports,并使用不同的 Ports。这些组合的自定义配置称为 set。在安装 ports-mgmt/poudriereports-mgmt/poudriere-devel 之后,请参阅 poudriere(8) 中的 CUSTOMIZATION 部分以获取详细信息。

这里展示的基本配置将在 /usr/local/etc/poudriere.d 中放置一个特定于单个 jail、 Port 和集的 make.conf 文件。在本例中,文件名是通过组合 jail 名称、 Ports 名称和集名称创建的:13amd64-local-workstation-make.conf。系统 make.conf 和这个新文件在构建时合并,以创建构建 jail 使用的 make.conf

要构建的软件包输入到 13amd64-local-workstation-pkglist 中(具有 FLAVORS 的 Port 可以使用 @FLAVOR 定义):

editors/emacs
devel/git
devel/php-composer2@php82
ports-mgmt/pkg
...

配置指定 Port 的选项和依赖关系:

# poudriere options -j 13amd64 -p local -z workstation -f 13amd64-local-workstation-pkglist

最后,构建软件包并创建软件包存储库:

# poudriere bulk -j 13amd64 -p local -z workstation -f 13amd64-local-workstation-pkglist

在运行时,按 Ctrl + t 可显示构建的当前状态。poudriere 还在 /poudriere/logs/bulk/jailname 中构建文件,可以与 web 服务器一起使用以显示构建信息。

完成后,新的软件包现在可以从 poudriere 存储库中安装。

有关使用 poudriere 的更多信息,请参阅 poudriere(8) 和主要网站 https://github.com/freebsd/poudriere/wiki

4.6.2. 配置 pkg 客户端以使用 poudriere 存储库

虽然可以同时使用自定义存储库和官方存储库,但有时禁用官方存储库会很有用。这可以通过创建覆盖并禁用官方配置文件的配置文件来完成。创建包含以下内容的 /usr/local/etc/pkg/repos/FreeBSD.conf 文件:

FreeBSD: {
	enabled: no
}

通常,最简单的方法是通过 HTTP 向客户机提供 poudriere 存储库。设置一个 web 服务器以提供软件包目录,例如:/usr/local/poudriere/data/packages/13amd64,其中 13amd64 是构建的名称。

如果软件包存储库的 URL 是:<a href="http://pkg.example.com/13amd64" class="bare">http://pkg.example.com/13amd64</a>,那么位于 /usr/local/etc/pkg/repos/custom.conf 的存储库配置文件如下:

custom: {
	url: "http://pkg.example.com/13amd64",
	enabled: yes,
}

如果不希望将软件包存储库暴露给互联网,可以使用 file:// 协议直接指向存储库:

custom: {
	url: "file:///usr/local/poudriere/data/packages/11amd64",
	enabled: yes,
}

最后更新于

FreeBSD 中文社区