Shippable CI tips

______

by Matt

A couple of tips for getting Shippable working with your Ruby on Rails Heroku-hosted project.

Shippable is a fast new continuous integration / continuous deployment service that, in my experience, is also one of the easiest to use. I installed it in my latest project a few days ago and thought I'd share a couple of tips. My project is a Ruby on Rails (Rails3) app hosted on Heroku using GitHub revision control. This is probably a similar setup to many, if not most, potential Shippable users, so I hope my experience will be helpful. I only hit a couple of snags that may hang you up as well.

1) PostgreSQL database setup 2) secret_token handling

The first problem I had was the database setup. The first time I ran Shippable, I got this error:

psql: FATAL: Peer authentication failed for user "matt"

Seems "matt" can't access the database. Turns out he doesn't need to. Here is how I got PostgreSQL working with Shippable (with thanks to the TravisCI docs - Shippable shares much in common with Travis).

First, create a new file called database.shippable.yml and place it in your config directory. Copy everything from your database.yml file to the new file, but make sure the username is Postgres and the password is blank (that's the stock username/password for PostgreSQL and all we need for testing). The file should look something like this now:

config/database.shippable.yml:

development:
  adapter: postgresql
  encoding: unicode
  database: appname_development
  pool: 5
  username: postgres
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: appname_test
  pool: 5
  username: postgres
  password:
  min_messages: warning

production:
  adapter: postgresql
  encoding: unicode
  database: appname_production
  pool: 5
  username: yourname
  password:

Great. Now we're ready to make sure Shippable can use that information, so let's open up your shippable.yml file in your root directory. Make sure you have the following line in the 'before_script' section:

shippable.yml:

before_script:
  - cp config/database.shippable.yml config/database.yml

That will copy over the Shippable database file into the original database file. I like having the separate file so I always know where the code came from and why it was needed. Now our database is almost ready to go, but we need to make sure the database is going to be created and ready to run your tests. And once the database is created, we also need to make sure every migration is run, so our shippable.yml file's 'before_script' section will end up looking like this:

shippable.yml:

before_script:
  - cp config/database.shippable.yml config/database.yml
  - psql -c 'create database acroparty_test;' -U postgres
  - rake db:migrate

There we go, the PostgreSQL problem should now be solved.

Now, the second problem I had was figuring out what to do with the secret_token of my project. I had used Figaro to move my secret_token out of the public eye, but that broke things for Shippable. The error I got when running my project through Shippable was:

A secret is required to generate an integrity hash for cookie session data. Use config.secret_token = "some secret phrase of at least 30 characters"in config/initializers/secret_token.rb

Shippable didn't have access to that environment variable, so things came to a screeching halt. I tried for a while to find a way to pass that secret_token to Shippable (Travis has a gem which can hide that variable), but in the end realized it didn't matter what the token was since it was just needed for the tests. So a quick bit of code in the secret_token.rb file fixes this problem:

config/initializers/secret_token.rb:

Yourapp::Application.config.secret_token = if Rails.env.test?
  ('x' * 30)
else
  ENV['SECRET_TOKEN']
end

Now when in the test environment, the secret_token is a bunch of x's. Problem solved!

I hope these two tips can help you get Shippable up and running in your Rails project. The two big strengths for Shippable are its speed (my last run lasted a whopping 39 seconds) and its ease of use. Allowing write access to your project is always a little scary, but in the end I think it saves some headaches and is worth it.

I'll be using Shippable to deploy to Heroku in the coming weeks and if anything comes up there I'll be sure to let you know.

Shippable CI tips

______

by Matt

A couple of tips for getting Shippable working with your Ruby on Rails Heroku-hosted project.

Shippable is a fast new continuous integration / continuous deployment service that, in my experience, is also one of the easiest to use. I installed it in my latest project a few days ago and thought I'd share a couple of tips. My project is a Ruby on Rails (Rails3) app hosted on Heroku using GitHub revision control. This is probably a similar setup to many, if not most, potential Shippable users, so I hope my experience will be helpful. I only hit a couple of snags that may hang you up as well.

1) PostgreSQL database setup 2) secret_token handling

The first problem I had was the database setup. The first time I ran Shippable, I got this error:

psql: FATAL: Peer authentication failed for user "matt"

Seems "matt" can't access the database. Turns out he doesn't need to. Here is how I got PostgreSQL working with Shippable (with thanks to the TravisCI docs - Shippable shares much in common with Travis).

First, create a new file called database.shippable.yml and place it in your config directory. Copy everything from your database.yml file to the new file, but make sure the username is Postgres and the password is blank (that's the stock username/password for PostgreSQL and all we need for testing). The file should look something like this now:

config/database.shippable.yml:

development:
  adapter: postgresql
  encoding: unicode
  database: appname_development
  pool: 5
  username: postgres
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: appname_test
  pool: 5
  username: postgres
  password:
  min_messages: warning

production:
  adapter: postgresql
  encoding: unicode
  database: appname_production
  pool: 5
  username: yourname
  password:

Great. Now we're ready to make sure Shippable can use that information, so let's open up your shippable.yml file in your root directory. Make sure you have the following line in the 'before_script' section:

shippable.yml:

before_script:
  - cp config/database.shippable.yml config/database.yml

That will copy over the Shippable database file into the original database file. I like having the separate file so I always know where the code came from and why it was needed. Now our database is almost ready to go, but we need to make sure the database is going to be created and ready to run your tests. And once the database is created, we also need to make sure every migration is run, so our shippable.yml file's 'before_script' section will end up looking like this:

shippable.yml:

before_script:
  - cp config/database.shippable.yml config/database.yml
  - psql -c 'create database acroparty_test;' -U postgres
  - rake db:migrate

There we go, the PostgreSQL problem should now be solved.

Now, the second problem I had was figuring out what to do with the secret_token of my project. I had used Figaro to move my secret_token out of the public eye, but that broke things for Shippable. The error I got when running my project through Shippable was:

A secret is required to generate an integrity hash for cookie session data. Use config.secret_token = "some secret phrase of at least 30 characters"in config/initializers/secret_token.rb

Shippable didn't have access to that environment variable, so things came to a screeching halt. I tried for a while to find a way to pass that secret_token to Shippable (Travis has a gem which can hide that variable), but in the end realized it didn't matter what the token was since it was just needed for the tests. So a quick bit of code in the secret_token.rb file fixes this problem:

config/initializers/secret_token.rb:

Yourapp::Application.config.secret_token = if Rails.env.test?
  ('x' * 30)
else
  ENV['SECRET_TOKEN']
end

Now when in the test environment, the secret_token is a bunch of x's. Problem solved!

I hope these two tips can help you get Shippable up and running in your Rails project. The two big strengths for Shippable are its speed (my last run lasted a whopping 39 seconds) and its ease of use. Allowing write access to your project is always a little scary, but in the end I think it saves some headaches and is worth it.

I'll be using Shippable to deploy to Heroku in the coming weeks and if anything comes up there I'll be sure to let you know.


Last posts

___

Shthumbnail

Shippable CI tips

A couple of tips for getting Shippable working with your Ruby on Rails Heroku-hosted project.

Yoda

has_many :through Tutorial

A step-by-step tutorial on how to make a has_many :through association in Ruby on Rails.

Billthecatthumb

Minitest Text-to-speech (pt. 1)

Listen to your tests. Literally! Getting text-to-speech in your MiniTest.


Scroll top