Packaging/Ruby

Draft

Ruby is used mainly for Testing and Tools in Mer and thus it is going to Mer:Tools project in community OBS. As ruby consists of numerous different gems, a packages that contain ruby libraries or applications, there is need for consistent policy how we should package them.

Package Naming
ruby gems packages should hae follow prefix in package names: rubygem-

Packaging with gem2rpm
First start by installing Mer SDK. After that is done login to the SDK and install rubygem-gem2rpm

sudo zypper install rubygem-gem2rpm

After that is done you need to fetch the gem you want to package.

gem fetch

When the gem is downloaded you can create .spec file with following cmd

gem2rpm-opensuse .gem > rubygem- .spec

After the .spec file is created next thing is to check if there are any hacks needed that needs to be preserved.

When the possible modifications are done it is time to add files, add new entry to .changes file and upload the new packaging.

Packaging with bundler
Some ruby applications have a significant number of gems. Rather than package them individually you can use bundler and create a single package that installs all the gems to a dedicated location.

To develop and prepare this package you need a suitable SDK with bundler 1.2 installed

Copy the Gemfile and .lock to a development directory (later this will be called DEVSRC) and run

bundle install --path=vendor/bundle

You may have local git repos checked out from github etc so to use those see the comments in the Gemfile. You need something like: bundle config local.ruote-amqp /maemo/devel/BOSS/src/ruby-ruote-amqp for each local git repo you're working with

In the DEVSRC ensure all commits are up-to-date and freeze using: bundle pack --all

Then cd to the osc project and create a spec-file like this:

Name:          sdk-webapp-bundle Summary:       Bundle of gems used by sdk-webapp Version:       0.0.1 Release:       1 # Group:         Development/Languages/Ruby License:       GPLv2+ or Ruby (see gems) # BuildRequires: rubygems_with_buildroot_patch %rubygems_requires BuildRequires: rubygem-bundler git gcc-c++ openssl-devel pkgconfig Requires:      rubygem-bundler # Url:           https://wiki.merproject.org/wiki/Platform_SDK Source0: Gemfile Source1: Gemfile.lock Source2: sdk-webapp-bundle.rpmlintrc Source3: haml-3.1.7.gem Source4: rack-1.4.1.gem Source5: rack-protection-1.2.0.gem Source6: sass-3.2.1.gem Source7: sinatra-1.3.3.gem Source8: tilt-1.3.3.gem Summary:       Gems needed to run sdk-webapp %description This package is the bundle of gems needed to run the Mer SDK webapp %prep cp %{SOURCE0}. cp %{SOURCE1}. cp %{SOURCE2}. mkdir -p vendor/cache; for file in %{lua: for i, p in ipairs(sources) do print(p.." ") end}; do if ; then cp $file vendor/cache; elif ; then tar xf $file; fi; done %build %install mkdir -p %{buildroot}/%{_libdir}/%{name} bundle install --local --standalone --deployment --binstubs=%{buildroot}/%{_bindir}/ --no-cache --shebang=%{_bindir}/ruby find. -name .gitignore -print0 | xargs --no-run-if-empty -0 rm cp -al. %{buildroot}/usr/lib/%{name}/ rm %{buildroot}/usr/lib/%{name}/$(basename %{SOURCE2}) fgrep -rl "usr/local/bin" %{buildroot} | xargs --no-run-if-empty sed -i -e 's_/usr/local/bin_/%{_bindir}_'g fgrep -rl "../../../../../BUILD" %{buildroot} | xargs --no-run-if-empty sed -i -e 's_../../../../../BUILD_%{_libdir}/%{name}_'g fgrep -rl "%{buildroot}" %{buildroot} | xargs --no-run-if-empty sed -i -e 's_%{buildroot}__'g %files %defattr(-,root,root,-) %{_libdir}/%{name}/ %{_bindir}
 * 1) This is the BR for all enclosed gems
 * 1) DEVSRC=/mer/mer/devel/mer-sdk/sdk-webapp-bundle ./update-pkg.sh
 * 1) SourceEnd : This line is needed to make the script in the README work
 * 1) We use the Gemfile, Gemfile,lock and rpmlintrc
 * 1) Install everything we just built
 * 1) Don't install the rpmlintrc
 * 1) Change #!/usr/local/bin/ruby to #!/usr/bin/ruby
 * 1) Change ../../../../../BUILD to {%_libdir}/%{name}
 * 1) Remove references to buildroot

Set DEVSRC to the dir where development takes place.

This script updates the .spec with any gems and tarballs (it should be added to the rubygem-bundle but include it in the packaging for now)

rm -f *gem *tar.bz2 cp $DEVSRC/Gemfile. cp $DEVSRC/Gemfile.lock. cp $DEVSRC/vendor/cache/*gem. > Source.new c=3 for src in $(cd $DEVSRC; find vendor/cache/ -mindepth 1 -maxdepth 1 -type d); do    tar cfj $(basename $src).tar.bz2 -C $DEVSRC $src; echo Source$((c++)): $(basename $src).tar.bz2 >> Source.new done for g in *gem; do echo Source$((c++)): $(basename $g) >> Source.new ; done; sed -i '/^Source2:/,/# SourceEnd/ {//!d}; /^Source2:/r Source.new' *.spec rm Source.new
 * 1) !/bin/bash

There's a lua macro to recreate the bundle cache ready for building.

Update the changelog and version and run osc ar

Then osc ci