Deploying to Heroku

2020-05-17

Dependencies

Steps

Make sure your application checks the PORT environment variable, and on launch, binds to that port.

Log in to the Heroku dashboard. Create a new app with a name of your choice.

Open a shell and navigate to your project directory.

Log in to Heroku with the CLI.

# Interactive command, follow the instructions
heroku login

Set up the current git repository to have an additional remote, heroku. Use the app name you created in the first step. This will allow you to push your code to Heroku.

heroku git:remote --app rapu

Set up the current Heroku app to use the Rust buildpack. This will make sure Heroku will build your application with the correct Rust tooling.

heroku buildpacks:set emk/rust

Create a file named Procfile in your repository. This will configure which command is used to run your application, when it has been built. Use the app name your program gets compiled to. The web part tells Heroku to use their web application runner for your app.

web: ./target/release/rapu

Now it is time to push your application to Heroku.

git push heroku master

First deployment can be slow, as everything has to be compiled. Subsequent deployments should be faster, as a cache can be utilized.

Optional

Go to the Heroku dashboard, to your application's settings. Add a custom domain or subdomain for it. Configure the domain at your registrar or DNS provider to point to the Heroku URL provided by the settings page.