LoginSignup
14
13

More than 5 years have passed since last update.

nginx.orgのrpmをカスタマイズしてfedora coprでビルド・配布するのを試してみた

Last updated at Posted at 2015-12-05

nginx Advent Calendar 2015の12/4(金)の枠が空いたまま過ぎていたので、今からこの記事を書いて登録しようと思います。

はじめに

nginxはCentOS 7だとepelに含まれていますが、こちらはバージョンが古いです。最近まではnginx: downloadのyumレポジトリを活用していました。が、luaを使いたい場合など、追加モジュールを利用する場合はソースからビルド必要があります。

nginx-buildでnginxをビルドしよう - Qiitaで説明されている方法もありますが、CentOSならrpmで管理したいという思いもあります。

そこで、fedora projectのcoprというサービスでngnxのrpmをビルド・配布するのを試してみました。

私が作成したnginxのrpmについて

Travis CIでdockerでnginxのsrpmを作ってcoprでビルドするのに必要なファイルをgithubのhnakamur/nginx-rpmに置いています。

nginx.orgのrpmのspecファイルをベースに以下の3つのモジュールをビルドするようにしています。

srpmの作成

srpmのビルド手順はDockerfileに書いています。主な部分を以下に抜粋します。

…(略)…
 && cd /root/rpmbuild/SRPMS \
 && curl -sLO http://nginx.org/packages/mainline/centos/7/SRPMS/nginx-${NGINX_VERSION}-1.el7.ngx.src.rpm \
 && rpm -i nginx-${NGINX_VERSION}-1.el7.ngx.src.rpm \
 && cd /root/rpmbuild/SOURCES \
 && curl -sLO https://github.com/openresty/lua-nginx-module/archive/v${NGX_LUA_VERSION}.tar.gz#/lua-nginx-module-${NGX_LUA_VERSION}.tar.gz \
 && curl -sLO https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.tar.gz#/nginx_upstream_check_module-master.tar.gz \
 && curl -sLO https://github.com/replay/ngx_http_consistent_hash/archive/master.tar.gz#/ngx_http_consistent_hash-master.tar.gz

ADD nginx.spec.patch /root/rpmbuild/SPECS/

RUN cd /root/rpmbuild/SPECS \
 && patch -p0 < nginx.spec.patch \
 && rpmbuild -bs nginx.spec
…(略)…

nginx.orgで提供しているrpmに含まれる nginx.spec に以下のパッチを当てています。

//github.com/hnakamur/nginx-rpm/blob/169bf4f4e49d8a4b80626481de42a67f3ac8034a/nginx.spec.patch
--- nginx.spec.orig 2015-11-18 00:07:19.000000000 +0900
+++ nginx.spec  2015-12-06 17:51:40.000000000 +0900
@@ -74,11 +74,16 @@
 Source9: nginx.upgrade.sh
 Source10: nginx.suse.logrotate

+Source100: https://github.com/openresty/lua-nginx-module/archive/v0.9.19.tar.gz#/lua-nginx-module-0.9.19.tar.gz 
+Source101: https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.tar.gz#/nginx_upstream_check_module-master.tar.gz
+Source102: https://github.com/replay/ngx_http_consistent_hash/archive/master.tar.gz#/ngx_http_consistent_hash-master.tar.gz
+
 License: 2-clause BSD-like license

 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
 BuildRequires: zlib-devel
 BuildRequires: pcre-devel
+BuildRequires: luajit-devel

 Provides: webserver

@@ -98,7 +103,8 @@
 %endif

 %prep
-%setup -q
+%setup -q -a 100 -a 101 -a 102
+patch -p0 < ./nginx_upstream_check_module-master/check_1.9.2+.patch

 %build
 ./configure \
@@ -136,6 +142,9 @@
         --with-mail_ssl_module \
         --with-file-aio \
         --with-ipv6 \
+        --add-module=./lua-nginx-module-0.9.19 \
+        --add-module=./nginx_upstream_check_module-master \
+        --add-module=./ngx_http_consistent_hash-master \
         --with-debug \
         %{?with_http2:--with-http_v2_module} \
         --with-cc-opt="%{optflags} $(pcre-config --cflags)" \
@@ -178,6 +187,9 @@
         --with-mail_ssl_module \
         --with-file-aio \
         --with-ipv6 \
+        --add-module=./lua-nginx-module-0.9.19 \
+        --add-module=./nginx_upstream_check_module-master \
+        --add-module=./ngx_http_consistent_hash-master \
         %{?with_http2:--with-http_v2_module} \
         --with-cc-opt="%{optflags} $(pcre-config --cflags)" \
         $*

変更内容を説明します。

coprでのrpmのビルド・配布

上記で作成したsrpmをcoprでビルドするのは copr-build.shで行っています。詳細についてはTravis CIとcopr.fedoraproject.orgを使ってrpmをビルド・配布するのを試してみた · hnakamur's blog at githubをご参照ください。

ビルドされたrpmのインストール方法

hnakamur/nginx Coprの"Installation Instructions"にも書いていますが、作成したrpmは以下のコマンドでインストールできます。

sudo curl -sL -o /etc/yum.repos.d/hnakamur-nginx.repo https://copr.fedoraproject.org/coprs/hnakamur/nginx/repo/epel-7/hnakamur-nginx-epel-7.repo

sudo yum install nginx

おわりに

coprを利用すると自作のrpmをホスティングしてくれるのでかなり便利です。みなさんもいろいろなrpmをcoprでビルド・配布してみてはいかがでしょうか。

14
13
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
14
13