Skip to content

Instantly share code, notes, and snippets.

@paulcuth
Created July 22, 2015 20:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulcuth/5cffe9f4ed310dc0a49d to your computer and use it in GitHub Desktop.
Save paulcuth/5cffe9f4ed310dc0a49d to your computer and use it in GitHub Desktop.
Deploying Sailor to Heroku

Deploying Sailor to Heroku

Getting set up

Heroku basics

You will need to create an Heroku account if you don't have one already. You'll also need to install the Heroku Toolbelt, which includes the Heroku CLI that we'll be using shortly.

Sailor basics

Follow the installation instructions for your platform in the Sailor docs, but essentially all you need is the sailor CLI.

Making your Sailor app Heroku-ready

I'm going to use the out-of-the-box Sailor example app. To do that I run:

sailor create 'Hey arnold' 
cd hey_arnold

As you can see, this creates a hey_arnold directory that contains our new project.

Next up we'll let the buildpack know about our dependency. Let's create the file hey_arnold.rockspec in the root of our project, containing the following:

dependencies = {
	"sailor >= 0.4"
}

We'll also need to tell Heroku what to do to run our app after deployment. To do that we create a file, again in the project root, named Procfile with a single instruction inside:

web:	lua start-server.lua $PORT

Notice that $PORT variable? Heroku will tell us which port to use, so we need to update start-server.lua file to respect that.

Somewhere near the top of the file, define a variable port and set it to value passed into the script:

local port = tonumber(...) or 8080

Finally, use that value when setting up Xavante:

xavante.HTTP{
    server = {host = "*", port = port},
	-- ...
}

That's all you need to do in your app. Let's deploy...

Deploying to Heroku

We deploy our app to Heroku using Git, but first we'll need to do a little admin. We'll login using the Heroku CLI, then create a new app and repo:

heroku login

You'll be asked for your credentials.

Now we create the new app and configure it to use the awesome Lua buildpack from @leafo. Replace mysailorapp with the name of your app, bearing in mind that the name you choose here will end up in the default URL for your app.

heroku create mysailorapp --buildpack https://github.com/leafo/heroku-buildpack-lua

Next we need to set up the new Heroku app repo as a remote. To do that we need find out what the new remote Git URL is (remember to replace mysailorapp with the name of your app):

heroku apps:info -a mysailorapp

It'll probably look something like https://git.heroku.com/mysailorapp.git. Note also the Web URL, you'll need that to take a look after deploy.

As our app is is fresh out of the box, we need to initialise it as a Git repo before setting the remote host. (Obviously, if you've already set up your project as a Git repo, don't do the first step).

git init
git remote add heroku https://git.heroku.com/mysailorapp.git
git add .
git commit -m 'Initial commit'
git push heroku master

The last command will kick off the deploy and you'll see the logs flash by. When it's done, navigate to the Web URL from above (something like https://mysailorapp.herokuapp.com/) and enjoy.

From now on, you only need to commit and push to the heroku remote to deploy again and again.

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