第485回で紹介したaptlyを使えば、
リポジトリの作成
第487回でバイナリパッケージの作成方法を学びました。次はそれを公開するリポジトリをaptlyを用いて作成しましょう。aptlyのインストール方法や基本的な使い方は第485回を参照してください。
aptlyで作ったリポジトリのフロントエンド部分~/.aptly/
」/srv
」~/.aptly.
」/etc/
」
{
"architectures": [ "all", "source", "armhf" ],
"FileSystemPublishEndpoints": {
"pomera": {
"rootDir": "/srv/aptly"
}
}
}
「pomera」/srv/
」architectures
にはアーキテクチャー非依存とソースパッケージ、-architecture
オプションで上書き可能です。
またローカルリポジトリも作りましょう。
$ aptly repo create -distribution=xenial-backports -component=main xenial-armhf
「-distribution
」/etc/
)-component
」
パッケージのリポジトリへの取り込み
aptlyのローカルリポジトリにパッケージを取り込みます。第487回でも説明したように、
個々のパッケージを構成するファイル群は.changes
ファイル」.changes
ファイルにはファイル名だけでなくそのハッシュ値も記録されているために、.changes
ファイルを用いて一度に取り込めたほうが便利ですし、
まずは.changes
ファイルに署名を行う人のGPG公開鍵をaptlyユーザーの鍵束に取り込んでおきます。
(パッケージに署名を行うマシン上で、公開鍵をエクスポートする) $ gpg --export --armor --output shibata.asc [email protected] $ file shibata.asc shibata.asc: PGP public key block Public-Key (old)
上記の手順でエクスポートした公開鍵ファイルshibata.
をaptlyが動くマシン上に何らかの安全な経路を使ってコピーしておきます
aptlyが動いているマシン上で、~/.gnupg/
」--keyring
」
$ gpg --no-default-keyring --keyring trustedkeys.gpg --import shibata.asc gpg: keyring `/home/aptly/.gnupg/trustedkeys.gpg' created gpg: key DF3CCF34: public key "Mitsuya Shibata <[email protected]>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) gpg: public key of ultimately trusted key 73C2FAC3 not found gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
最後に取り込んだGPG公開鍵で署名された.changes
ファイルをリポジトリに取り込んでみましょう。第487回のやり方に沿ってパッケージをビルドしていれば、
$ aptly repo include -repo=xenial-armhf tmux_2.5-3build1~ubuntu16.04.1_source.changes gpgv: Signature made Sat Sep 2 12:18:40 2017 JST using RSA key ID DF3CCF34 gpgv: Good signature from "Mitsuya Shibata <[email protected]>" Loading repository xenial-armhf for changes file tmux_2.5-3build1~ubuntu16.04.1_source.changes... [+] tmux_2.5-3build1~ubuntu16.04.1_source added
「-repo
」.changes
ファイルのDistribution
」.changes
ファイルの代わりにディレクトリを指定した場合は、.changes
ファイルを順番にチェックしていきます。
「-uploaders-file
」.changes
ファイルの署名のチェックは行います。ちなみにaptly repo create
のときにも指定できます。
同じ名前・-force-replace
」
リポジトリにパッケージを取り込むことに成功したら、-no-remove-files
」
「aptly repo show
」
$ aptly repo show --with-packages=true xenial-armhf Name: xenial-armhf Comment: Default Distribution: xenial-backports Default Component: main Number of packages: 1 Packages: tmux_2.5-3build1~ubuntu16.04.1_source
バイナリパッケージへの署名
一般的なDebianパッケージの開発フローにおいて、
もっとも手っ取り早い方法はdevscriptsパッケージに所属するdebsign
コマンドを使うことです。
$ debsign tmux_2.5-3build1~ubuntu16.04.1_armhf.changes
これだけで.changes
ファイルが署名済みのファイルに置き換わります。オプションなどの詳しい使い方についてはdebsignのマニュアルページを参照してください。
あとはソースパッケージと同じように.changes
ファイルを指定すれば、
$ aptly repo include -repo=xenial-armhf tmux_2.5-3build1~ubuntu16.04.1_armhf.changes gpgv: Signature made Mon Sep 18 18:53:32 2017 JST using RSA key ID DF3CCF34 gpgv: Good signature from "Mitsuya Shibata <[email protected]>" Loading repository xenial-armhf for changes file tmux_2.5-3build1~ubuntu16.04.1_armhf.changes... [+] tmux-dbgsym_2.5-3build1~ubuntu16.04.1_armhf added [+] tmux_2.5-3build1~ubuntu16.04.1_armhf added
「aptly repo show
」
$ aptly repo show --with-packages=true xenial-armhf Name: xenial-armhf Comment: Default Distribution: xenial-backports Default Component: main Number of packages: 3 Packages: tmux_2.5-3build1~ubuntu16.04.1_armhf tmux_2.5-3build1~ubuntu16.04.1_source tmux-dbgsym_2.5-3build1~ubuntu16.04.1_armhf
パッケージリポジトリを公開状態にする
ローカルリポジトリのデータを元にパッケージリポジトリを作成しましょう。第485回でも説明したように公開するパッケージリポジトリはリポジトリの流儀に沿ってHTTPでアクセス可能なディレクトリツリーです。
まずあらかじめ~/.aptly.
で指定した公開リポジトリ用のディレクトリを作っておきます。
$ sudo mkdir -p /srv/aptly $ sudo chown aptly: /srv/aptly
さらにローカルリポジトリのスナップショットを作成します。そうすることでローカルリポジトリの状態と公開リポジトリの状態を独立して管理できます。
$ aptly snapshot create xenial-backports-20170918 from repo xenial-armhf Snapshot xenial-backports-20170918 successfully created. You can run 'aptly publish snapshot xenial-backports-20170918' to publish snapshot as Debian repository.
最後に作ったスナップショットを公開します。第485回と異なるのは公開するストレージ~/.aptly.
ではFileSystemPublishEndpoints
としてpomera
を作成しましたので、filesystem:pomera
」
$ aptly publish snapshot xenial-backports-20170918 filesystem:pomera: Loading packages... Generating metadata files and linking package files... Finalizing metadata files... Signing file 'Release' with gpg, please enter your passphrase when prompted: Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: Snapshot xenial-backports-20170918 has been successfully published. Please setup your webserver to serve directory '/srv/aptly' with autoindexing. Now you can add following line to apt sources: deb http://your-server/ xenial-backports main deb-src http://your-server/ xenial-backports main Don't forget to add your GPG key to apt with apt-key. You can also use `aptly serve` to publish your repositories over HTTP quickly.
エンドポイントとしてローカルストレージ以外にAmazon S3やOpenStack Swiftといったクラウドストレージも指定可能です。また最後のコロンの後ろにパス名を指定することで、
作られたディレクトリの中身は次のような構造になっています。
(メタデータ類) $ ls /srv/aptly/dists/xenial-backports/ InRelease Release Release.gpg main (パッケージの実体) $ ls /srv/aptly/pool/main/t/tmux/ tmux-dbgsym_2.5-3build1~ubuntu16.04.1_armhf.ddeb tmux_2.5-3build1~ubuntu16.04.1.dsc tmux_2.5.orig.tar.gz tmux_2.5-3build1~ubuntu16.04.1.debian.tar.xz tmux_2.5-3build1~ubuntu16.04.1_armhf.deb
たとえばjp.~/.aptly/
」
Nginxを用いて外部からアクセスできるようにする
ここまでの状態だとローカルファイルシステム上にパッケージディレクトリが配置されているだけです。リポジトリとして運用するためには、
たとえばNginxを使う場合、/etc/
」/etc/
」server_
部分をリポジトリのドメイン名にしておきます。またautoindex on
にしておくことで、
server {
listen 80;
listen [::]:80;
server_name aptly.example.com;
root /srv/aptly;
location / {
autoindex on;
}
}
設定したらsudo service nginx configtest
」sudo systemctl restart nginx
」
クライアント側ではリポジトリの公開鍵とURLを登録します。リポジトリの公開鍵は、
$ gpg --export --armor --output aptly.asc [email protected]
一般的には上記ファイルをHTTPS経由で取得できる場所に置いておきます。もしくは鍵サーバー上に公開鍵を登録しておき、
あとはこのリポジトリ鍵を登録し、sources.
を設定します。ここでaptlyが動いているマシンのアドレスをaptly.
」
$ sudo apt-key add aptly.asc $ echo "deb http://aptly.example.com/ xenial-backports main" | sudo tee /etc/apt/sources.list.d/aptly.list $ sudo apt update $ sudo apt policy tmux
先程登録したtmuxのバックポートパッケージのバージョンが表示されたら成功です。
パッケージのアップロードを簡単にする
パッケージをビルドするマシン.changes
ファイルをはじめとしたビルドした成果物を公開するマシンにコピーする必要があります。このときdput
コマンドを使うと手間が省けて便利です。dputはDebianパッケージのメンテナーが新しいパッケージをアップロードキューに送ったり、
dput自体は必要なファイルを指定したサーバーに送るだけの単なるPythonスクリプトであり、/etc/
もしくは~/.dput.
で設定すれば、
たとえばaptly./srv/
ディレクトリに、
[aptly]
login = aptly
fqdn = aptly.example.com
method = scp
ssh_config_options =
Port 2222
incoming = /srv/aptly/queue
allow_dcut = 1
dput
コマンドに.changes
ファイルを指定すればアップロードできます。
$ dput aptly tmux_2.5-3build1~ubuntu16.04.1_source.changes Checking signature on .changes (中略) Good signature on /home/shibata/backport/sign/tmux_2.5-3build1~ubuntu16.04.1.dsc. Package includes an .orig.tar.gz file although the debian revision suggests that it might not be required. Multiple uploads of the .orig.tar.gz may be rejected by the upload queue management software. Uploading to aptly (via scp to aptly.example.com): tmux_2.5-3build1~ubuntu16.04.1.dsc 100% 2060 3.3MB/s 00:00 tmux_2.5.orig.tar.gz 100% 465KB 62.9MB/s 00:00 tmux_2.5-3build1~ubuntu16.04.1.debian.tar.xz 100% 12KB 17.7MB/s 00:00 tmux_2.5-3build1~ubuntu16.04.1_source.changes 100% 7162 12.4MB/s 00:00 Successfully uploaded packages.
署名済みかどうかもチェックしてくれるので便利です。ちなみにローカルで一度アップロードするとchangesファイル名.対象マシン名.upload
」--force
」
aptly側でsystemd./srv/
をチェックするようにしておけば、