Converting Ruby Gems to RPMs using FPM
In my last post I demonstrated compiling Ruby from source and building an RPM for it using FPM.
This works great and it's a major timesaver, but FPM allows you to take this one step further and even build RPMs out of Ruby Gems.
Here's how I did it:
1. Install my repository, then install Ruby plus the usual suspects for building RPM packages:
yum -y install http://rpm.chaidas.com/rpm.chaidas.com-0.1-1.x86_64.rpm
yum -y install ruby make rpm-build gcc
2. Install the FPM gem:
gem install fpm --no-ri --no-rdoc
3. Use FPM to convert the FPM gem into an RPM:
fpm -s gem -t rpm fpm
Explanation for the above:
-s gem = the source is a gem
-t rpm = the target is an RPM
fpm = the name of the gem we're converting
4. Now that the RPM is created, check what the dependencies are:
rpm -qp rubygem-fpm-1.9.2-1.noarch.rpm --requires
rubygem(json) < 2.0
rubygem(json) >= 1.7.7
rubygem(cabin) >= 0.6.0
rubygem(backports) >= 2.6.2
rubygem(arr-pm) >= 0.0.10
rubygem(arr-pm) < 0.1.0
rubygem(clamp) >= 1.0.0
rubygem(clamp) < 1.1.0
rubygem(childprocess) >= 0
rubygem(ffi) >= 0
rubygem(ruby-xz) >= 0
rubygem(pleaserun) >= 0.0.29
rubygem(pleaserun) < 0.1.0
rubygem(stud) >= 0
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(CompressedFileNames) <= 3.0.4-1
As you can see there's a bunch of them - don't worry! we can convert them too! (buhuahuaha)
5. Download all the gem dependencies (without installing them though!):
mkdir /tmp/gems
gem install --no-ri --no-rdoc --install-dir /tmp/gems fpm
6. Make RPMs out of all gems (this command is totally stolen from the awesome FPM docs):
cd /tmp/gems
7. I want some more dependencies for the fpm RPM. Namely the 'rpm-build' and 'make' packages - I'll add those and rebuild it:
fpm -d ruby-lampros -d rpm-build -d make -s gem -t rpm fpm
8. Create a local repo and copy all the RPMs in there - we'll use this for testing:
yum install createrepo -y
mkdir -pv /yumrepo
# the next command simply copies all the *.rpm files into the /yumrepo/ directory:
for i in `find /tmp/ -name "*.rpm"`; do echo $i; cp $i /yumrepo/; done
createrepo /yumrepo
9. Create a repository definition - /etc/yum.repos.d/lampros-gems.repo:
[lampros-gems-repo]
name=Lampros Gems
baseurl=file:///yumrepo
enabled=1
gpgcheck=0
10. Remove Ruby etc, so that we can test installing the RPM gems:
yum -y remove ruby\*
11. Get the list of available packages from our new repository:
yum --disablerepo=* --enablerepo=lampros-gems-repo list available
You should get output like this:
Available Packages
rubygem-arr-pm.noarch 0.0.10-1 lampros-gems-repo
rubygem-backports.noarch 3.8.0-1 lampros-gems-repo
rubygem-cabin.noarch 0.9.0-1 lampros-gems-repo
rubygem-childprocess.noarch 0.7.1-1 lampros-gems-repo
rubygem-clamp.noarch 1.0.1-1 lampros-gems-repo
rubygem-dotenv.noarch 2.2.1-1 lampros-gems-repo
rubygem-ffi.x86_64 1.9.18-1 lampros-gems-repo
rubygem-fpm.noarch 1.9.2-1 lampros-gems-repo
rubygem-insist.noarch 1.0.0-1 lampros-gems-repo
rubygem-io-like.noarch 0.3.0-1 lampros-gems-repo
rubygem-json.x86_64 1.8.6-1 lampros-gems-repo
rubygem-mustache.noarch 0.99.8-1 lampros-gems-repo
rubygem-pleaserun.noarch 0.0.30-1 lampros-gems-repo
rubygem-ruby-xz.noarch 0.2.3-1 lampros-gems-repo
rubygem-stud.noarch 0.0.23-1 lampros-gems-repo
12. Try to install FPM:
yum -y install rubygem-fpm
13. Did it work?
fpm --version
1.9.2
Yes sir!