When you deploy your application, you may want to trigger custom actions after the deployment succeeded automatically. So far you had to run custom commands by hand which was sensible to human-keyboard interface errors. This hook is then exactly what you need. It will automatically start the configured command at the end of your deployment.
To add a postdeploy hook to your application , you just have to add to your Procfile (or create a Procfile file), a new type named postdeploy
. The command specified for this type of container will be executed in a one-off container at the end of each deployment.
postdeploy: command to run
The command will be executed synchronously after the deployment. If the hook fails, the deployment will also fail, the old version of your application will be kept until a new successful attempt of deployment. Here is an example of logs you can get when a postdeploy
hook has been set:
The postdeploy hook is executed in a one-off container and has exactly the same environment, which means you’ll have access to your the environment variables of your application, and variables from the runtime environment (APP
, CONTAINER
, CONTAINER_VERSION
). You can use these variables directly in the postdeploy
line of the Procfile, or in a script which is called by it.
postdeploy: bundle exec rake db:migrate
Keep in mind that migrations may fail, design them knowing that, you will find an article from Codeship explaining this process.
postdeploy: newrelic deployments --revision=$CONTAINER_VERSION
postdeploy: curl https://api.rollbar.com/api/1/deploy/ -F access_token=$ROLLBAR_TOKEN -F environment=$RAILS_ENV -F revision=$CONTAINER_VERSION -F local_username=scalingo
postdeploy: ./scripts/postdeploy.sh
You can event chain taks by using logical operators like &&
or ||
postdeploy: ./postdeploy-step1.sh && ./postdeploy-step2.sh
A while ago, we released our way to add a button on your open-source project website or Github page. Thanks to this hook a lot of new possibilities are available as you can achieve operations to initialize the database or anything required by your application in an automated fashion.
Note that to ease the process, if you were already using this feature from Heroku, we’ve added a compatibility layer to use the scripts.postdeploy
attribute of the JSON app manifest as a standard postdeploy
hook on Scalingo.
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 operation relative to assets should be done in the build process.You’ll find more information about the way this hook is being executed in our documentation. This is a first stone to a bigger picture, next step will be related to Github:
Raise your hand if you want to test the new Github integration! #PaaS #Github pic.twitter.com/8MK6IM9KtE
— Scalingo (@ScalingoHQ) October 7, 2016
Don’t hesitate to contact us if you’ve any feedback on the feature, or if you want to beta-test the Github integration.
At Scalingo (with our partners) we use trackers on our website.
Some of those are mandatory for the use of our website and can't be refused.
Some others are used to measure our audience as well as to improve our relationship with you or to send you quality content and advertising.