Skip to content

Latest commit

 

History

History
65 lines (37 loc) · 3.86 KB

README.md

File metadata and controls

65 lines (37 loc) · 3.86 KB

Traveling Ruby Linux build system

The linux/ directory contains the build system for building Traveling Ruby binaries for Linux.

Building binaries

The build system requires Docker and Rake. To build binaries, run:

cd linux
rake

This will produce a traveling-ruby-XXXXX.tar.gz file which contains the Ruby binaries, and a traveling-ruby-gems-XXXXX directory which contains the native extensions.

How it works

Overview

The build system works by setting up Mock chroots inside a CentOS 6 Docker container, and using those Mock chroots to perform the actual compilation of the binaries.

Mock is a Fedora tool for building packages against architectures and different Fedora/Red Hat/CentOS versions. This tool downloads RPMs for the requested OS version, extracts them into a directory (thereby setting up a system root) and runs command inside a chroot jail for that directory. We use Mock to create a CentOS 6 x86 chroot and a CentOS 6 x86-64 chroot inside the Docker container, for the purpose of compiling x86 and x86-64 binaries.

The Docker image that we use is phusion/traveling-ruby-builder. See the Dockerfile in this directory for its definition. This Docker image is generated by running the setup-docker-image script.

But there is a problem with Docker: we cannot create Mock chroots within a Dockerfile. This is because Mock needs chroot() privileges, but docker build runs containers without that privilege. So we work around this fact by creating Mock chroots outside the docker build phase. This is why the Docker image doesn't contain much. It's pretty much a bare CentOS 6 system that only has Mock installed.

The runtime setup phase


The setup-runtime script creates Mock chroots inside the Docker container.

The Rakefile begins by invoking the setup-runtime script. This script:

  • Pulls the Docker image.
  • Runs Mock inside the container to create the Mock chroots.
  • Installs necessary tools (such as compilers) and libraries inside the Mock chroots.

So this script does not actually produce Traveling Ruby binaries yet.

Setting up the runtime is only done once, although you may have to re-setup the runtime if you upgrade Traveling Ruby.

The runtime is saved to the runtime directory.

The build phase


The build-ruby script uses the Mock chroots inside the Docker container to invoke the compiler, which produces out binaries.

Once the runtime is setup, the Rakefile proceeds with invoking the build-ruby script. This script runs the compiler inside the Mock chroot environments to produce binaries. The script:

  • Builds Ruby. It extracts the Ruby source tarball and runs ./configure, make and make install.
  • Builds the native extensions that Traveling Ruby supports. It runs bundle install on the Gemfile located in the shared/ directory in the Traveling Ruby repository.
  • Performs various postprocessing tasks, such as stripping debugging symbols from the binaries and running various sanity checks.

The build outputs are saved to the output directory.

The package phase

Once binaries are compiled, the Rakefile invokes the package script. This script packages files inside the output directory into various tarballs.

Why CentOS 6?

CentOS 6 was chosen as the compilation environment because its glibc version is sufficiently old that any produced binaries are compatible with nearly all Linux distributions still in use today. The binaries we generate should be compatible with any Linux distribution that was released circa 2010 and beyond. This includes:

  • Debian 6
  • Ubuntu 10.04