Skip to content

Instantly share code, notes, and snippets.

@Pushplaybang
Last active July 29, 2019 13:38
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pushplaybang/4a1a81e1288f5a1fb8887250fac19049 to your computer and use it in GitHub Desktop.
Save Pushplaybang/4a1a81e1288f5a1fb8887250fac19049 to your computer and use it in GitHub Desktop.
no frills instructions for getting meteor up on a free heroku and mongolab instance, no credit card required.

Prerequisites

You're going to need to create accounts at both Heroku and mlab, get the heroku toolbelt, create a database and get the full db url with the credentials.

  1. Have a meteor project you want to deploy setup on GIT
    • if your not yet on git, you'll need to get up to speed before proceeding with this, of course you should be on git, versioning all your work, and luckily getting started is pretty easy. You'll also need a github account to follow this tutorial.
  2. Setup a Heroku Account here
  3. Setup a mongo lab account
  4. Install the Heroku tool belt
  5. create a new db on mlab
  6. create a new user for that db
  7. get the full url for the db and replace the <dbuser> and <dbpassword> with the username and password you just created. it'll look something like this:
 mongodb://your-db-user-name:your-db-password@ds017231.mlab.com:17231/db-name

Setup your app for deployment

Now in a fresh terminal, we'll need to do some basic setup using the heroku toolbelt we downloaded and installed earlier.

Firstly, we'll create the app on heroku, by running this command in your project root folder.

heroku create your-app-name

this will print out a url for your app, as well as add a new git remote, you can verify this by running git remote.

Next we'll need to set some environmental variables for meteor. We'll need to run both of the following:

The ROOT_URL var that lets meteor know what its base root url is, you will need to use the one printed by the heroku create command above.

heroku config:set ROOT_URL=your-heroku-url

Then we'll need to set the MONGO_URL so that meteor can connect with the mongo database instance we created on mlab.

heroku config:set MONGO_URL=your-mlab-db-uri

Lastly, if you're using the settings.json file in your app, you'll need to do the following:

heroku config:add METEOR_SETTINGS="$(cat settings.json)"

Now, to actually build our meteor project we're going to use a community buildpack to build our meteor project on heroku.

Setting up the build back.

Heroku buildpacks are a structured set of shell scripts for building different environments on heroku. These handle building the project, and defining the environment it needs to run in. There are many for meteor out there, but we're going to use a variation of one of the most popular ones.

The reason we're going to use a variation is that the original calls for the mlab extension in heroku, which requires credit card verification in your account. Avoiding this is simple, and it only really a conveninece that actually adds an additional layer of complexity.

First, we'll fork the buildpack we mentioned previously. Go to the horse buildpack url and fork the repo on github. Pull it down, and open it up in your favourite editor. Navigate to bin/release and remove the mongolab addon. The file should look like this:

#!/bin/sh

cat <<EOF
default_process_types:
  web: .meteor/heroku_build/bin/node .meteor/heroku_build/app/main.js
EOF

Now commit your changes and push them back to your github repo. Copy the url from the browser url bar, and then switch back over to your terminal. In the root of your project, run the following command to set this as the buildpack for this app.

heroku buildpacks:set https://github.com/Pushplaybang/meteor-buildpack-horse

Deploying Meteor to Heroku

Now that you've completed all the setup, whenever you'd like to deploy you can simply push your git repo to heroku with the following command:

git push heroku master

App not in the root directory?

I usually don't have my meteor app in the root project directory, but rather place it in a sub folder, so that I can keep other assets and tools in the project directory with it, such as a grunt build script for preparing mobile assets, compressing images and svgs, shell scripts, and mobile releases. If you tend to do the same, you'll need to add one additional environmental variable, as we did above:

heroku config:set METEOR_APP_DIR='your-app-dir/'
@Pushplaybang
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment