5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

FreeBSDでパッケージを使っていると、

  • 「デフォルトのビルドオプションを変えたい」
  • 「最新のPortsを使いたい」
  • 「複数のサーバーに同じパッケージを配りたい」

という要望が出てくる。

そんなときに使うのがpoudriere(プードリエール)。

公式のパッケージビルドシステムそのものだ。

poudriereとは

  • FreeBSD公式のパッケージビルドインフラ
  • jail内でクリーンビルド
  • 複数のFreeBSDバージョン向けにビルド可能
  • 独自のpkgリポジトリを構築できる

インストール

pkg install poudriere

初期設定

設定ファイルの準備

cp /usr/local/etc/poudriere.conf.sample /usr/local/etc/poudriere.conf

主要な設定

# /usr/local/etc/poudriere.conf

# ZFSを使う(推奨)
ZPOOL=zroot
ZROOTFS=/poudriere

# データディレクトリ
POUDRIERE_DATA=${BASEFS}/data

# jail用のFreeBSDバージョン取得先
FREEBSD_HOST=https://download.FreeBSD.org

# Portsツリーの取得方法
# git(推奨)
PORTSTREE_METHOD=git
PORTSTREE_URL=https://git.FreeBSD.org/ports.git

# CPUコア数(make -j)
PARALLEL_JOBS=4

# distfiles保存場所
DISTFILES_CACHE=/usr/ports/distfiles

# ccache(オプション)
CCACHE_DIR=/var/cache/ccache

ZFSデータセット作成

# poudriere用のデータセットを作成
zfs create -o mountpoint=/poudriere zroot/poudriere

jailの作成

poudriereはjail内でビルドする。

FreeBSD 14.2-RELEASE用のjailを作成

poudriere jail -c -j 142amd64 -v 14.2-RELEASE -a amd64

オプションの意味:

  • -c: 作成(create)
  • -j 142amd64: jail名
  • -v 14.2-RELEASE: FreeBSDバージョン
  • -a amd64: アーキテクチャ

jail一覧

poudriere jail -l
# JAILNAME        VERSION         ARCH    METHOD  TIMESTAMP           PATH
# 142amd64        14.2-RELEASE    amd64   http    2024-11-01 12:00    /poudriere/jails/142amd64

jailの更新

poudriere jail -u -j 142amd64

jailの削除

poudriere jail -d -j 142amd64

Portsツリーの作成

# 最新のPortsツリーを取得
poudriere ports -c -p default

# 特定のブランチを使う場合
poudriere ports -c -p quarterly -B 2024Q4

Portsツリー一覧

poudriere ports -l
# PORTSTREE  METHOD  TIMESTAMP           PATH
# default    git     2024-11-01 12:00    /poudriere/ports/default

Portsツリーの更新

poudriere ports -u -p default

ビルドするパッケージの指定

パッケージリストファイルを作成

# /usr/local/etc/poudriere.d/pkglist
editors/vim
www/nginx
lang/python311
databases/postgresql15-server
www/apache24
lang/php83
security/sudo
shells/zsh

カテゴリ/Port名形式で書く

# 調べ方
pkg search nginx
# nginx-1.24.0,3     Robust and small WWW server
# →  www/nginx

ビルドオプションの設定

全ポートのオプションを設定

poudriere options -j 142amd64 -p default -f /usr/local/etc/poudriere.d/pkglist

各portのmake configメニューが順番に表示される。

特定のportのオプションを設定

poudriere options -j 142amd64 -p default www/nginx

オプション設定の保存場所

ls /usr/local/etc/poudriere.d/142amd64-default-options/
# www_nginx/
# editors_vim/
# ...

ファイルで直接設定

# /usr/local/etc/poudriere.d/142amd64-default-options/www_nginx/options
_OPTIONS_READ=nginx-1.24.0
_FILE_COMPLETE_OPTIONS_LIST=DEBUG DSO ...
OPTIONS_FILE_SET+=HTTP_GZIP_STATIC
OPTIONS_FILE_SET+=HTTP_SSL
OPTIONS_FILE_UNSET+=MAIL

make.confの設定

jail固有のビルド設定。

# /usr/local/etc/poudriere.d/142amd64-make.conf

# 全ポートに適用
WITH_DEBUG=yes
CFLAGS+=-O2

# 特定のportに適用
www_nginx_SET=HTTP_SSL HTTP_V2 HTTP_GZIP_STATIC
www_nginx_UNSET=MAIL MAIL_IMAP MAIL_POP3

# PHPのデフォルト
DEFAULT_VERSIONS+=php=8.3
DEFAULT_VERSIONS+=python=3.11
DEFAULT_VERSIONS+=pgsql=15

ビルド実行

# パッケージリストをビルド
poudriere bulk -j 142amd64 -p default -f /usr/local/etc/poudriere.d/pkglist

ビルド中の表示

[00:00:00] ====>> Creating the reference jail... done
[00:00:01] ====>> Mounting system devices for 142amd64-default
[00:00:02] ====>> Mounting ports/packages/distfiles
[00:00:03] ====>> Appending to make.conf: /usr/local/etc/poudriere.d/142amd64-make.conf
[00:00:04] ====>> Starting jail 142amd64-default
[00:00:05] ====>> Logs: /poudriere/data/logs/bulk/142amd64-default/2024-11-01_12h00m00s
[00:00:06] ====>> WWW: http://localhost:80/build.html
[00:01:00] ====>> [00] [00:01:00] [Building: 5/50]  Built: 3   Failed: 0   Skipped: 0   Ignored: 0   Queued: 45   
[00:02:00] ====>> [01] [00:02:00] [Building: 5/50]  Built: 15  Failed: 0   Skipped: 0   Ignored: 0   Queued: 35

特定のパッケージだけビルド

poudriere bulk -j 142amd64 -p default www/nginx

テストビルド(-t)

poudriere bulk -j 142amd64 -p default -t www/nginx

-tをつけると依存パッケージのテストも実行。

Web UI

poudriereにはビルド状況を見るためのWebインターフェースがある。

Nginxの設定例

# /usr/local/etc/nginx/nginx.conf

server {
    listen 80;
    server_name poudriere.local;
    
    root /usr/local/share/poudriere/html;
    
    location /data {
        alias /poudriere/data/logs/bulk;
        autoindex on;
    }
    
    location /packages {
        alias /poudriere/data/packages;
        autoindex on;
    }
}

アクセスするとリアルタイムでビルド状況が見れる。

ビルド結果

パッケージの場所

ls /poudriere/data/packages/142amd64-default/All/
# nginx-1.24.0,3.pkg
# vim-9.0.2000.pkg
# python311-3.11.6.pkg
# ...

ログの場所

ls /poudriere/data/logs/bulk/142amd64-default/
# 2024-11-01_12h00m00s/
#   logs/
#     www_nginx.log
#     editors_vim.log
#   ...

失敗したビルドの確認

cat /poudriere/data/logs/bulk/142amd64-default/latest/logs/errors/*.log

独自リポジトリとして公開

リポジトリ設定ファイル

# /usr/local/etc/pkg/repos/poudriere.conf

poudriere: {
    url: "file:///poudriere/data/packages/142amd64-default",
    enabled: yes,
    priority: 100
}

# 公式リポジトリを無効化する場合
FreeBSD: {
    enabled: no
}

HTTPで公開する場合

# /usr/local/etc/pkg/repos/poudriere.conf

poudriere: {
    url: "http://pkg.example.com/poudriere/packages/142amd64-default",
    enabled: yes
}

クライアント側で使う

pkg update
# Updating poudriere repository catalogue...
# poudriere repository is up to date.

pkg install nginx
# 自分のビルドしたパッケージがインストールされる

ccacheでビルド高速化

ccacheインストール

pkg install ccache

poudriere設定

# /usr/local/etc/poudriere.conf
CCACHE_DIR=/var/cache/ccache

キャッシュディレクトリ作成

mkdir -p /var/cache/ccache

2回目以降のビルドが劇的に速くなる。

複数バージョン対応

# FreeBSD 13.4用
poudriere jail -c -j 134amd64 -v 13.4-RELEASE -a amd64

# FreeBSD 14.2用
poudriere jail -c -j 142amd64 -v 14.2-RELEASE -a amd64

# arm64用(クロスビルド)
poudriere jail -c -j 142arm64 -v 14.2-RELEASE -a arm64

全部ビルド

for jail in 134amd64 142amd64; do
    poudriere bulk -j $jail -p default -f /usr/local/etc/poudriere.d/pkglist
done

トラブルシューティング

ビルド失敗

# ログを確認
cat /poudriere/data/logs/bulk/142amd64-default/latest/logs/errors/www_nginx.log

# 個別に再ビルド
poudriere bulk -j 142amd64 -p default -t www/nginx

ディスク容量不足

# 古いビルドログを削除
poudriere logclean -j 142amd64 -p default -N 5

# 古いパッケージを削除
poudriere pkgclean -j 142amd64 -p default

jailが壊れた

poudriere jail -d -j 142amd64
poudriere jail -c -j 142amd64 -v 14.2-RELEASE -a amd64

自動化スクリプト

#!/bin/sh
# /usr/local/bin/update-poudriere.sh

JAIL="142amd64"
PORTS="default"
PKGLIST="/usr/local/etc/poudriere.d/pkglist"

# Portsツリー更新
poudriere ports -u -p $PORTS

# jail更新
poudriere jail -u -j $JAIL

# ビルド
poudriere bulk -j $JAIL -p $PORTS -f $PKGLIST

# 古いログ/パッケージ削除
poudriere logclean -j $JAIL -p $PORTS -N 3
poudriere pkgclean -j $JAIL -p $PORTS -y
# crontabに登録
0 3 * * 0 /usr/local/bin/update-poudriere.sh > /var/log/poudriere-weekly.log 2>&1

まとめ

poudriereを使えば:

  • カスタムオプションでパッケージをビルド
  • 複数バージョンのFreeBSD向けに同時ビルド
  • 独自リポジトリを運用できる
  • 公式と同じビルドシステム

自分用のカスタムパッケージを作りたいなら、poudriereは必須ツール。

この記事が役に立ったら、いいね・ストックしてもらえると嬉しいです!

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?