Buildpacks, mirrors and Deployments!

My past one week has mostly been wasted on deployments. Sometimes I just couldn’t find the right documentation, when at others I was just too frustrated to even try. I am going to write the steps of deployment both on heroku and openshift in this one, I hope someone will find it useful. First Openshift!

  • You will need an account, so go ahead and sign up if you haven’t already. I will be using GG as example app to deploy.
  • Pick ruby on rails 4, it uses ruby 2 and mysql 5.5 as default, just name your app and you are good to go.
  • Get source code url of the app you just made. It will look something like this:

ssh://xxxxxxxxxxxxxxxxxxxxxxx@ruby-glitterfollowers.rhcloud.com/~/git/ruby.git/

  •  Open up your terminal and clone it:

git clone ssh://xxxxxxxxxxxxxxxxxxxxxxx@ruby-glitterfollowers.rhcloud.com/~/git/ruby.git/

  • Get inside the app you just clone, in my case it is will be

cd ruby

  • You would want to remove following files:

git rm public/index.html app/views/layouts/application.html.erb -r app/assets/

  • Now you can pull the repository you want to deploy
  1. git remote add glitter -m master http://github.com/glittergallery/GlitterGallery.git
  2. git pull -s recursive -X theirs glitter master
  • It is most likely that you will be safe if you ignore the merge conflicts, so just go ahead and commit:
  1. git add .
  2. git commit -m “merge glittergallery with ruby example app”
  • Change the mirror from ‘rubygems.org’ in your gemflie to ‘mirror.ops.rhcloud.com/mirror/ruby/’, precompile your assets and commit them as well:
  1. rake assets:precompile
  2. git commit -am “change mirror and precompile assets”
  •  I hope you have set your rhc by now. If not, you can find how to do it here. You will be better off if you don’t install gems of test and development:

rhc env set BUNDLE_WITHOUT=”development test” -a ruby

  • Thats it! You can push your code to openshift now:

git push origin master

Moving on to Heroku. Just sign up and jump into terminal. Make sure you are inside the directory to app you are trying to deploy.

  • Install heroku toolbelt and login from your terminal:

heroku login

  • Heroku doesn’t support sqlite3 or mysql so you will need to go to your gemfile and replace them with
gem 'pg'
  • While you are at it, why don’t you add rails_12factor as well. It is just something they use to integrate rails with heroku
gem 'rails_12factor', group: :production 
  • Install the gems you just added:

 bundle install

  •  You will need to replace content of database.yml file with:

default: &default

adapter: postgresql
encoding: unicode
pool: 5
port: 5432

development:

<<: *default

username:
host: localhost
password:
database: gg_development

production:
<<: *default

  • Add Postgres addon to your app

heroku addons | grep POSTGRES

  • Go to heorku and check your databases, a new one with your app name must be created. Copy host, database, user and password from that to your database.yml file under production.
  • We use rugged and it has cmake as dependency. You will need buildpack of cmake and ruby:
  1. heroku buildpacks:set https://github.com/rcaught/heroku-buildpack-cmake
  2. heroku buildpacks:add https://github.com/heroku/heroku-buildpack-ruby
  • Precompile your assets and commit everthing:
  1. rake assets:precompile
  2. git add .
  3. git commit -m “add gems for heroku and precompile assets”
  • Now you can push your code to heroku

git push heroku master

There are a few gotcha with heroku. We use delayed jobs, for which we need worker but heroku provides limited hours of free worker. Start the working only when you have to. Besides that, public directory will be reset every time you push to heroku so anything you are saving there will be lost. Same will happen each time the application shuts down and restarts after being inactive for x minutes.

Talking about things added on glittergallery, I fixed a bug I had in tagging. Tags were not being added in context of project. I just need to define an association between tags and projects. I have started my work on exploration page. My mentor suggested that we should add rating system to the projects. I found ratyrate, but it was really buggy. I tried to fix it and thus I made my first contribution to any ruby gem. I am really hoping I will be done with this as soon as possible. We are getting serious about adding push and pull features to deployments.

Advertisements
Buildpacks, mirrors and Deployments!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s