Post-deployment hook


When you deploy your application, you may want to trigger automatically custom actions after the deployment succeeded, this hook is then exactly what you need. This hook will automatically starts the specified command at the end of your deployment.


To setup a post-deployment hook, you have to add a postdeploy entry in your Procfile:

postdeploy: command you want to run

Then commit your Procfile and from the next deployment, the hook will be executed.


The Post-deployment hook will be part of the deployment process, things will happen in the following order:

  1. The application is built
  2. Containers from the new version of the application are started
  3. We wait until they started successfully (see common deployment start errors)
  4. An extra container is started to run the postdeploy command
  5. If the postdeploy command has succeeded, we update the routing configuration, the new containers start to get requests and the deployment is considered a success


The environment available in the context of the container running the postdeploy hook will be exactly the same as the one of your running app. It contains the environment variables from your app, with the one we inject in any runtime environment


  • Duration: a postdeploy hook should be achieved in less than 20 minutes, otherwise the process will be stopped and the status -128 will be returned. If you have long task to achieve after a deployment, it is recommended not to use a postdeploy hook but a one-off container once the deployment has been done.


Applying migrations

A common example to this feature is to apply migrations, for instance with a Rails application:

postdeploy: bundle exec rake db:migrate

Notifying external service

New Relic

postdeploy: newrelic deployments --revision=$CONTAINER_VERSION


postdeploy: curl -F access_token=$ROLLBAR_ACCESS_TOKEN -F environment=$RAILS_ENV -F revision=$CONTAINER_VERSION -F local_username=scalingo


The appsignal CLI notify_of_deploy command is deprecated. But you can notify AppSignal of a new deployment by adding the file config/appsignal.yml with the following content:

default: &defaults
  revision: <%= ENV.fetch("CONTAINER_VERSION") { nil } %>
<<: *defaults

This solution works for the AppSignal Ruby gem version >= 2.6.1.

You can also use AppSignal Push API to manually create a deploy marker with this postdeploy command:

postdeploy: curl -X POST -d "{\"revision\":\"$CONTAINER_VERSION\",\"user\":\"scalingo\"}" "$APPSIGNAL_PUSH_API_KEY&name=$APPSIGNAL_APP_NAME&environment=$APPSIGNAL_APP_ENV"

Both Applying migrations and notifying external service

Use the standard && bash operator:

postdeploy: bundle exec rake db:migrate && newrelic deployments --revision=$CONTAINER_VERSION

What you should not do

Build assets

The postdeploy hook is not the right place to build your assets. Keep in mind that the action is executed in a dedicated one-off container, the other containers from your application won’t be impacted by any file change.

All operations related to assets should be done in the build process. The location of the instruction to build the assets depends on the technology:

  • PHP Symfony (doc)
  • Node.js (doc)

mode_edit Suggest edits