---
title: Deployment & Rollback Runbook
summary: Operator runbook for deploying BookWorm releases, shifting Container App revision traffic, and executing instant rollbacks.
owners:
  - platform-engineering-team
badges:
  - content: Cloud / DevOps
    backgroundColor: green
    textColor: green
---

## When to Use & Blast Radius

Use this runbook to deploy new infrastructure or application releases to `Development`, `Staging`, or `Production`, shift traffic between Container App revisions, or roll back a broken release. Provisioning and production rollouts modify live Container Apps, identity bindings, and ingress routing.

<Admonition type="warning" title="Blast Radius & Deployment Tooling">

BookWorm deploys exclusively via `aspire deploy` or the CI/CD workflow (`apphost-cd.yml`). Do not
use `azd up` or manual template deployments. In single-active-revision mode, deploying a new
revision replaces live traffic immediately—verify candidate revisions or enable multiple-revision
mode before shifting production traffic.

</Admonition>

### Release and Rollback Path

<MermaidFileLoader file="mermaids/001-azure-deployment-guide-diagram-1.mmd" />

## Pre-Flight Check

Verify Azure authentication, target subscription, and current Container App health before deploying or shifting traffic:

```bash
az login
az account set --subscription "<SUBSCRIPTION_ID>"
az containerapp list --resource-group "<RESOURCE_GROUP>" \
  --query "[].{Name:name, Status:properties.runningStatus, LatestRevision:properties.latestRevisionName}" -o table
```

## Procedure

<Steps>
<Step title="Export deployment environment variables (workstation deploys)">

Set the target Azure context and external partner connection strings before running `aspire deploy`:

```bash
export Azure__SubscriptionId="<SUBSCRIPTION_ID>"
export Azure__TenantId="<TENANT_ID>"
export Azure__Location="<REGION>"
export Azure__ResourceGroup="<RESOURCE_GROUP>"
export Azure__CredentialSource="AzureCli"

export ConnectionStrings__broker="<KAFKA_CONNECTION_STRING>"
export ConnectionStrings__vectordb="<QDRANT_CONNECTION_STRING>"

export Parameters__email_smtp_endpoint="smtp://smtp.sendgrid.net:587"
export Parameters__email_smtp_username="apikey"
export Parameters__email_smtp_password="<SMTP_PASSWORD>"
export Parameters__email_sender_address="<SENDER_EMAIL>"
export Parameters__email_sender_name="BookWorm Support"
```

</Step>

<Step title="Deploy via Aspire CLI or dispatch GitHub Actions">

Run `aspire deploy` for direct operator releases, or dispatch the CI/CD workflow for audited environment promotion:

```bash
# Option A: Direct CLI deploy
aspire deploy --environment "<ENV>" --pipeline-log-level information --include-exception-details

# Option B: Trigger CI/CD release promotion
gh workflow run apphost-cd.yml \
  -f environment="<ENV>" \
  -f clear_cache=false \
  -f pipeline_log_level=information
```

</Step>

<Step title="Monitor CI/CD run status (if using GitHub Actions)">

Watch the active workflow run until all build, push, and Container App rollout steps complete:

```bash
gh run list --workflow=apphost-cd.yml --limit 5
gh run watch "<RUN_ID>"
```

</Step>

<Step title="Perform staged traffic shifting (optional blue/green)">

Switch a target Container App to multiple-revision mode to split traffic between the previous and candidate revisions:

```bash
az containerapp revision set-mode \
  --name "<APP_NAME>" \
  --resource-group "<RESOURCE_GROUP>" \
  --mode multiple

az containerapp ingress traffic set \
  --name "<APP_NAME>" \
  --resource-group "<RESOURCE_GROUP>" \
  --revision-weight "<PREVIOUS_REVISION>=90" "<REVISION_NAME>=10"
```

</Step>

<Step title="Promote candidate revision to 100% traffic">

Once smoke checks and error rates remain clean, shift full traffic to the new revision:

```bash
az containerapp ingress traffic set \
  --name "<APP_NAME>" \
  --resource-group "<RESOURCE_GROUP>" \
  --revision-weight "<REVISION_NAME>=100"
```

</Step>

</Steps>

## Verification

Confirm all 16 application Container Apps report `Running` and the **API Gateway** serves HTTP `200`:

```bash
GATEWAY_FQDN=$(az containerapp show --name gateway --resource-group "<RESOURCE_GROUP>" --query "properties.configuration.ingress.fqdn" -o tsv)
az containerapp list --resource-group "<RESOURCE_GROUP>" \
  --query "[].{Name:name, Status:properties.runningStatus, External:properties.configuration.ingress.external}" -o table
curl -I "https://${GATEWAY_FQDN}/"
curl -I "https://${GATEWAY_FQDN}/backoffice"
```

Expected output:

```text
Name                 Status    External
-------------------  --------  ----------
gateway              Running   True
storefront           Running   False
commerce             Running   False
backoffice           Running   False
catalog              Running   False
...
HTTP/2 200
```

## Rollback / Escape Hatch

If a release causes `5xx` spikes, probe failures, or broken journeys, immediately shift 100% traffic back to the previous healthy revision or re-run the last known-good CI/CD commit:

```bash
# 1. List recent revisions to identify <PREVIOUS_REVISION>
az containerapp revision list --name "<APP_NAME>" --resource-group "<RESOURCE_GROUP>" \
  --query "[].{Revision:name, Active:properties.active, Health:properties.healthState, Created:properties.createdTime}" -o table

# 2. Ensure multiple-revision mode is enabled, activate previous revision, and shift 100% traffic
az containerapp revision set-mode --name "<APP_NAME>" --resource-group "<RESOURCE_GROUP>" --mode multiple
az containerapp revision activate --name "<APP_NAME>" --resource-group "<RESOURCE_GROUP>" --revision "<PREVIOUS_REVISION>"
az containerapp ingress traffic set --name "<APP_NAME>" --resource-group "<RESOURCE_GROUP>" --revision-weight "<PREVIOUS_REVISION>=100"

# 3. Deactivate the faulty revision
az containerapp revision deactivate --name "<APP_NAME>" --resource-group "<RESOURCE_GROUP>" --revision "<REVISION_NAME>"
```

To redeploy the previous release from GitHub Actions:

```bash
gh workflow run apphost-cd.yml --ref "<PREVIOUS_TAG_OR_COMMIT>" -f environment="<ENV>" -f clear_cache=true
```

<Accordion title="Non-Production Environment Cleanup & Common Deploy Failures">

<Admonition type="danger" title="Destructive Action">

Deleting a resource group permanently destroys all Container Apps, databases, storage accounts,
and logs inside it. Never run this against Production.

</Admonition>

```bash
az group delete --name "<RESOURCE_GROUP>" --yes --no-wait
```

| Symptom                                                         | Cause                                                             | Fix                                                                       |
| :-------------------------------------------------------------- | :---------------------------------------------------------------- | :------------------------------------------------------------------------ |
| Missing parameter error for `broker`, `vectordb`, or email      | Required environment variable is unset                            | Export all variables in Step 1 and re-run `aspire deploy`                 |
| `AuthorizationFailed` during provisioning                       | Deploying identity lacks `User Access Administrator` or `Owner`   | Assign `Contributor` + `User Access Administrator` on `<SUBSCRIPTION_ID>` |
| `403` or PostgreSQL token login errors right after first deploy | Newly assigned Entra ID RBAC roles take 5–10 minutes to propagate | Wait 10 minutes and restart the failing revision                          |
| Unexpected resource drift                                       | Cached Aspire deployment state is stale                           | Re-run `aspire deploy` with `--clear-cache`                               |

</Accordion>
