Installing & Using the Travis CLI with Nanobox

Travis CI provides a command line client, Travis CLI, that adds really nice-to-use tools and functionality to your Travis CI workflow. The CLI is distributed as a Ruby gem, so it needs Ruby installed. I also recommend using Bundler to automatically install the Travis CLI in each new local build.

When working locally, Nanobox builds your app inside an isolated virtual environment with its own runtime and binaries. The runtime is determined by the engine specified in your boxfile.yml. While you can install Travis CI on your host machine, you wouldn't be able to use it inside the Nanobox container.

Installing it within the context of your Nanobox app keeps your host machine clean of any unnecessary binaries and ships the Travis CLI with your code.

Add/Update Your Gemfile

Bundler downloads and installs Ruby gems defined in the Gemfile. If there isn't already one in your project, create one in your project root.

Add the following to your Gemfile:

source "https://rubygems.org"

gem "travis"  

Using the Travis CLI with the Ruby Engine

Ruby and Bundler are included by default in the ruby engine. With travis added to your Gemfile, it will be automatically installed when you start your local dev environment. From the root of your project:

# start your local dev environment and drop into a console
nanobox run

# use the travis cli
travis help  

Using the Travis CLI with All Other Engines

If using any engine other than ruby, you can include Ruby and Bundler packages in your project using the run.config > extra_packages and run.config > dev_packages nodes of your boxfile.yml.

Since you'll likely only use the Travis CLI when developing locally, you can add them as dev_packages. This will keep Ruby and Bundler out of your production runtime. The boxfile.yml configuration below will do the following:

  • Include Ruby and Bundler packages in your dev environment.
  • Cache loaded gems so they're reused on subsequent builds.
  • Add binaries installed by Bundler to the system $PATH.
  • Run Bundler in the your app's runtime build process.
run.config:  
  #...
  dev_packages:
    - ruby-2.4.0nb1
    - ruby24-bundler
  cache_dirs:
    - vendor/bundle
    - .bundle
  extra_path_dirs:
    - vendor/bundle/.bin 
  extra_steps:
    - bundle install

If you need a different version of Ruby, specific packages can be found and pulled from the Nanobox pkgsrc.

With these boxfile.yml options in place and travis added to your Gemfile, run the following from the root of your project:

# start your local dev environment and drop into a console
nanobox run

# use the travis cli
travis help  

Scott Anderson

Designer, code-dabbler, writer, foodie, husband, and father. Core Team Member at Nanobox.

Subscribe to Nanobox

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!