Jesse Cotton | San Diego, CA | | https://jessecotton.com

Application Packaging Solution Using Docker

Role: Developer
Technologies: Docker, Docker-Compose, Ruby, FPM

To support simpler application deployments I was tasked with implementing a process to package a series of Ruby on Rails applications into system packages. I can’t take all of the credit for the solution however because an associate implemented the initial FPM/Rake packaging automation. I expanded on his work however and streamlined the process.

Process:

FPM was employed to abstract the OS specific details of packaging the applications. Using FPM meant avoiding the complexity of creating a RPM specfile or Debian control file, etc.

Rake was utilized to automate the packaging process including downloading Gem dependencies and calling FPM to generate the packages. The Rake task also wrapped logic like excluding files that weren’t stored in Git and setting package dependencies and build dependencies based on simple OS specific manifests.

Docker was utilized to create the build environments needed to produce the packages. Simple Dockerfiles were compiled that installed the package build dependencies (ex: build-essential, git) and Ruby.

Docker-Compose was used to unify the process of building packages for both RedHat and Ubuntu into a single command.

Result:

$ ./scripts/build-pkgs
Building centos-66-pkg
Step 1 : FROM centos:6.6
6.6: Pulling from library/centos
90577c79babf: Pull complete
Digest: sha256:e21297742183af3e64cbd42585c1718b53c677797a77044ba13c1425c21ef06b
Status: Downloaded newer image for centos:6.6
 ---> d03626170061
Step 2 : RUN yum update -y &&   yum groupinstall -y "Development Tools" &&   yum install -y tar wget git
 ---> Running in e0f9296b2c5e
...
 ---> 30ae89569cfd
Removing intermediate container e0f9296b2c5e
Step 3 : WORKDIR /tmp
 ---> Running in 820291e10d0c
 ---> 88974ce3f3bc
Removing intermediate container 820291e10d0c
Step 4 : RUN export RUBY_INSTALL_VER=0.6.0 && export RUBY_INSTALL_CHKSUM=cebd31a5c2790f7d250b6a1185d1f2a9 &&   wget -O ruby-install-${RUBY_INSTALL_VER}.tar.gz https://github.com/postmodern/ruby-install/archive/v${RUBY_INSTALL_VER}.tar.gz &&   tar -xzvf ruby-install-${RUBY_INSTALL_VER}.tar.gz &&   echo "$RUBY_INSTALL_CHKSUM  ruby-install-${RUBY_INSTALL_VER}.tar.gz" | md5sum -c - &&   cd ruby-install-${RUBY_INSTALL_VER} &&   make install
 ---> Running in 650c227b1be4
...
 ---> c8c43c938623
Removing intermediate container 650c227b1be4
Successfully built c8c43c938623
WARNING: Image for service centos-66-pkg was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Building ubuntu-1404-pkg
Step 1 : FROM ubuntu:14.04
14.04: Pulling from library/ubuntu
16da43b30d89: Pull complete
1840843dafed: Pull complete
91246eb75b7d: Pull complete
7faa681b41d7: Pull complete
97b84c64d426: Pull complete
Digest: sha256:881befbe6f54c1e85029fe3a11554342bf765a0849600ecb8fa2f922798b4925
Status: Downloaded newer image for ubuntu:14.04
 ---> 3f755ca42730
Step 2 : RUN apt-get -y update && apt-get install -y   build-essential   wget   git
 ---> Running in ec9438668eda
...
 ---> d8ea9cd6da9e
Removing intermediate container ec9438668eda
Step 3 : WORKDIR /tmp
 ---> Running in 731574c6f90b
 ---> 6a2f07e06e4b
Removing intermediate container 731574c6f90b
Step 4 : RUN export RUBY_INSTALL_VER=0.6.0 && export RUBY_INSTALL_CHKSUM=cebd31a5c2790f7d250b6a1185d1f2a9 &&   wget -O ruby-install-${RUBY_INSTALL_VER}.tar.gz https://github.com/postmodern/ruby-install/archive/v${RUBY_INSTALL_VER}.tar.gz &&   tar -xzvf ruby-install-${RUBY_INSTALL_VER}.tar.gz &&   echo "$RUBY_INSTALL_CHKSUM  ruby-install-${RUBY_INSTALL_VER}.tar.gz" | md5sum -c - &&   cd ruby-install-${RUBY_INSTALL_VER} &&   make install
 ---> Running in 7665cde640d5
...
 ---> 5bf670ff391e
Removing intermediate container 7665cde640d5
Successfully built 5bf670ff391e
WARNING: Image for service ubuntu-1404-pkg was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating pkgbuild_centos-66-pkg_1
Creating pkgbuild_ubuntu-1404-pkg_1
Attaching to pkgbuild_centos-66-pkg_1, pkgbuild_ubuntu-1404-pkg_1
centos-66-pkg_1    | >>> Updating ruby versions ...
ubuntu-1404-pkg_1  | >>> Updating ruby versions ...
ubuntu-1404-pkg_1  | >>> Installing ruby 2.2.4 into /opt/rubies/ruby-2.2.4 ...
centos-66-pkg_1    | >>> Installing ruby 2.2.4 into /opt/rubies/ruby-2.2.4 ...
...
pkgbuild_centos-66-pkg_1 exited with code 0
pkgbuild_ubuntu-1404-pkg_1 exited with code 0
$ ls -lh
application-1.0.0-amd64.deb
application-1.0.0-amd64.rpm