Skip to content
Regis Millet edited this page Nov 4, 2013 · 5 revisions

Welcome to the canvabadges wiki!

Running on something other than Heroku

Made by @Kulgar (copied/pasted from a mail):

Hi!

Actually you did help me! :) As it's true that we have to defined SESSION_KEY/DATABASE_URL at the server level on Heroku, I've made some searches and found a way to define those thanks to passenger. I'll explain how for others!

The idea is to set up a file exporting those variables and to make passenger load this file on startup. Actually it is quite simple! Here is a step by step:

  • Create a file named "set_environment" (or whatever) in the root folder of your project and define there your variables like so (for canvabadges): export DATABASE_URL="postgres://username:password@hostname/database_name" export SESSION_KEY="your_secret_chain"

And save the file!

  • Next create one other file, that would be conventionally named "ruby_wrapper". This little wrapper will only load the "set_environment" file + execute ruby: (I recommend using the "which ruby" command from the canvabadges project root to know the path to your ruby binary).
#!/bin/sh
source /path/to/project/set_environment
exec "/path/to/your/ruby"

Once it's done, don't forget to remove those two files from your versioning manager (like git) as they contain some sensitive information. Then you have to add the "execute" right to the ruby_wrapper file. (sudo chmod u+x ruby_wrapper).

  • The last step is to tell passenger to use this ruby wrapper when it launches the server for this application. I've set it that in my VirtualHost, like so:
SetEnv RACK_ENV production
PassengerRuby /path/to/your/project/ruby_wrapper

Then on next restart passenger should load this file and everything should be set up and work as expected!

Don't forget to create the postgres database that you put in your DATABASE_URL. Here is a starting guide on DataMapper to help you configure the application according to your needs: http://datamapper.org/getting-started.html. You should know that canvabadges is already configured to work perfectly with postgresql (as Heroku uses postgres so does the application ^^).

One last thing, once you've created your database (in command lines, for instance), you have to initialize it. To do so, you have to launch the irb console from the root folder of the project. To make my life easier, I've created a third file, which I named "ruby_console" and I've put those lines in it:

#!/bin/sh
export RACK_ENV=production
source path/to/your/project/set_environment
exec "/path/to/your/irb"

Then I added the execution right on it, and I now just have to launch it ./ruby_console to have an irb console with the expected environment variables. (Again do not include it in git). Then the:

> require './canvabadges.rb' 

Command should go through without any problems. Then you just have to launch:

> DataMapper.auto_migrate!

To initialize your database. (All the tables will be created with correct columns). Be warned, auto_migrate will wipe out existing data. Use "auto_upgrade!" if you already have some datas in your badge database...

And that's it!

I hope this little how to will help others!

Clone this wiki locally