grails (11) vaadin (11) meteor (6) elasticsearch (3) java (2) centos (1) cloudbees (1) google analytics (1) gradle (1) heroku (1) javascript (1) jdbc (1) jug (1) logback (1) logging (1) mac os (1) mongodb (1) mongolab (1) mysql (1) twitter (1) ubuntu (1)

Sunday, May 26, 2013

How to deploy Meteor on Heroku with external MongoDB

The case is following, you have made a Meteor application and you want to deploy it on heroku.com. Also, you want to use external MongoDB database provided by mongolab.com.
  1. Register at https://id.heroku.com/login 
  2. Install Heroku Toolbelt from https://toolbelt.heroku.com
  3. Register at https://mongolab.com/signup and create new MongoDB database (they give 500MB for free)
  4. Open the root folder of you Meteor project in console (you need a Git repository in order to deploy applications to Heroku, just set up one or use the one provided by Heroku, it becomes accesible after you create new application)
  5. Login to the Heroku from the command line: $ heroku login
  6. Create new Heroku application: 
    $ heroku create <appname> --stack cedar --buildpack https://github.com/oortcloud/heroku-buildpack-meteorite
  7. Setup other than default MongoDB for your Meteor application (you can get all the details for constructing the MONGO_URL from yours Mongolab account): 
    $ heroku config:set MONGO_URL=mongodb://<username>:<password>@ds027308.mongolab.com:27308/<dbname>
  8. Set the root URL
    $ heroku config:set ROOT_URL=http://<appname>.herokuapp.com
  9. Or this, in case you have got a domain
    heroku config:add ROOT_URL=http://yourdomain.com
  10. Add the Heroku Git repository as another remote to your git repository and push the code to that remote. The application will be automatically deployed and becomes accesible on <appname>.herokuapp.com 
    $ git remote add heroku git@heroku.com:<appname>.git
    $ git push heroku master
When you make changes to your code, just run git push heroku master again and all the commit from your origin/master will be released.

In case you want to see the response times for this setup, you can try it out on http://failtracker.com or http://templhub.com 

17 comments:

  1. thanks for sharing these instructions!

    ReplyDelete
  2. I tried this with the default leaderboard meteor example app and while the deployment went successfully and the isServer code was run successfully, the clientside is not getting the data from the mongo instance.

    Any idea why?
    Here is what I get on the app: http://qawsedrf.herokuapp.com/ ... The MongoHQ shows that there are 5 documents in the db though :(

    ReplyDelete
  3. Navin Pai, try to connect with your MONGO_URL from some client (to make sure your connection string is fine).

    Do you see anything interesting when you run: heroku logs ?

    What is the output when you run: heroku config ?

    ReplyDelete
  4. got it's after deploy

    2013-07-28T00:39:03+00:00 heroku[slug-compiler]: Slug compilation finished
    2013-07-28T00:39:04.771109+00:00 heroku[web.1]: Starting process with command `node bike_alarm.js`
    2013-07-28T00:39:05.493068+00:00 app[web.1]: bash: node: command not found
    2013-07-28T00:39:06.660391+00:00 heroku[web.1]: Process exited with status 127
    2013-07-28T00:39:06.677989+00:00 heroku[web.1]: State changed from starting to crashed
    2013-07-28T00:39:06.677989+00:00 heroku[web.1]: State changed from crashed to starting
    2013-07-28T00:39:09.018743+00:00 heroku[web.1]: Starting process with command `node bike_alarm.js`
    2013-07-28T00:39:09.835502+00:00 app[web.1]: bash: node: command not found
    2013-07-28T00:39:11.238165+00:00 heroku[web.1]: Process exited with status 127
    2013-07-28T00:39:11.253697+00:00 heroku[web.1]: State changed from starting to crashed
    2013-07-28T00:39:19.128339+00:00 heroku[web.1]: Error R99 (Platform error) -> Failed to launch the dyno within 10 seconds
    2013-07-28T00:39:19.128559+00:00 heroku[web.1]: Stopping process with SIGKILL


    any ideas?

    thanks!

    ReplyDelete
  5. Yes, it seems you have wrong configuration. Can you show what is the output when you run: heroku config (remove your database URL string... the rest can remain)

    ReplyDelete
    Replies
    1. I would guess, BUILDPACK_URL is not set properly. So you can try to run:
      heroku config:set BUILDPACK_URL=https://github.com/ondrej-kvasnovsky/heroku-buildpack-meteor.git

      Delete
  6. I get this error on Meteor 0.6.5.1 while deploying:

    Error: The package named jquery-ui does not exist.

    ReplyDelete
    Replies
    1. I've got the same error when deploying to Heroku, Meteor 0.6.6.3

      Error: The package name query-ui does not exist

      Anybody has a suggestion?

      Did you solve it Graeme?

      Delete
  7. Thanks for sharing this. My Meteor 0.7 was crashing with "Error: a route URL prefix must begin with a slash" which was easily solved by adding "http://" to my ROOT_URL (see https://github.com/meteor/meteor/issues/1404). I also modified the buildpack and dropped the mongohq:sandbox add-on (see https://github.com/ze-phyr-us/heroku-buildpack-meteorite) which is not needed when you use MongoLab.

    ReplyDelete
    Replies
    1. I have not updated to 0.7, so thanks for sharing! After I update to 0.7 I will also update the tutorial.

      Delete
  8. hi ! do i need to run meteor bundle before pushing to heroku? or will the buildpack take care of bundling the app?
    thank you!

    ReplyDelete
  9. 'git push heroku master' is all you need to do in order to deploy a new version. it will be bundled on the heroku server for you.

    ReplyDelete
  10. and this buildpackage works with meteor 0.8.0 too, right?
    thank you!

    ReplyDelete
    Replies
    1. I have not tested it with 0.8.0 version... so I do not know.

      Delete
  11. Thanks for sharing this. I just got Meteor working in Heroku. I was pulling my hair prior, thinking that it was straightforward.

    ReplyDelete
  12. Here are instructions for hosting Meteor 0.8.2 on Heroku, which can be challenging the first time around: http://stackoverflow.com/a/24706472/111948

    ReplyDelete