I’ve spent quite a bit of time trying to figure out how to successfully deploy Go Revel applications to Heroku, luckily for you. Let’s go through them step by step and I’ll show you how I did it.
First install Go if you haven’t already, this should be pretty self explanatory.
Next, install the Revel framework. Change to the directory where you have your GOPATH configured, for example:
Then execute the following to install Revel:
Update your path to contain the Revel binary:
Now change directory to the src directory:
Create the app
If you haven’t already done so, create a basic vanilla app using revel by executing the following command (replaceing “myapp” with your application name of course):
Next, let’s make sure the app runs by executing the run command:
Open a browser to http://localhost:9000 (or whatever port you have your application configured to run on) and verify that everything is working as expected.
Install Heroku Toolbelt
Download and install the Heroku Toolbelt: https://toolbelt.heroku.com/
Next login to Heroku using the toolbelt:
Enter your Heroku credentials.
Password (typing will be hidden):
Once that’s done you’ll need to create the application. If you’ve already done so by way of the Heroku web GUI, you can skip this step, if not execute the following (Once again replacing “myapp” with your actual app name):
This will ensure that the revel go buildpack is being used.
If you’ve already created the application using the Heroku web GUI, then go under settings and set the buildpack to use “https://github.com/revel/heroku-buildpack-go-revel.git”
Next ensure that you are still under your application directory “src/myapp” and execute the following:
Now that your git is initialized let’s link it to the Heroku online app repo, execute the following (Replace myapp with your actual app name).
Now, we need to install Godep for our project to work correctly on Heroku, install by executing the following:
Next, let’s automatically update all of our dependencies using godep, execute the following under your application directory:
If this ran correctly, you should see a “Godeps” and “vendor” folder under your application directory. Note: pay special attention to the “./…” that needs to be there verbatim.
Test Heroku Local
To ensure everything is going to work in the Heroku environment, we should first test the application locally by executing the following:
[WARN] ENOENT: no such file or directory, open ‘Procfile’
[FAIL] No Procfile and no package.json file found in Current Directory – See heroku local –help
You probably noticed the errors there, this isn’t really an issue, we just need to complete a few things. First lets create a file called “.env” and add an environment variable to it that tells Heroku to use a version later than go 1.5, execute the following:
This file should be located at the root of your application directory (“myapp/.env”).
Next, let’s create a simple Procfile to execute our revel run command. Execute the following:
Finally, let’s add our application name to the “.godir” file. Execute the following:
Now, let’s run “heroku local” again, you should see something similar to the following:
[OKAY] Loaded ENV .env File as KEY=VALUE Format
3:37:24 PM web.1 | ~
3:37:24 PM web.1 | ~ revel! http://revel.github.io
3:37:24 PM web.1 | ~
3:37:24 PM web.1 |
3:37:24 PM web.1 | INFO 2016/06/29 15:37:24 revel.go:365: Loaded module static
3:37:24 PM web.1 | INFO 2016/06/29 15:37:24 revel.go:365: Loaded module testrunner
3:37:24 PM web.1 | INFO 2016/06/29 15:37:24 revel.go:230: Initialized Revel v0.13.1 (2016-06-06) for >= go1.4
3:37:24 PM web.1 | INFO 2016/06/29 15:37:24 run.go:57: Running myapp (myapp) in dev mode
3:37:24 PM web.1 | INFO 2016/06/29 15:37:24 harness.go:170: Listening on :9000
3:37:24 PM web.1 |
Now open your browser to http://localhost:9000 again and verify that it runs correctly in the heroku environment.
If everything runs well locally, then we’re ready to deploy.
Deploy To Heroku
First let’s add all of our changes to git, execute the following:
Next, let’s commit:
Now let’s push the changes to Heroku
user@computer:$ git push heroku master
Counting objects: 377, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (352/352), done.
Writing objects: 100% (377/377), 845.31 KiB | 0 bytes/s, done.
Total 377 (delta 96), reused 0 (delta 0)
remote: Compressing source files… done.
remote: Building source:
remote: —–> Fetching set buildpack https://github.com/revel/heroku-buildpack-go-revel.git… done
remote: —–> Revel app detected
remote: —–> Installing go1.6… done
remote: Installing Virtualenv… done
remote: Installing Mercurial… done
remote: Installing Bazaar… done
remote: —–> Running: godep restore
remote: —–> Discovering process types
remote: Default types for buildpack -> web
remote: —–> Compressing…
remote: Done: 127.8M
remote: —–> Launching…
remote: Released v4
remote: https://obscure-beyond-93544.herokuapp.com/ deployed to Heroku
remote: Verifying deploy… done.
Once completed you should be ready to go. Next run the following to test:
If you received errors during deployment or testing, you may be able to help resolve your issue by viewing the heroku logs:
Hopfully everything turned out well for you. If it didn’t, drop me a line and I’ll see if I can help you out.