For this detour, you’ll need to ensure that you have the heroku toolbelt installed on your system. You should have an account with Heroku: try using “heroku login”. You may need to go to their website to create an account if you don’t have one already.

As with Heroku, all Seven5 configuration is through environment variables. If you look at the enable script, there are some variables like HEROKU_NAME and PORT that are used to help initialize the app. The variable FRESNO_TEST is only set in the case of local development.

Create an Heroku app

It would be great if somebody could submit a pull request that has deployment support for dokku running locally, tutum, gce, acs or similar.

You’ll need to create a new Heroku app so you can deploy your copy of fresno. You may need to login to authenticate your account with the Heroku toolbelt, that’s not shown below.

$ heroku apps:create
Creating damp-sierra-7161... done, stack is cedar-14
https://damp-sierra-7161.herokuapp.com/ | https://git.heroku.com/damp-sierra-7161.git

You should take the output name you have received from this creation step and put it in the enable script as HEROKU_NAME.

If you are wondering why the name of the application’s name must be configured, it’s because it’s often the case that applications need to generate a full URL that points to themselves, notably when doing oauth.

Build and run on Heroku

You first need to tell heroku about the buildpack for Seven5 and the app’s own name (change this to the name you got when you created your app). After that, “git push” is your deployment mechanism:

$ heroku config:set BUILDPACK_URL=https://github.com/seven5/heroku-buildpack-seven5.git
$ heroku config:set HEROKU_NAME=damp-sierra-7161
$ heroku config:set STATIC_DIR=static
$ heroku config:set SERVER_SESSION_KEY=xxxxx # look in enable script for how to generate this value
$ git push heroku tutorial:master
[bunch of output about the build procedure]
remote:        https://damp-sierra-7161.herokuapp.com/ deployed to Heroku

You’ll notice that the branch “tutorial” is being pushed to “master” on Heroku because Heroku only builds on pushes to master.

If you see an error like this:

! [rejected]        my-simple-server -> master (non-fast-forward)
error: failed to push some refs to 'https://git.heroku.com/damp-sierra-7161.git'

it is usually because you have re-written your git history and you need to use force (-f) with the git push to get Heroku to accept the push.

You should now be able to visit https://damp-sierra-7161.herokuapp.com/ (with your app’s name) and see the same output that you receive locally.

Add PostgreSQL to your Heroku app

It would be great if somebody could try to get this application to work under mysql since both qbs and heroku support that relational system.

You can add the production database to your Heroku app like this:

$ heroku addons:add heroku-postgresql
$ heroku config
[configuration output]

You’ll notice that the output of the “heroku:config” now includes a DATABASE_URL. There is a corresponding entry in the enable script for the local development case.

$ cat $TUTROOT/src/tutorial/enable-tutorial
[ lots of settings]
export DATABASE_URL="postgres://$USER@localhost:$PGPORT/fresno"

No need to create a database

You will need to be aware that heroku creates the database user, database password, and database name for you and these are all “hard to guess” random values. Because all the configuration information is drawn from the DATABASE_URL you can run the same Go code on both your local system and on Heroku (and they may very well run different operating systems, if you are developing locally on OSX).

Getting a psql prompt

You can access psql to get an SQL prompt from the Heroku toolbelt:

$ heroku pg:psql

By-hand updates to the “production” database on Heroku may be an exceptionally bad idea.

Building and running migrations on Heroku

If you push this version of the code to Heroku, you can get a bash shell on the remote (Heroku) machine and then use the migrations just as with the local case.

$ git push -f heroku tutorial:master
$ heroku run bash
Running `bash` attached to terminal... up, run.4328
$ migrate status
current migration number is 000
$ migrate --up
[migrator] attempting migration UP 001
001 UP migrations performed

Building tags

To avoid conflicts with the “standard” Go compiler, you should put this at the top of all the client-side files you create (and this tutorial does this):

// +build js

Note that this two lines including the blank line that must be present before the file’s package declaration.

Return To Main Tutorial