Heroku

If you haven't done so please read the guides to install the Maze CLI

The Maze Heroku Buildpack

You can create an app in Heroku with Maze buildpack by running the following command:

$ heroku create myapp --buildpack https://github.com/mazeframework/heroku-buildpack-maze.git

The default behaviour is to use the latest crystal release. If you need to use a specific version create a .crystal-version file in your application root directory with the version that should be used (e.g. 0.23.1).

Requirements

In order for the buildpack to work properly you should have a shard.yml file,as it is how it will detect that your app is a Crystal app. Your application has to listen on a port defined by Heroku.

Maze::Server.configure do |settings|
  settings.host = "0.0.0.0"
  settings.port = ENV["PORT"].to_i if ENV["PORT"]?
end

To be able to decrypt and use production environment you'll need to set ENV["MAZE_ENCRYPTION_KEY"] to the value of your local projects .encryption_key file.

All that's left is to create a git repository, add the Heroku remote and push it there.

Using the Maze CLI on Heroku

When you deploy your project to heroku the maze build-pack will make available the maze cli to you via the bin/maze path.

To run an maze command just on heroku do the following:

Read more about heroku run command on Heroku Dev Center

The Heroku Procfile

To deploy your app to heroku you're going to need a Procfile. Create a Procfile at the root of your Maze application and add the following:

The Maze buildpack takes care of compiling the project for you but if you wish to run your project locally using the heroku command heroku local you must do the following steps.

Create an .env at the root of your Maze project and add the following 2 lines to the .env

Then you must compile your project locally with the following command:

crystal build src/{your-app-name}.cr -o bin/{your-app-name}.

When the compilation process is complete a bin/{your-app-name} directory is added, with this binary of your application with this binary file ready you can proceed to run your application locally with heroku.

And should output something similar to:

You're are now all set and ready to deploy with Heroku.

Last updated