Skip to content

Deploying to Heroku

Daniel Hedlund edited this page Feb 13, 2014 · 9 revisions

Getting Started

All of the commands assume you have a Heroku account and the Heroku Toolbelt installed.

These instructions assume you want to install ActivateHub on small (free) heroku instance. If you using this project in a production capacity, it is recommended that you understand what additional services heroku offers, particularly running multiple dynos and upgrading the postgresql add-on to handle more than 10k records.

Creating a New Instance

Deploying to heroku works almost out-of-the-box, with one caveat. Even though we do not use the sqlite3 gem in production mode, we include it in our Gemfile to make it easier for developers to get started with the project. Heroku does not have the development headers needed to compile the sqlite3 gem so it fails. To work around this, we have a Gemfile.heroku file which excludes the sqlite3 gem, but their buildpack does not honor the BUNDLE_GEMFILE environment variable used to load alternative gemfiles. Until we come up with a better solution to contribute back upstream, we use a custom buildpack that replaces all instances of Gemfile with Gemfile.heroku.

# instructions assume you have the following variable set. setting this variable is shell
# specific (this example uses the bash shell).  alternatively, you can replace all instances
# of $HEROKU_APP with the name of the heroku app you want to create
export HEROKU_APP="activate-dublin"

heroku create --app $HEROKU_APP --buildpack https://github.com/activate/heroku-buildpack-ruby.git
heroku addons:add heroku-postgresql:dev --app $HEROKU_APP
heroku addons:add pgbackups:auto-month --app $HEROKU_APP

heroku config:set \
  BUNDLE_GEMFILE=Gemfile.heroku \
  RACK_ENV=production \
  RAILS_ENV=production \
  --app $HEROKU_APP

heroku labs:enable user-env-compile --app $HEROKU_APP

git clone [email protected]:activate/ActivateHub.git
cd ActivateHub
git remote add $HEROKU_APP [email protected]:$HEROKU_APP.git
git push $HEROKU_APP master:master

heroku run rake db:migrate --app $HEROKU_APP
heroku restart --app $HEROKU_APP

Configuring Your Site

All commands in this section are examples and you should change values to match your site.

Run heroku run rails console --app activate-dublin to get to a rails console:

Site.create( 
  :name   => 'Staging Ground',
  :domain => 'activate-dublin.herokuapp.com',
  :timezone => 'Pacific Time (US & Canada)',
  :locale => 'en-x-activate-hub',
)

You should now be able to access your copy of the project at http://activate-dublin.herokuapp.com/.

For access to a admin interface where you can create topics and types, visit http://activate-dublin.herokuapp.com/admin/.

Geocoding / Maps API Support

This project is currently configured to use the Google Maps API to display maps and convert addresses to lat/long coordinates. To take advantage venue maps, you will need to enable V1 and V2 of the Google Maps API and create a Google API key. Use the following instructions but also enable V2 when enabling V3 when you get to step 3: https://developers.google.com/maps/documentation/javascript/tutorial#api_key

To use the API key with your heroku account, set the GOOGLE_API_KEY heroku variable and restart:

heroku config:set GOOGLE_API_KEY=mygoogleapikey --app activate-dublin
heroku restart --app activate-dublin

Background Jobs / Re-Importing Sources

Heroku has a scheduler add-on that can be used to run maintenance tasks in the background; they charge about $0.10/hour for for time used. If you add this add-on, you can enable pulling new calendar events and updates from existing calendar sources on a nightly basis.

Schedule rake sources:import[activate-dublin.herokuapp.com,*] to run daily at 10:30 UTC (3:30AM PDT).