Aptly_cli was created to work with the Aptly Debian repository management system. It provides a command line interface that can be used on remote systems that need to interact with Aptly repositories.

The initial testing framework was based on a combination of Webmock and Vcr. Vcr allowed me to record Aptly server responses while testing Aptly_cli API interactions. A local Vagrant VirtualBox instance that ran Aptly Aptly_Vagrant provided the server responses.

Aptly_cli is plugged into Travis-CI for running tests. The Webmock framework ran well there. The builds took advantage of Ruby RVM for testing multiple versions of Ruby.

The local development environment became cumbersome. I had to record server responses periodically from the Aptly server which would update the Vcr yml files (Where HTTP responses where recorded). The test setup and cleanup was sort of pain to deal with too. Sometime segments of your Vcr results would get overwritten when you weren't expecting it. I wanted a testing suite that didn't get in my way and instead encouraged adding tests.

Now here is where Docker comes in. I noticed that Travis-CI started supporting Docker builds. Great! Since almost all of the Aptly_cli tests relied on server responses it made sense to give Docker a shot. The idea to have tests working locally with Docker and also have Travis-CI run build tests using the same Docker build.

To get rolling with Docker I first got rid of the Vcr cassette recordings which contained expected Aptly server responses. Next, I created a Dockerfile

FROM debian:jessie


RUN echo "deb http://repo.aptly.info/ squeeze main" > /etc/apt/sources.list.d/aptly.list; \
apt-key adv --keyserver keys.gnupg.net --recv-keys 2A194991; \
apt-get update; \
apt-get install aptly curl xz-utils bzip2 gnupg wget graphviz -y --force-yes; \
wget --quiet http://mirror.as24220.net/pub/ubuntu-archive/pool/main/z/zeitgeist/zeitgeist_0.9.0-1_all.deb -O /tmp/zeitgeist_0.9.0-1_all.deb; \
wget --quiet http://mirror.as24220.net/pub/ubuntu-archive/pool/main/z/zsh/zsh_5.1.1-1ubuntu1_i386.deb -O /tmp/zsh_5.1.1-1ubuntu1_i386.deb

ADD ./test/fixtures/aptly.conf /etc/aptly.conf

RUN aptly repo create testrepo
RUN aptly repo create testrepo20
RUN aptly repo add testrepo /tmp/zeitgeist_0.9.0-1_all.deb
RUN aptly repo add testrepo20 /tmp/zsh_5.1.1-1ubuntu1_i386.deb

CMD /usr/bin/aptly api serve

This built a Docker container that installed the latest Aptly server, sets up a basic configuration and places a couple test packages into it.

Now with a working Aptly Docker container my next step was to add some Rake Task to my Rakefile to help control container image creation, starting and stopping.

desc "Docker build image"
task :docker_build do
  sh %{docker build -t sepulworld/aptly_api .}

desc "List Docker Aptly running containers"
task :docker_list_aptly do
  sh %{docker ps --filter ancestor='sepulworld/aptly_api' --format="{{.ID}}"}

desc "Stop running Aptly Docker containers"
task :docker_stop do
  sh %{docker stop $(docker ps --filter ancestor='sepulworld/aptly_api' --format="{{.ID}}")}

desc "Start Aptly Docker container on port 8082"
task :docker_run do
  sh %{docker run -d -p 8082:8080 sepulworld/aptly_api /bin/sh -c "aptly api serve"}

desc "Show running Aptly process Docker stdout logs"
task :docker_show_logs do
  sh %{docker logs $(docker ps --filter ancestor='sepulworld/aptly_api' --format="{{.ID}}")}

desc "Restart Aptly docker container"
task :docker_restart => [:docker_stop, :docker_run] do
  puts "Restarting docker Aptly container"

At this point I started refactoring some of my Minitests. Now that I wasn't needing to setup mocks and record responses with Vcr adding new tests became a faster process. After I ensured all of my previous tests and new ones were running locally, I needed to add some changes to .travis-ci.yml.

sudo: required
  - docker

- rake docker_build
- rake docker_run
- docker ps -a

- bundle exec rake test

- rake docker_show_logs

This takes advantage of the Rake commands I noted above, and activated the Docker testing infrastructure in Travis-CI.

Travis-CI ran the build on the new branch and found all tests past. At this point I have a new testing suite using Docker working on Travis-CI! The fain step was to remove the Gemfile dependencies for Webmock and Vcr and merge this branch into master.

Overall, this was a very fruitful process that put Aptly_cli into a better development state. I have already fixed about a dozen bugs thanks to this faster, easier to use framework driven by Docker. I went from 52% test coverage to 92% (Percentage based on Coveralls) thanks to Docker.