The Mer Wiki now uses your Mer user account and password (create account on https://bugs.merproject.org/)


Packaging/Ruby

From Mer Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "'''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 …")
 
(howto do bundler packages)
 
(5 intermediate revisions by one user not shown)
Line 3: Line 3:
 
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.
 
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 <mygemname>
 +
 
 +
When the gem is downloaded you can create .spec file with following cmd
 +
 
 +
gem2rpm-opensuse <mygemname-version>.gem > rubygem-<mygemname>.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
 +
# This is the BR for all enclosed gems
 +
BuildRequires:  rubygem-bundler git gcc-c++ openssl-devel pkgconfig
 +
Requires:      rubygem-bundler
 +
#
 +
Url:            https://wiki.merproject.org/wiki/Platform_SDK
 +
# DEVSRC=/mer/mer/devel/mer-sdk/sdk-webapp-bundle ./update-pkg.sh
 +
 +
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
 +
# SourceEnd : This line is needed to make the script in the README work
 +
 +
Summary:        Gems needed to run sdk-webapp
 +
%description
 +
 +
This package is the bundle of gems needed to run the Mer SDK webapp
 +
 +
%prep
 +
# We use the Gemfile, Gemfile,lock and rpmlintrc
 +
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 [[ ${file: -3:3} == "gem" ]]; then cp $file vendor/cache; elif [[ ${file: -3:3} == "bz2" ]]; 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
 +
 +
# Install everything we just built
 +
cp -al . %{buildroot}/usr/lib/%{name}/
 +
 +
# Don't install the rpmlintrc
 +
rm %{buildroot}/usr/lib/%{name}/$(basename %{SOURCE2})
 +
 +
# Change #!/usr/local/bin/ruby to #!/usr/bin/ruby
 +
fgrep -rl "usr/local/bin" %{buildroot} | xargs --no-run-if-empty sed -i -e 's_/usr/local/bin_/%{_bindir}_'g
 +
# Change ../../../../../BUILD to {%_libdir}/%{name}
 +
fgrep -rl "../../../../../BUILD" %{buildroot} | xargs --no-run-if-empty sed -i -e 's_../../../../../BUILD_%{_libdir}/%{name}_'g
 +
# Remove references to buildroot
 +
fgrep -rl "%{buildroot}" %{buildroot} | xargs --no-run-if-empty sed -i -e 's_%{buildroot}__'g
 +
 +
%files
 +
%defattr(-,root,root,-)
 +
%{_libdir}/%{name}/
 +
%{_bindir}
 +
 
 +
 
 +
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)
 +
 
 +
#!/bin/bash
 +
 +
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
 +
 
 +
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
 +
 
 +
 
 +
[[Category:Packaging]]

Latest revision as of 23:15, 25 October 2012

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.

[edit] Package Naming

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

[edit] 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 <mygemname>

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

gem2rpm-opensuse <mygemname-version>.gem > rubygem-<mygemname>.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.

[edit] 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
# This is the BR for all enclosed gems
BuildRequires:  rubygem-bundler git gcc-c++ openssl-devel pkgconfig
Requires:       rubygem-bundler
#
Url:            https://wiki.merproject.org/wiki/Platform_SDK
# DEVSRC=/mer/mer/devel/mer-sdk/sdk-webapp-bundle ./update-pkg.sh

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
# SourceEnd : This line is needed to make the script in the README work

Summary:        Gems needed to run sdk-webapp
%description

This package is the bundle of gems needed to run the Mer SDK webapp

%prep
# We use the Gemfile, Gemfile,lock and rpmlintrc
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 [[ ${file: -3:3} == "gem" ]]; then cp $file vendor/cache; elif [[ ${file: -3:3} == "bz2" ]]; 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

# Install everything we just built
cp -al . %{buildroot}/usr/lib/%{name}/

# Don't install the rpmlintrc
rm %{buildroot}/usr/lib/%{name}/$(basename %{SOURCE2})

# Change #!/usr/local/bin/ruby to #!/usr/bin/ruby
fgrep -rl "usr/local/bin" %{buildroot} | xargs --no-run-if-empty sed -i -e 's_/usr/local/bin_/%{_bindir}_'g
# Change ../../../../../BUILD to {%_libdir}/%{name}
fgrep -rl "../../../../../BUILD" %{buildroot} | xargs --no-run-if-empty sed -i -e 's_../../../../../BUILD_%{_libdir}/%{name}_'g
# Remove references to buildroot
fgrep -rl "%{buildroot}" %{buildroot} | xargs --no-run-if-empty sed -i -e 's_%{buildroot}__'g

%files
%defattr(-,root,root,-)
%{_libdir}/%{name}/
%{_bindir}


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)

#!/bin/bash

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

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

Personal tools