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:
- Open up your terminal and clone it:
git clone ssh://firstname.lastname@example.org/~/git/ruby.git/
- Get inside the app you just clone, in my case it is will be
- 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
- git remote add glitter -m master http://github.com/glittergallery/GlitterGallery.git
- 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:
- git add .
- 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:
- rake assets:precompile
- 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 doesn’t support sqlite3 or mysql so you will need to go to your gemfile and replace them with
- 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:
- You will need to replace content of database.yml file with:
- 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:
- Precompile your assets and commit everthing:
- rake assets:precompile
- git add .
- 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.