# Deploys, rollback and release command > How a deploy works and how to follow it, cancel it, roll back to an earlier version and run migrations before the switch. Each deploy builds a new image and replaces the service's container. There's no cache to clear and no process to reload: what is live is always a whole image. The **Deploys** tab shows the deploy in progress, what is live and the history. ## Run a deploy A deploy starts in one of these ways: - The **Deploy** button at the top of the service screen. - A push to the service's branch, with **Deploy on every push** turned on. See [Build](https://ployter.com/en/docs/services/builds/#github). - The **Deploy** button in the pending changes bar, or **Deploy all** on the project screen. - The CLI: `ployter deploy` or `ployter up`. See [CLI](https://ployter.com/en/docs/cli/cli/). The service needs a server. Without one, the **Deploy** button is disabled and the screen asks you to choose one in **Settings**. ### Schedule a deploy To deploy later (for example, outside peak hours), click the calendar button next to **Deploy**. Pick the date and time, or one of the shortcuts (**In 1 hour**, **Tonight at 11 PM**, **Tomorrow at 3 AM**), and click **Schedule**. ![Schedule deploy window with one deploy waiting](https://ployter.com/assets/docs/en/deploy-schedule.webp) At the set time, the panel deploys the latest version of the branch, like the **Deploy** button, on behalf of whoever scheduled it. In the history, it shows as **Scheduled**. A dot on the calendar button shows there's a deploy waiting; you can **Cancel** it in the same window. - You can schedule from 1 minute to 30 days ahead, with up to 5 schedules waiting per service. - If whoever scheduled it leaves the team or loses the deploy permission, the schedule doesn't run and shows as **Didn't run**, with the reason. ## The deploy steps The deploy follows the order shown in **Settings → Deploy**: 1. **Image build**: clones the repository at the pushed commit (or the latest on the branch) and builds the image. For a service with a ready-made image, the server only pulls the image. 2. **Before switching versions**: runs the release command (migrations or your script), if there is one. 3. **Version switch**: starts the new container, waits for it to be up and only then removes the old one. Extra processes (queues, workers) start with the new version too. Being up means: - With a **Health check** configured: the path (e.g. `/health`) responds successfully on the service's port. The server waits up to 2 minutes. - Without a health check: the container keeps running for a few seconds without crashing. If the new container doesn't come up, the deploy fails and the previous version stays live. > [!WARNING] > A service with a volume, or with a public or private port published on the server, stops the old version before starting the new one. In those cases the deploy has a few seconds of downtime. ## Follow a deploy In the **Deploys** tab, each deploy shows in a card with its status, who triggered it, the commit and the duration. Click **View logs** to open the live log. ![Deploys tab of the web service with a deploy in progress and the history](https://ployter.com/assets/docs/en/deployments-tab.webp) The possible statuses: | Status | Meaning | | --- | --- | | **Queued** | Waiting for the server (build limit) or for another deploy of the same service. The reason shows on the card. | | **Building** | Cloning and building the image. | | **Deploying** | Running the release and starting the container. | | **Active** | It is the live version. | | **Failed** | The build, the release or the health check failed. The error shows at the top of the log. | | **Cancelled** | Cancelled by someone or replaced in the queue by a newer request. | | **Replaced** | It was live and was replaced by a newer deploy. | | **Crashed** | The live version crashed and the server is trying to start it again. | | **Stopped** | The service was stopped. Run a deploy to bring it back. | ![Modal for deploy #128 with the build log](https://ployter.com/assets/docs/en/deployments-log-modal.webp) When a deploy fails and AI diagnosis is available, the modal shows the diagnosis button next to the error. See [AI diagnosis](https://ployter.com/en/docs/observability/ai-diagnosis/). ## Cancel a deploy While the deploy is **Queued**, **Building** or **Deploying**, the card shows **Cancel** (or **Remove from queue**). In the log modal, use **Cancel deploy**. The server stops the build, the download, the release or the health check and undoes whatever was started. Once the version switch starts, you can no longer cancel. > [!NOTE] > A deploy of a service with replicas can't be cancelled midway, because each server is at a different step. ## Rollback: go back to an earlier version 1. In the **Deploys** tab, open **History**. 2. On the deploy you want back, open the **More actions** menu and click **Roll back to this version**. 3. Confirm with **Roll back**. A rollback starts that deploy's image again, with no build. You can only roll back to a deploy that actually went live. > [!WARNING] > A rollback uses the **current** variables and domains. The history doesn't keep a copy of the variables. Images built on the server take up disk space. The server keeps the 5 most recent images of each service. For versions older than that, run a new deploy of the commit. Services with a ready-made image (Docker Hub) can roll back to any version, because the server pulls the image again. ### Automatic rollback On by default for every service, under **Settings → Automatic rollback**. The panel goes back on its own to the last version that was working in two cases: - **The deploy took the service down.** A service with a volume or public port stops the old version before starting the new one. If the new one fails the health check, nothing is left running: the panel starts the previous version again. - **The new version went down right after.** It passed the health check but went down twice (error or out of memory) in the first 10 minutes. For other services, a failed deploy takes nothing down: the previous version stays up until the new one passes the health check. The automatic rollback shows up in the deploy history with the origin **Automatic rollback** and in **Metrics → Events**. Whoever gets deploy notices receives an email with the reason. It never chains: if the previous version also fails, the panel stops and lets you know. ![Automatic rollback option in the service settings](https://ployter.com/assets/docs/en/auto-rollback-setting.webp) ## Restart with the current variables On the deploy card, the **More actions** menu has **Restart**. It starts that deploy's image again with the current variables, port and domains, in seconds and with no build. Use it to: - Apply new variables without waiting for a build. - Retry a deploy that failed after the build (database down, wrong variable). - Start a crashed version again. > [!NOTE] > The **Restart** button at the top of the screen is different: it only restarts the live container, with the same variables. > [!TIP] > Variables read at build time (such as `NEXT_PUBLIC_*` in Next.js) are baked into the image. To change them, run a full **Deploy**. ## Release command (migrations) The release command runs with the new image, in a separate container, before the switch. If it fails, the deploy is cancelled and nothing changes on the live version. 1. Open **Settings** and go to **Before switching versions**. 2. Choose an option: - **Nothing**: runs nothing. - **Migrations**: runs the migrations command for the framework detected in the build. - **Custom script**: runs your script, one command per line. 3. Click **Save**. It applies from the next deploy. With **Migrations**, the command depends on the framework: | Framework | Command | | --- | --- | | Laravel | `php artisan migrate --force` | | Symfony | `php bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration` | | Django | `python manage.py migrate --noinput` | | Rails | `bundle exec rails db:migrate` | | AdonisJS | `node ace migration:run --force` | | Phoenix | `mix ecto.migrate` | For other frameworks (such as Prisma or TypeORM on Node), use **Custom script**. The script runs with `/bin/sh`. To stop at the first error, start with `set -e`: ```bash set -e npx prisma migrate deploy ``` ![Before switching versions section with Custom script filled in](https://ployter.com/assets/docs/en/deployments-release-script.webp) ## Deploys with replicas With the service on several servers (AWS or DigitalOcean), the deploy updates one server at a time. The card shows the progress of each replica (e.g. **Replica 1 of 2 (app-1)**). See [Replicas and load balancer](https://ployter.com/en/docs/scaling/replicas/). ## How long the history is kept Deploys stay in the history and rollback keeps working. Each deploy's log is deleted after your plan's history period (the `history_days` limit). See [Subscription, plans and costs](https://ployter.com/en/docs/team/billing/).