Skip to content

Instantly share code, notes, and snippets.

@chriswburke
Forked from vitalbone/keystone2heroku.md
Created November 21, 2016 01:11
Show Gist options
  • Save chriswburke/20ba2fa0659b6a7e48f1ab3259539a3f to your computer and use it in GitHub Desktop.
Save chriswburke/20ba2fa0659b6a7e48f1ab3259539a3f to your computer and use it in GitHub Desktop.
Deploying KeystoneJS to Heroku

Deploying a Keystone App to Heroku

Keystone comes completely set up to install on Heroku in a couple of steps.

1. Sign up for a Heroku account and install the Heroku Toolbelt.

Log in with it and you're ready to begin. Heroku uses git to deploy a new site, so with that in mind:

2. Create a new repository on Github and then clone it.

3. Run the Keystone Yeoman generator.

(if you don't have yeoman then npm install -g yo)

yo keystone

4. cd into your project’s root folder and run heroku create.

heroku create

Heroku will generate an app name for you (something like beautiful-island-4327) and set up a git remote called heroku to use for identification (for deployment, etc).

Imgur

5. Rename if to something more useful.

heroku apps:rename your-app-name --app current-name-of-your-app

You should see something like this:

Imgur

6. Add your new Heroku remotes.

heroku git:remote --app deploy-tester-4000

Now for some add-ons!

Firstly, you’ll need a database. There are a few provides you can choose from in Heroku’s add-ons directory. For the purpose of this walk-through we’ll be using Mongolab (gives you <= 512mb for free).

N.B: You'll have to set up billing to do this (it won't charge you; they just want a credit card on file)

7. Add Mongolab.

heroku addons:add mongolab:sandbox

You should see something like this:

Imgur

N.B: You can point your Keystone site at any database provider by customising the MONGO_URI environment variable (make sure to remove the mongolab addon first!)

Secondly, let’s add a logging system. Again, there are a few to choose from but we'll be usinfg Papertrail. This gives you a nice web UI to your application logs (i.e. console.log()) and lets you set up alerts for errors, etc. The basic plan for papertrail is also free.

8. Add Papertrail. heroku addons:add papertrail:choklad

You should see something like this:

Imgur

9. Finally, you'll want to set up a Cloudinary account. You can do this yourself (the dashboard gives you the ENV variable to set up) or you can add it as an add-on to your Heroku account like Mongolab and Papertrail - we recommend you do this manually as you'll probably want to use the account in development and staging as well, rather than having it tied to a single Heroku app.

  • Bonus: if you click through to the signup page from the Keystone docs you should get access to a special cheaper low-tier plan for Keystone users. Also free for light traffic though. *her

Ok, that’s the setup process over.

10. Once you've created your app and got the database (at least) configured, just commit all your code to git and run this command to make your site go live:

git push heroku master

Your site will now be hosted at http://your-app-name.herokuapp.com

Log into your account to add a real domain for it, and then just point your DNS at Heroku and you're off.

You can also set up SSL and whatever else you need.

The only thing to be aware of is that Heroku doesn't keep any changes to the local file system so you can't keep user-uploaded images (etc) without putting them on a 3rd party site / service, hence the Cloudinary / Azure / S3 integration.

You're all set.

Make sure to check out Heroku’s getting started docs for Node.js if you hit any hurdles.

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