.rpmファイルの作成 (/root/rpmbuild/SPECS/〜.spec)

## mysql-ruby をrpm化してみる

* https://github.com/tmtm/ruby-mysql
* [Index of /downloads/mysql/ruby](http://tmtm.org/downloads/mysql/ruby/?C=M;O=D)
    * http://tmtm.org/downloads/mysql/ruby/mysql-ruby-2.8.2.tar.gz

対象は `/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so` 1ファイルのみ。


### specファイル

* `cp --parents`が便利。

```spec:/root/rpmbuild/SPECS/mysql-ruby.spec
%define name mysql-ruby
%define version 2.8.2
%define unmangled_version 2.8.2
%define release 1
%define _binaries_in_noarch_packages_terminate_build 0

Summary: mysql-ruby
Name: %{name}
Version: %{version}
Release: %{release}
License: Ruby's
Source0: %{name}-%{unmangled_version}.tar.gz
Group: Applications/File
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
Prefix: %{_prefix}
BuildArch: x86_64

%define INSTALLDIR %{buildroot}

%description
http://tmtm.org/downloads/mysql/ruby/

%prep

%build

%install
rm -rf %{INSTALLDIR}
mkdir -p %{INSTALLDIR}
cp --parents /usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so %{INSTALLDIR}

%clean
rm -rf %{buildroot}

%files
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so
%defattr(-,root,root)
```

### build

```rb:Dockerfile
FROM centos:6

ENV BUILDROOT="/root/rpmbuild"
WORKDIR $BUILDROOT/SOURCES/ruby/
RUN yum install -y ruby ruby-devel

# mysql-ruby
RUN tar xzf mysql-ruby-2.8.2.tar.gz \
 && cd mysql-ruby-2.8.2 \
 && ruby extconf.rb --with-mysql-dir=/opt/mysql \
 && make -s \
 && make install

# rpmbuild
WORKDIR $BUILDROOT/
COPY files.ruby/mysql-ruby.spec $BUILDROOT/SPECS/
RUN tar czf $BUILDROOT/SOURCES/mysql-ruby-2.8.2.tar.gz /usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so \
 && rpmbuild -ba SPECS/mysql-ruby.spec
```

* `/root/rpmbuild/RPMS/x86_64/mysql-ruby-2.8.2-1.x86_64.rpm` が生成される。


----

## ruby-dbi 0.4.3 をrpm化してみる

* https://github.com/erikh/ruby-dbi/tags

### spec

```spec:files.ruby/ruby-dbi.spec 
%define name ruby-dbi
%define version 0.4.3
%define unmangled_version 0.4.3
%define release 1
%define _binaries_in_noarch_packages_terminate_build 0

Summary: ruby-dbi
Name: %{name}
Version: %{version}
Release: %{release}
License: GPL
Source0: %{name}-%{unmangled_version}.tar.gz
Group: Applications/File
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
Prefix: %{_prefix}
BuildArch: x86_64

%define INSTALLDIR %{buildroot}

%description
https://github.com/erikh/ruby-dbi/

%prep

%build

%install
rm -rf %{INSTALLDIR}
mkdir -p %{INSTALLDIR}
cp --parents -a /usr/lib/ruby/site_ruby/1.8 %{INSTALLDIR}
cp --parents /usr/bin/dbi %{INSTALLDIR}
cp --parents /usr/bin/test_broken_dbi %{INSTALLDIR}

%clean
rm -rf %{buildroot}

%files
/usr/bin/dbi
/usr/bin/test_broken_dbi
/usr/lib/ruby/site_ruby/1.8
%defattr(-,root,root)
```

### build

```bash:Dockerfile
# mysql-dbi
WORKDIR $BUILDROOT/SOURCES/ruby/
COPY files.ruby/0.4.3_real.tar.gz .
RUN tar xzf 0.4.3_real.tar.gz \
 && cd ruby-dbi-0.4.3_real \
 && ruby setup.rb config \
 && ruby setup.rb setup \
 && ruby setup.rb install
# rpmbuild
WORKDIR $BUILDROOT/
COPY files.ruby/ruby-dbi.spec $BUILDROOT/SPECS/
RUN tar czf $BUILDROOT/SOURCES/ruby-dbi-0.4.3.tar.gz /usr/bin/dbi /usr/bin/test_broken_dbi /usr/lib/ruby/site_ruby/1.8 \
 && rpmbuild -ba SPECS/ruby-dbi.spec
```

----

## ruby-dbi 0.1.1 をrpm化してみる

```spec:files.ruby/ruby-dbi-0.1.1.spec
%define name ruby-dbi
%define version 0.1.1
%define unmangled_version 0.1.1
%define release 1
%define _binaries_in_noarch_packages_terminate_build 0

Summary: ruby-dbi
Name: %{name}
Version: %{version}
Release: %{release}
License: GPL
Source0: %{name}-%{unmangled_version}.tar.gz
Group: Applications/File
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
Prefix: %{_prefix}
BuildArch: x86_64

%define INSTALLDIR %{buildroot}

%description
https://github.com/erikh/ruby-dbi/

%prep

%build

%install
rm -rf %{INSTALLDIR}
mkdir -p %{INSTALLDIR}
cp --parents -a /usr/lib/ruby/site_ruby/1.8 %{INSTALLDIR}
cp --parents /usr/bin/sqlsh.rb %{INSTALLDIR}

%clean
rm -rf %{buildroot}

%files
/usr/bin/sqlsh.rb
/usr/lib/ruby/site_ruby/1.8
%defattr(-,root,root)
```

```bash:Dockerfile
# ruby-dbi 0.1.1
WORKDIR $BUILDROOT/SOURCES/ruby/
COPY files.ruby/rel-0-1-1.tar.gz .
RUN tar xzf rel-0-1-1.tar.gz \
 && cd ruby-dbi-rel-0-1-1 \
 && ruby setup.rb config --with=dbi,dbd_mysql \
 && ruby setup.rb setup \
 && ruby setup.rb install
# rpmbuild
WORKDIR $BUILDROOT/
COPY files.ruby/ruby-dbi-0.1.1.spec $BUILDROOT/SPECS/
RUN tar czf $BUILDROOT/SOURCES/ruby-dbi-0.1.1.tar.gz /usr/lib/ruby/site_ruby/1.8 /usr/bin/sqlsh.rb \
 && rpmbuild -ba SPECS/ruby-dbi-0.1.1.spec
```