# Startup Pricing Service: delivery and recovery runbook Service: stateless Flask + Gunicorn pricing API (course starter `dosSecureDelivery`). Environments on the single Droplet (shared failure domain, no high availability): | Environment | URL | Compose project / directory | Network alias | |---|---|---|---| | staging | https://staging.ssw590.abrdns.com | `pricing-staging` / `/opt/startup/pricing-staging` | `pricing-staging` | | production | https://app.ssw590.abrdns.com | `pricing-production` / `/opt/startup/pricing-production` | `pricing-production` | Jenkins job: `pricing-delivery` (https://ci.ssw590.abrdns.com/job/pricing-delivery/), runs only on agent `delivery-agent`. ## Roles | Action | Who | How it is enforced | |---|---|---| | Change code or configuration | SB, SD | Gitea pull request to `main` | | Start a release or redeploy | SB, SD (Jenkins accounts) | Jenkins login; anonymous users have no build permission | | Approve production (release or rollback) | `sbhayana`, `sdevanahally` only | `input` step `submitter`, 30-minute timeout | | Roll back production | SB, SD | `MODE=redeploy` + approval | | Host-level emergency access | SB, SD | SSH as root from allow-listed addresses only | ## Release (normal path) 1. Merge the reviewed change to `main` (Jenkins posts `continuous-integration/jenkins`). 2. Jenkins → `pricing-delivery` → Build with Parameters: `BRANCH=main`, `MODE=release`. 3. Pipeline: unit tests → pip-audit → Trivy secret scan → build → Trivy image scan → publish + pull back by digest → write release records → Ansible deploy staging → smoke test → second Ansible run must report `changed=0` → **approval** → Ansible deploy production (same digest) → smoke test. 4. Download `pricing/releases/vN-staging.yml` and `vN-production.yml` from the build artifacts and commit them to `pricing/releases/` through a pull request. Rollback uses only committed records. ## Failed deployment Symptom: Ansible task "Converge application without rebuilding" fails (container unhealthy) or a smoke/assert task fails; Jenkins run is red; no automatic rollback. 1. Do not retry blindly. Read the Ansible log artifact and `docker compose -p pricing- ps` / `docker logs pricing--app-1` on the Droplet. 2. Revert the faulty configuration commit in Gitea (pull request) so `main` again holds the last reviewed record/template. 3. Run `MODE=redeploy`, `RECORD=`. The job checks out the record's `config_commit` version of `pricing/ansible` before deploying. 4. Confirm the smoke test passes (health, version, commit, total 30/36, HTTP 400). ## Production rollback (healthy release, wrong business result) 1. Decide: e.g. v2 price is not approved. Note the time. 2. Start a timestamped check from an allow-listed laptop: `while true; do printf '%s ' "$(date -u +%T.%N | cut -c1-12)"; curl -s -m 2 https://app.ssw590.abrdns.com/ || echo FAIL; echo; sleep 0.5; done | tee rollback-probe.log` 3. Jenkins: `MODE=redeploy`, `RECORD=v1-production.yml`; approve. 4. Recovery = first `SMOKE PASS` with v1 and total 30; interruption = gap of FAIL/502 lines in the probe log. A recreate deployment is **not** zero-downtime. Never run `docker compose down -v`, `docker system prune`, or touch Gitea/Jenkins/Caddy volumes as part of an application rollback. ## State and rollback limits This service is stateless, so image + configuration rollback is complete. With a database, a v2 schema migration (e.g. dropping or renaming a column) could make v1 fail against the migrated data; payments already captured at v2 prices cannot be "rolled back". Use expand/contract migrations: add new columns/tables first (both versions work), switch code, and drop old structures only in a later release after rollback is no longer needed. ## Cleanup (only after grading, when instructed) ``` cd /opt/startup/pricing-staging && docker compose -p pricing-staging down cd /opt/startup/pricing-production && docker compose -p pricing-production down ``` Then remove the two Caddy site blocks and reload Caddy, delete the `staging` and `app` DNS records, remove the `app` probe target, revoke the Gitea package tokens and the `deploy` SSH key, and delete the `deploy-ssh`, `gitea-registry-write`, `gitea-status-token` Jenkins credentials. Keep Gitea, Jenkins, monitoring and their volumes.