Procfile

Procfile support is one of our compatibility layers that makes Scalingo compatible with Heroku.

Definition

The Procfile is a way to define how the platform will try to start your containers. In this file, you can define all the different process you would like to run in your project from the same code base. It is commonly used to define how to start workers which will consume asynchronous jobs.

A Procfile is a text file using the YAML format describing how to start each type of container for your app. It has to be located at the root of your project. Environment variables will be interpolated.

web: bundle exec rails server -p $PORT -e $RAILS_ENV -b 0.0.0.0
worker: bundle exec sidekiq -e $RAILS_ENV

By default, when you first try to deploy your application, we’ll try to launch the web process. We try to determine it without your help, but in some cases it is required to define it, as in the previous example. If your application requires a Procfile and you haven’t defined it, your deployment will fail and a log entry will attest the lack of Procfile.

The standard syntax is:

<container type>: <command>

container type: should contain letters and digits only
command: any command line which can includes environment variables

When you have more complex commands to run, don’t hesitate to write a short start script, for instance in bin/start.sh:

#!/bin/bash

if [ "$SOME_ENV" = "SOME_VALUE" ] ; then
  exec run_this_command -p $PORT
else
  exec run_that_other_command
fi

Then in your Procfile, directly call this script:

web: bash bin/start.sh

Postdeploy Hook

The Procfile is also the place to declare a post-deploy hook. More information here.

You can use a custom script if you only want to run the post-deploy hook in some situations, in the following case if the variable SOME_ENV equals SOME_VALUE:

#!/bin/bash

if [ "$SOME_ENV" = "SOME_VALUE" ] ; then
  exec postdeploy_command -p $PORT
else
  echo "Postdeploy hook disabled"
  exit 0
fi

Then modify the Procfile:

postdeploy: bash bin/postdeploy.sh

Using in development

To reduce the environment gap between the development and the production, it is important to execute the same processes in development and in any deployed environment.

To achieve this different tools exist. The most famous is foreman. A little ruby gem executing and displaying the output of all the processes defined in your Procfile.

└> cat Procfile
web: bin/project
worker: bin/project -worker

└> foreman start
17:52:56 web.1    | started with pid 10663
17:52:56 worker.1 | started with pid 10664
17:52:56 web.1    | 2014/12/01 17:52:56 Listen HTTP requests on :5000
17:52:56 worker.1 | 2014/12/01 17:52:56 Starting Asynchronous worker

To install it: gem install foreman

Alternatives to foreman:


mode_edit Suggest edits