How to Deploy Vapor Apps to Heroku

November 01, 2016
Written by

vapor-deploy

Building web applications with Swift using Vapor is super simple. Thankfully, deploying them is also a breeze. In just a few steps we’ll go from localhost to Heroku with Vapor’s CLI.

Prerequisites

We need a few things before we get started:

  1. A working Vapor web application. If you don’t have one, you can follow this tutorial to get started.
  2. Git
  3. A free Heroku account
  4. Heroku Command Line Interface – Make sure to run heroku login once the CLI is installed to authenticate your account.

Deploying to Heroku

Vapor supports deployment to any server that can run Swift. The Vapor CLI tool makes deployment to Heroku super simple.

If your Vapor app is not already in a Git repository we’ll need to add one. Run the following commands from your project directory:

git init
git add .
git commit -m "Initial commit"

Now that we have a Git repo we can use Vapor’s CLI to deploy our app to Heroku. Run this command to start the process:

vapor heroku init

Here’s how to answer the questions the CLI asks you:

  • Choose whether you want to give your app a custom name on Heroku. This one’s up to you.
  • Answer n to the custom executable name if you have not modified Vapor’s defaults or y if you have. Answer n if you followed the previously mentioned tutorial.
  • Answer y to deploy now.

Grab some coffee because this will take 5-10 minutes. The reason it takes so long is Swift will be installed on your Heroku instance using swiftenv before building your app.

Once the process is done launch your browser to the Heroku URL provided by the output you should see your app running in the cloud. Here’s some sample output from the tutorial app mentioned above:


If you need to push new changes up to Heroku just commit those changes using git and then use Vapor CLI to push the new code:
git add -A
git commit -m "Shiny new features!"
vapor heroku push

That’s all there is to deploying Vapor apps to Heroku!

What’s Next?

Now that you’ve written some Vapor apps and deployed them to the cloud, what are you going to do next? Here’s some things you might consider:

No matter what you choose to do next, I’d love to hear about it. You can find me on Twitter @brentschooley or send me an email at brent@twilio.com.