GuidesAdvancedPre-deploy Command

Pre-Deploy Command

The pre-deploy command allows you to run a command after the build step and before the deploy step. The command runs as part of the deployment lifecycle, meaning the whole deployment will fail if the command fails.

Pre-deploy commands are can be good for commands and scripts crucial for the operation of your application, for example database migration. The command runs by spinning a container similar to the runtime container while overriding the start command. The command runs in the basePath directory of your application.

Note: using this to run database migrations will add 2-3 minutes to your deploy time because of the time it takes this temporary container to boot and run. It will be faster to run the database migrations at the end of your build command, if feasible.

When running the main application in a custom Dockerfile, you must use CMD instead of ENTRYPOINT

Configuring Pre-Deploy Command

Pre-deploy command can be configured as a service configuration parameter for web, worker, and scheduler services.

If you are using the dashboard to configure your project, set the command as shown in the screenshot.

Configuring predeploy command in service settings

If you are using the flightcontrol.json file to configure your app, add a new parameter preDeployCommand to your service object.

{
    "id": "web",
    "name": "Webserver",
    "type": "web",
    "target": {"type": "fargate"},
    "preDeployCommand": ["bundle", "exec",  "rails", "db:prepare"],
    ... // remaining service config
}

Notifications

You can turn on email or Slack notifications for pre-deploy command failures in organization settings.

Enabling Pre-deploy Command Failure notifications in Organizations Settings