# Phase 22 — Staging deployment and runtime test execution

## Source changes in this phase
- Added a Docker build argument `INSTALL_DEV` so production containers install `--no-dev`, while a dedicated testing image installs PHPUnit and other dev dependencies.
- Added a Docker Compose `testing` profile with an isolated in-memory SQLite test container.
- Added `scripts/phase22-staging-deploy.sh`, a fail-closed staging deployment runner.
- The runner validates production-mode environment settings, builds production services, waits for MySQL health, starts app/Nginx/queue/scheduler, boots Laravel, compiles routes, inspects migration status, requires explicit `APPLY_MIGRATIONS=YES`, runs PHPUnit in the isolated test container, and runs HTTPS smoke tests.

## Controlled staging execution
On a provisioned staging host:

1. Generate and review `composer.lock`.
2. Copy `.env.example` to `.env`; set unique staging secrets, HTTPS APP_URL, APP_KEY, database credentials and secure cookie settings.
3. Place the app behind an approved TLS reverse proxy. The Docker Nginx listener is loopback-bound by default.
4. Create and verify an encrypted pre-migration backup.
5. Inspect migration status and database target.
6. Run the staging deployment runner with explicit migration approval:

```bash
APPLY_MIGRATIONS=YES HMIS_BASE_URL=https://staging.example.gov.ng \
  scripts/phase22-staging-deploy.sh
```

The script will not apply migrations unless the operator explicitly sets `APPLY_MIGRATIONS=YES`.

## Current authoring-environment execution evidence
- `scripts/verify-project.sh`: PASS.
- `scripts/phase20-acceptance.sh`: BLOCKED at prerequisite check because `composer.lock` is absent.
- `scripts/phase21-release-candidate.sh`: BLOCKED because `composer.lock` is absent.
- PHP CLI is present, but PHP extensions required by Laravel are missing: PDO SQLite, PDO MySQL, mbstring, curl, XML, ZIP, intl and bcmath.
- Composer, Docker, Docker Compose, MySQL/MariaDB, vendor dependencies and `.env` are absent.
- `php artisan` cannot boot because `vendor/autoload.php` is absent.
- No staging URL is configured.

## Runtime test status
| Test | Result |
|---|---|
| PHP/JS/shell static syntax | Passed |
| Project preflight | Passed |
| Composer install / audit | Blocked |
| Docker image build | Blocked |
| MySQL service startup | Blocked |
| Laravel boot / route:list | Blocked |
| Database migrations | Not run |
| PHPUnit | Not run |
| HTTP smoke test | Not run |
| DHIS2/FHIR external tests | Not run |
| SMS delivery | Not run |
| Backup/restore drill | Not run |

## Important distinction
The SQLite test container is a convenience for fast feature tests, not a substitute for MySQL acceptance. Run all schema and integration acceptance tests against a clean MySQL staging database as well. No test is marked passed unless it was actually executed.

## Release decision
**STAGING DEPLOYMENT BLOCKED IN THIS ENVIRONMENT.** Source changes and deployment automation are prepared, but no runtime deployment or acceptance has occurred. Production remains NOT RELEASED.


## Actual execution attempt (2026-11-22)
- `scripts/phase22-staging-deploy.sh` was executed. It completed static preflight and stopped at prerequisite step 2 with: `PHASE 22 BLOCKED: Docker is not installed.`
- `php artisan about` was attempted and failed because `vendor/autoload.php` does not exist.
- `scripts/verify-project.sh` completed with exit code 0.
- The host has PHP and Node, but does not have Composer, Docker, Docker Compose, MySQL/MariaDB, `.env`, `composer.lock` or `vendor`.
- PHP PDO exists, but PDO SQLite and PDO MySQL are absent. Required local PHP extensions including mbstring, curl, XML, ZIP, intl and bcmath are also absent.
- Static PHP, JavaScript and shell syntax checks and YAML/JSON/XML parsing were performed; no runtime acceptance result is inferred from these checks.
