Skip to content
This repository was archived by the owner on Feb 25, 2019. It is now read-only.

Setup toolchain with rails application

Matthias Winzeler edited this page Apr 1, 2014 · 2 revisions

Github setup & clone

First, we need a github account. Sign up there and create a new repository.

Then, clone the repository on your local workstation (change url to your repository):

git clone https://github.com/MatthiasWinzeler/bfh-os2-toolchain.git
cd bfh-os2-toolchain/

Install Ruby & rails

We use rvm to manage the used rubies, so we install it first:

\curl -sSL https://get.rvm.io | bash -s stable

Now we can install ruby 2:

rvm install ruby-2.0```

At least, we install the latest **rails** release as a gem:

gem install rails rails -v


### Setup rails project
Now we create a simple - almost empty - rails app:

`rails new .`

Setup the database:

`rake db:migrate`

Create some dummy controller:

`rails generate controller welcome index`

Further, this has created our first test. We run the test using rake:

`rake`

All tests should run fine. We can fire up our rails server and have a look at the empty app at http://localhost:3000 :

`rails server`

Since we have now a working project, let's push these changes to github:

git add . # add all all our created files to the changeset, git commit # commit them.. git push origin master # ... and push them to github


these changes should now appear on our github repository.

### Add continous integration from travis
(according to http://docs.travis-ci.com/user/getting-started/

Sign in with github account on travis-ci.org, sync repo, turn switch

On our local workstation, we add a file .travis.yml in the root of our rails application, containing the following:

language: ruby rvm:

  • 2.0.0

We push this to github, and then travis bot should now pick up this project to build:

git add .travis.yml git commit git push origin master


Some minutes later, a new build should appear in Travis CI web interface and build successfully (it automatically runs `rake` with our single test, as we did before)

### Add deployment to heroku 

First, sign up on heroku, create a new rails application (it's free) and add the postgresql as database add-on.

According to http://blog.travis-ci.com/2013-07-09-introducing-continuous-deployment-to-heroku/ we should setup the travis-heroku integration using the command line client (since our repository on github is public, we do not want to add our secret heroku API token there).

`gem install travis -v 1.6.8 --no-rdoc --no-ri`

Now, we can setup heroku as deployment target to .travis.yml:
`travis setup heroku`

> Open question: where does this the heroku stuff take from (only github acc is needed, no heroku api key? maybe from already installed heroku toolbelt?)

Our .travis.yml should now look like this

api_key: secure: bmn40znJz0A7YRl2F43H/KcARRkSlJ5DcsNHXXm7Mim0XHohHisjRdXUlOSQ5mF1cNPf1Lu+5ri/6KzV9Q1VejL9Gd8zGlCd7cDWuUVqNIlDseDYJAQODVozt8+ok1rP93a8Xfs5PFmzQbXVU3EBDUbUTi3BZDxMl831OuZOgAU= app: bfh-os2-toolchain on: repo: MatthiasWinzeler/bfh-os2-toolchain


Since heroku has some requirements for our vanilla rails app to run, we must respect those heroku-specifities:

Gemfile:

...

Use sqlite3 as the database for Active Record (dev & test)

gem 'sqlite3', group: [:development, :test]

use postgres (heroku) on prod

gem 'pg', group: :production gem 'rails_12factor', group: :production ... ruby '2.0.0'


Install the newly specified packages:

`bundle install`

Because we use postgresql as our database on heroku, specifiy pgsql for our prod db:

config/database.yml

... production: adapter: postgresql pool: 5 timeout: 5000


After travis deploys, he should migrate our database to the latest schema:

.travis.yml

... run: "rake db:migrate"


At last, commit & push all these changes:

git commit Gemfile* config/database.yml .travis.yml git push origin master


Finished! A new build should be started by the travis bot which now deploys it straight to our heroku app!
(Further commits to the master branch will also be)

Clone this wiki locally