LoginSignup
30
29

More than 5 years have passed since last update.

Consulをfpmでrpm化する

Posted at

公式にはバイナリのみを提供しているみたいなので、もう少し楽なように各種ディレクトリや展開済のWeb UIをrpm化しておいた。Puppet/Chefのコード数が減って便利。

サードパーティのrpmは他にもあるのだが、個人的に

config-dirは /etc/consul.d
data-dirは   /var/consul/data
ui-dirは     /var/consul/web_ui

でやっていきたいので自分で雑に書いた。

fpm が便利

fpm は各プラットフォームのパッケージを簡単に作成できるコマンド。Rubyのgemで提供されている。

  • 適当なrootfsにディレクトリとファイル構成を構築する
  • そこを指定して、後は適当にメンテナ名などの設定を入れつつコマンドを放つ

Goの場合、バイナリ一発+設定のディレクトリやファイル ぐらいしか必要ないのでこれだけでできる(rpmを作る場合は別途 rpm-builder が必要だった)。

fpm -s dir -t rpm -n consul-web_ui -v ${CONSUL_VERSION} -p /var/tmp/consul-web_ui.rpm \
    --rpm-compression bzip2 --rpm-os linux \
    --force \
    --iteration $(date +%s) \
    --epoch $RPM_EPOCH \
    --url https://www.consul.io/ \
    --description "Consul Web UI - Consul is a tool for service discovery and configuration. Consul is distributed, highly available, and extremely scalable." \
    --maintainer "Uchio KONDO <udzura@udzura.jp>" \
    --license "MPLv2.0" \
    --vendor "hashicorp" -a amd64 \
    /rootfs/=/

こんな感じで、まあ一つ一つ項目を埋めていけば良い。メンテナは当然自分だが、なんかくすぐったいですね...。

あと、今回は consul agent のサービス化はやってなくて、適当に自分で設定を書いて supervisord などを使えば良いかなと思った。サービスを入れたりするとpost-installやpre-uninstallなどのフックでサービスをどうこうする必要が出てくるが、fpmはそれも対応してるんで便利感がある。

というか、 Drone の Makefile が参考になる。ぼくもほとんどこれをコピペしただけです...。

Dockerでビルドしてる

こちらの話の通り、クリーンな環境を毎回作ってビルドできるのは安心感があるので採用した。

30
29
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
30
29