Magic Apps
Deploys and rollbacks
What a deploy does, what happens when one fails, and how to cancel, redeploy or roll back.
A deploy turns a commit into a running release. Releases are numbered v1, v2 and so on, and each is frozen: the image, the command for each process, the release command, the port and the environment variables.
The stages
| Stage | What happens | Fails when |
|---|---|---|
| Building | The commit is built into an image | The build fails, or runs over 35 minutes |
| Releasing | The release command runs once | It exits with a code other than 0, or runs over 30 minutes |
| Deploying | Every process gets new instances, one at a time | A new instance crashes, or isn’t ready in time |
| Live | The release is serving |
A deploy starts from a push to the app’s branch, from the dashboard, or when you create the app. Deploys of one app run one at a time.
When a deploy fails
The running version keeps serving.
- A failed build names the step that failed and quotes the first line of its output that mentions an error. The step’s last 15 lines are repeated at the end of the build log.
- A failed release command stops the deploy before any process changes. Its output is in the deploy log.
- A crash during rollout is rolled back: every process goes back to the previous release. The deploy’s error quotes the crashed process’s last line naming an error, and its last 150 lines go to the deploy log.
A command that exits with an error is not retried, since running it again gives the same result. A network or registry error is retried up to three times.
Cancel a deploy
You can cancel a deploy at any stage before it goes live.
| Cancelled while | Result |
|---|---|
| Waiting | Dropped |
| Building | Stopped. Nothing running changed |
| Releasing | The release command is stopped. Whatever it already did, such as a migration, is not undone |
| Deploying | Processes go back to the previous release |
Redeploy without building
A redeploy runs the live image again with the current settings and environment variables. Use it after changing a runtime variable or a setting; it skips the build.
Changes to build variables, the branch or the root directory need a build, so a redeploy doesn’t apply them. The dashboard lists the changes waiting for a deploy and offers the right kind.
Roll back
A rollback deploys an earlier release exactly as it was: the same image, commands and variables. There is no build and no release command, so database migrations applied since then stay applied.
Rollouts without downtime
During a rollout the old and new versions serve side by side, so a migration has to work with both. For example, a Django migration that adds a required column with default= breaks inserts from the old version until it’s replaced; db_default= keeps the default in the database and works with both.
An app whose process has a volume is the exception: its old instance stops before the new one starts, so each deploy has about 40 seconds of downtime.