Skip to content

Commit a84225b

Browse files
committed
Update deployment documentation and validate environment variables in CI/CD workflow
1 parent b90a50e commit a84225b

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

.github/workflows/cd.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ jobs:
4141
|| github.ref == 'refs/heads/develop' && 'staging'
4242
|| '' }}
4343
steps:
44+
- name: Validate GitHub Environment variables
45+
run: |
46+
set -euo pipefail
47+
err() { echo "::error title=Missing environment variable::$1" >&2; exit 1; }
48+
[ -n "${{ vars.DEPLOY_PATH }}" ] || err "Set Variable DEPLOY_PATH on this job's GitHub Environment (e.g. /opt/paperscout). Settings → Environments → ${{ github.environment }} → Environment variables."
49+
[ -n "${{ vars.DEPLOY_BRANCH }}" ] || err "Set Variable DEPLOY_BRANCH (e.g. main or develop)."
50+
[ -n "${{ vars.HEALTH_PORT }}" ] || err "Set Variable HEALTH_PORT to the host port published for GET /health (see docker-compose / README; e.g. 9101). Without it the workflow builds http://localhost:/health and curl fails."
51+
4452
- name: Deploy via SSH
4553
uses: appleboy/ssh-action@v1
4654
with:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
- Documentation: deployment URLs (Slack Request URL behind nginx `/paperscout/`), clone URL in server setup, staging-style placeholders.
1818
- `db-backup.yml`: matrix parallel backups for `staging` / `production` using environment-level SSH secrets; uploads under `gs://insights-db-backups/paperscout/<environment>/` with unique temp files and object keys (UTC timestamp + `run_id` + `run_attempt` + environment); `EXIT` trap removes temp dump on failure. `SERVER_SETUP` restore examples updated (`--no-owner`, listing/copy by object name).
19+
- `cd.yml`: validate `DEPLOY_PATH`, `DEPLOY_BRANCH`, and `HEALTH_PORT` GitHub Environment variables before SSH so missing `HEALTH_PORT` fails with a clear error instead of curling `http://localhost:/health`.
1920

2021
## [0.1.0] - 2026-05-05
2122

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,17 @@ Push to develop → CI tests → SSH into staging → git pull --ff-only → doc
154154

155155
#### Configure GitHub Environments
156156

157-
Create two environments under **Settings → Environments**: `production` and `staging`. Both use the **same secret names** (different values per environment) and a small set of per-environment **Variables**:
157+
Create two environments under **Settings → Environments**: `production` and `staging`. Both use the **same secret names** (different values per environment) and **these Environment variables are required for CD** — if `HEALTH_PORT` is omitted, the workflow builds `http://localhost:/health` and the deploy fails at the health check:
158158

159159
| Type | Name | Production | Staging |
160160
| -------- | ---------------- | ----------------------- | --------------------------------- |
161161
| Secret | `SERVER_HOST` | prod host / IP | staging host / IP |
162162
| Secret | `SERVER_USER` | deploy user | deploy user |
163163
| Secret | `SERVER_SSH_KEY` | private key | private key |
164164
| Secret | `SERVER_PORT` | optional (default `22`) | optional (default `22`) |
165-
| Variable | `DEPLOY_PATH` | `/opt/paperscout` | `/opt/paperscout-staging` |
165+
| Variable | `DEPLOY_PATH` | `/opt/paperscout` | `/opt/paperscout` |
166166
| Variable | `DEPLOY_BRANCH` | `main` | `develop` |
167-
| Variable | `HEALTH_PORT` | `9101` | `9102` (or whatever staging maps) |
167+
| Variable | `HEALTH_PORT` | `9101` | `9101` (or whatever staging maps) |
168168

169169
The workflow picks the environment from the branch (`refs/heads/main``production`, `refs/heads/develop``staging`), so values like `DEPLOY_PATH` and `HEALTH_PORT` are not hard-coded in the YAML.
170170

@@ -184,11 +184,11 @@ curl -sf http://localhost:9101/health
184184
On the **staging** server (separate host or separate path on the same host; must match the `staging` environment's `DEPLOY_PATH` and expose `/health` on `HEALTH_PORT`):
185185

186186
```bash
187-
git clone -b develop https://github.com/cppalliance/paperscout.git /opt/paperscout-staging
188-
cd /opt/paperscout-staging
187+
git clone -b develop https://github.com/cppalliance/paperscout.git /opt/paperscout
188+
cd /opt/paperscout
189189
cp .env.example .env # use staging credentials / DB / Slack app as appropriate
190190
docker compose up -d --build
191-
curl -sf http://localhost:9102/health
191+
curl -sf http://localhost:9101/health
192192
```
193193

194194
See [`deploy/SERVER_SETUP.md`](deploy/SERVER_SETUP.md) for the full Ubuntu 22.04 provisioning guide, and [`.github/workflows/cd.yml`](.github/workflows/cd.yml) for the CD pipeline.
@@ -444,6 +444,7 @@ The `.github/workflows/cd.yml` workflow runs on push to `main` or `develop` (and
444444
1. **Test** — single Python 3.12 pytest run as a gate (re-uses the same coverage threshold as CI).
445445
2. **Deploy** — single environment-driven job:
446446
- Selects the **GitHub Environment** from the branch (`main``production`, `develop``staging`).
447+
- **Validates** Environment variables `DEPLOY_PATH`, `DEPLOY_BRANCH`, and **`HEALTH_PORT`** are non-empty (missing `HEALTH_PORT` produces an invalid health URL and fails the job immediately with an actionable error).
447448
- SSHes using the environment-scoped secrets (`SERVER_HOST`, `SERVER_USER`, `SERVER_SSH_KEY`, optional `SERVER_PORT`).
448449
- Reads per-environment **variables** (`DEPLOY_PATH`, `DEPLOY_BRANCH`, `HEALTH_PORT`) so the same workflow targets prod or staging without code changes.
449450
- Runs `git fetch` + `git checkout` + `git pull --ff-only` against `DEPLOY_BRANCH` to keep deploys deterministic, then `docker compose up -d --build paperscout`.

deploy/SERVER_SETUP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ docker compose logs -f paperscout
231231
If you use a **separate** staging deployment (second clone path and GitHub Environment `staging`), typical placeholders are:
232232

233233
- TLS / DNS: `sudo certbot --nginx -d staging.example.org` (replace with your real staging hostname when provisioning).
234-
- Health check on the staging machine after mapping ports (see README CD table): `curl -sf http://localhost:9102/health` — use whatever port your staging compose publishes for health instead of `9102` if different.
234+
- Health check on the staging machine after mapping ports (see README CD table): `curl -sf http://localhost:9101/health`.
235235
- Slack **Request URL** when nginx proxies under `/paperscout/`: `https://staging.example.org/paperscout/slack/events`.
236236

237237
---

0 commit comments

Comments
 (0)