Skip to content

Commit 34a4214

Browse files
author
dream-hermes-agent
committed
v2 postgres: update idcreate runbooks for PostgreSQL + provisioning adapter
- idcreate-vrsctest-deploy.md: add postgres container, provisioning HTTP adapter, 4-container stack (postgres + provisioning + api + worker), PostgreSQL backup cmd, remove 'database is locked' troubleshooting entry (v1 only) - idcreate-vrsctest-update.md: update for postgres health wait, container list updated
1 parent 1c39317 commit 34a4214

2 files changed

Lines changed: 83 additions & 33 deletions

File tree

runbooks/idcreate-vrsctest-deploy.md

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ parent: Deployment
1616
**Service IP:** `10.200.0.14`
1717
**URL:** `https://idcreate.vrsctest.buildwithdreams.com`
1818

19+
> **v2 change (2026-05-15):** PostgreSQL replaces SQLite as the data store. A `provisioning` container runs the HTTP provisioning adapter. Total containers: 4 (`postgres`, `provisioning`, `api`, `worker`).
20+
1921
---
2022

2123
## Prerequisites
@@ -43,7 +45,7 @@ VRSC mainnet and VRSCTEST use identical octets on their respective networks —
4345

4446
---
4547

46-
## Architecture
48+
## Architecture (v2)
4749

4850
```
4951
Internet
@@ -60,19 +62,34 @@ Caddy (mains_blue_caddy-caddy-1)
6062
idcreate-api container (dev200_idcreate-api-1)
6163
at 10.200.0.14:5003 (net-vrsctest only)
6264
63-
▼ (background)
64-
idcreate-worker container (dev200_idcreate-worker-1)
65-
polls pending registrations, advances state
65+
├──────────────────────────────┐
66+
▼ ▼
67+
idcreate-worker idcreate-provisioning
68+
(background state machine) (Node.js HTTP adapter)
69+
│ │
70+
▼ ▼
71+
PostgreSQL 16-alpine svc-provisioning scripts
72+
dev200_idcreate-postgres-1 (provisioning/engine.py)
73+
5432 (host: 127.0.0.1:5432)
6674
6775
68-
VRSCTEST verusd daemon at 10.200.0.11:18842
76+
VRSCTEST verusd daemon at 10.200.0.11:18843
6977
```
7078

71-
> **Caddy is dual-homed.** It is already connected to `net-vrsctest` from the qrcodes deployment (playbook `37`). No network changes needed for this deployment.
79+
---
80+
81+
## Containers (v2)
82+
83+
| Container | Service | IP | Port |
84+
|---|---|---|---|
85+
| `dev200_idcreate-postgres-1` | PostgreSQL 16-alpine | auto | `5432` (host: `127.0.0.1:5432`) |
86+
| `dev200_idcreate-provisioning-1` | Node.js provisioning scripts | auto | `5055` (host: `127.0.0.1:5055`) |
87+
| `dev200_idcreate-api-1` | FastAPI | `10.200.0.14` | `5003` (host: `127.0.0.1:5003`) |
88+
| `dev200_idcreate-worker-1` | Polling worker | auto | — (internal) |
7289

7390
---
7491

75-
## Environment Variables Written by Playbook 41
92+
## Environment Variables Set by Playbook 41
7693

7794
Playbook `41-idcreate-deploy.yml` reads VRSCTEST RPC credentials from `~/docker-verusd/vrsctest/data_dir/vrsctest.conf` and writes these to `~/svc-idcreate/.env`:
7895

@@ -86,18 +103,18 @@ verusd_vrsc_rpc_port=18843
86103
verusd_vrsc_rpc_host=10.200.0.11
87104
```
88105

89-
> **SFConstants mapping:** The VRSCTEST chain hijacks the `DAEMON_VERUSD_VRSC` slot in `SFConstants.py` via `NATIVE_COIN="VRSCTEST"`. There is no separate VRSCTEST daemon slot.
90-
91-
---
92-
93-
## Containers
106+
**New in v2 (added by playbook 41):**
94107

95-
| Container | Service | IP | Port |
96-
|---|---|---|---|
97-
| `dev200_idcreate-api-1` | FastAPI | `10.200.0.14` | `5003` (host: `127.0.0.1:5003`) |
98-
| `dev200_idcreate-worker-1` | Polling worker | `10.200.0.14` | — (internal) |
108+
```
109+
DATABASE_URL=postgresql://idcreate:<auto-generated-password>@postgres:5432/idcreate
110+
PROVISIONING_ADAPTER_MODE=http
111+
PROVISIONING_SERVICE_URL=http://127.0.0.1:5055
112+
PROVISIONING_HTTP_TIMEOUT_SECONDS=10
113+
PROVISIONING_RETRY_COUNT=1
114+
PROVISIONING_LOG_LEVEL=INFO
115+
```
99116

100-
No provisioning service — not ready yet. Focus is on the id creation base Python service.
117+
> **SFConstants mapping:** The VRSCTEST chain hijacks the `DAEMON_VERUSD_VRSC` slot in `SFConstants.py` via `NATIVE_COIN="VRSCTEST"`. There is no separate VRSCTEST daemon slot.
101118
102119
---
103120

@@ -135,15 +152,17 @@ Delegate: ansible-playbook -i inventory.ini playbooks/41-idcreate-deploy.yml
135152

136153
This playbook:
137154
1. Reads VRSCTEST RPC credentials from `~/docker-verusd/vrsctest/data_dir/vrsctest.conf`
138-
2. Writes `~/svc-idcreate/.env` with all required vars (RPC, NATIVE_COIN, etc.)
139-
3. Removes any existing containers (`dev200_idcreate-api-1`, `dev200_idcreate-worker-1`)
140-
4. Writes `docker-compose.yml` targeting `net-vrsctest` at IP `10.200.0.14`
141-
5. Runs `docker compose up -d --force-recreate`
142-
6. Waits for api container to appear in `docker ps`
155+
2. Writes `~/svc-idcreate/.env` with all required vars (RPC, NATIVE_COIN, DATABASE_URL, provisioning adapter, etc.)
156+
3. Auto-generates a strong PostgreSQL password and writes it to `DATABASE_URL`
157+
4. Removes any existing containers
158+
5. Writes `docker-compose.yml` with 4 services: postgres + provisioning + api + worker
159+
6. Runs `docker compose up -d --force-recreate`
160+
7. Waits for postgres container to become healthy (`pg_isready`)
161+
8. Waits for api container to appear in `docker ps`
143162

144-
> If `.env` already exists, step 1 (copy from env.sample) is skipped and RPC vars are updated in place — safe to re-run.
163+
> If `.env` already exists, step 1 (copy from env.sample) is skipped and all vars are updated in place — safe to re-run.
145164
146-
### Step 3.5 — Issue API key
165+
### Step 3.5 — Issue API key (if not already set)
147166

148167
```
149168
Delegate: ansible-playbook -i inventory.ini playbooks/43-idcreate-add-api-key.yml
@@ -155,8 +174,8 @@ This playbook:
155174
3. Prints the key to the ansible output — **copy it now**, it will not be shown again
156175

157176
> After running this, you **must restart the containers** for the new env var to take effect:
158-
> ```bash
159-
> ssh bwd "cd ~/svc-idcreate && docker compose -p dev200_idcreate restart"
177+
> ```
178+
> Delegate: ansible-playbook -i inventory.ini playbooks/47-idcreate-restart.yml
160179
> ```
161180
162181
### Step 4 — Add Caddy route
@@ -165,7 +184,7 @@ This playbook:
165184
Delegate: ansible-playbook -i inventory.ini playbooks/42-idcreate-caddy-route.yml
166185
```
167186
168-
This playbook:
187+
This playbook (unchanged in v2):
169188
1. **Pre-flight check** — verifies Caddy is connected to `net-vrsctest`; aborts if missing
170189
2. Appends `idcreate.vrsctest.buildwithdreams.com` route block to the host Caddyfile using `blockinfile`
171190
3. Copies the updated Caddyfile into the container (`docker cp` — needed because the container mount is read-only)
@@ -187,14 +206,34 @@ Expected: `HTTP/2 200` from the FastAPI service.
187206

188207
To verify container health from the server:
189208
```bash
190-
ssh bwd "docker ps | grep idcreate"
209+
ssh bwd "docker ps | grep dev200_idcreate"
191210
ssh bwd "curl -s http://10.200.0.14:5003/health"
192211
```
193212

213+
To verify PostgreSQL is running:
214+
```bash
215+
ssh bwd "docker ps | grep postgres"
216+
ssh bwd "docker exec dev200_idcreate-postgres-1 pg_isready -U idcreate -d idcreate"
217+
```
218+
194219
To check logs:
195220
```bash
196221
ssh bwd "docker logs dev200_idcreate-api-1 --tail 50"
197222
ssh bwd "docker logs dev200_idcreate-worker-1 --tail 50"
223+
ssh bwd "docker logs dev200_idcreate-postgres-1 --tail 20"
224+
```
225+
226+
---
227+
228+
## PostgreSQL Backup
229+
230+
Compose stores DB data on volume `idcreate_postgres_data`.
231+
232+
Recommended: periodic host-level volume snapshots, keep at least daily backups, keep longer retention for operational audits.
233+
234+
Example backup command:
235+
```bash
236+
ssh bwd "cd ~/svc-idcreate && docker compose -p dev200_idcreate exec -T postgres pg_dump -U idcreate -d idcreate > idcreate_backup.sql"
198237
```
199238

200239
---
@@ -206,14 +245,16 @@ ssh bwd "docker logs dev200_idcreate-worker-1 --tail 50"
206245
| `502 Bad Gateway` | Caddy not on `net-vrsctest` | Run `37-qrcodes-caddy-network.yml` (should already be done) |
207246
| `Connection refused` | idcreate container not running | Run `41-idcreate-deploy.yml`; check `docker logs dev200_idcreate-api-1` |
208247
| `500 Internal Server Error` | RPC connection failed | Verify VRSCTEST daemon running; check `docker logs dev200_idcreate-api-1` for RPC errors |
248+
| `database is locked` (v1 only) | SQLite concurrent write conflict | Upgrade to v2 — PostgreSQL handles concurrent access |
209249
| `curl: (6) Could not resolve host` | DNS not propagated | Wait 5-10 minutes for Let's Encrypt DNS propagation |
210250
| Container keeps restarting | Health check failing or bad env vars | `docker logs dev200_idcreate-api-1`; verify `.env` has correct RPC port and credentials |
211-
| Route not responding | Caddyfile stale | Run `42-idcreate-caddy-route.yml` again to reload |
251+
| PostgreSQL container not healthy | postgres not ready yet | Wait up to 150s; check `docker logs dev200_idcreate-postgres-1` |
212252

213253
**Container restart loop:**
214254
```bash
215-
ssh bwd "docker rm -f dev200_idcreate-api-1 dev200_idcreate-worker-1"
255+
ssh bwd "cd ~/svc-idcreate && docker compose -p dev200_idcreate down"
216256
# Then re-run Step 3
257+
Delegate: ansible-playbook -i inventory.ini playbooks/41-idcreate-deploy.yml
217258
```
218259

219260
**RPC connection refused — common cause:**
@@ -252,7 +293,7 @@ Delegate: ansible-playbook -i inventory.ini playbooks/42-idcreate-caddy-route.ym
252293
|---|---|---|
253294
| `39` | `39-idcreate-clone.yml` | Clone repo |
254295
| `40` | `40-idcreate-build.yml` | Build Docker image |
255-
| `41` | `41-idcreate-deploy.yml` | Deploy api+worker on `net-vrsctest` at `10.200.0.14`; writes `.env` |
296+
| `41` | `41-idcreate-deploy.yml` | Deploy full stack (postgres + provisioning + api + worker) |
256297
| `42` | `42-idcreate-caddy-route.yml` | Add HTTPS route in Caddy |
257298
| `43` | `43-idcreate-add-api-key.yml` | Generate and persist `REGISTRAR_API_KEYS` test key |
258299
| `08b` | `08b-start-vrsctest.yml` | Start VRSCTEST daemon (prereq) |
@@ -263,4 +304,5 @@ Delegate: ansible-playbook -i inventory.ini playbooks/42-idcreate-caddy-route.ym
263304

264305
## History
265306

266-
- **2026-04-29** — Created. Mirrors the qrcodes VRSCTEST deployment pattern. Deploys api + worker only; provisioning service excluded (not ready). VRSCTEST uses the `DAEMON_VERUSD_VRSC` slot via `NATIVE_COIN="VRSCTEST"` — no separate VRSCTEST slot in `SFConstants.py`.
307+
- **2026-04-29** — Created. Mirrors the qrcodes VRSCTEST deployment pattern. Deploys api + worker only; provisioning service excluded (not ready). VRSCTEST uses the `DAEMON_VERUSD_VRSC` slot via `NATIVE_COIN="VRSCTEST"`.
308+
- **2026-05-15** — v2 postgres migration. Replaces SQLite with PostgreSQL 16-alpine. Adds provisioning adapter in HTTP mode (`PROVISIONING_ADAPTER_MODE=http`). Total containers increases from 2 to 4. `database is locked` errors are resolved.

runbooks/idcreate-vrsctest-update.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ parent: Deployment
1616
**Service IP:** `10.200.0.14`
1717
**URL:** `https://idcreate.vrsctest.buildwithdreams.com`
1818

19+
> **v2 change (2026-05-15):** PostgreSQL container is now part of the stack. The update playbook waits for postgres to be healthy before declaring success. Total containers: 4.
20+
1921
---
2022

2123
## Prerequisites
@@ -41,7 +43,8 @@ This playbook (in order):
4143
4. **Stops** running containers
4244
5. **Rebuilds** `buildwithdreams/svc-idcreate:local` from latest code
4345
6. **Starts** containers with `docker compose up -d --force-recreate`
44-
7. **Verifies** api container appears in `docker ps`
46+
7. **Waits** for postgres container to become healthy (`pg_isready`)
47+
8. **Verifies** api container appears in `docker ps`
4548

4649
> `.env` is restored unconditionally after every pull. This is required because git operations can remove or replace untracked files during merge/rebase.
4750
@@ -64,6 +67,8 @@ ssh bwd "curl -s http://10.200.0.14:5003/health"
6467
```bash
6568
ssh bwd "docker logs dev200_idcreate-api-1 --tail 30"
6669
ssh bwd "docker logs dev200_idcreate-worker-1 --tail 30"
70+
ssh bwd "docker logs dev200_idcreate-postgres-1 --tail 20"
71+
ssh bwd "docker logs dev200_idcreate-provisioning-1 --tail 30"
6772
```
6873

6974
---
@@ -91,6 +96,7 @@ Common causes:
9196
| Symptom | Check | Fix |
9297
|---|---|---|
9398
| Container not starting | `docker logs dev200_idcreate-api-1` | Check for import errors or missing env vars |
99+
| PostgreSQL not healthy | `docker logs dev200_idcreate-postgres-1` | Check `pg_isready` output; disk space |
94100
| RPC unreachable | `docker logs dev200_idcreate-api-1` | Verify VRSCTEST daemon at `10.200.0.11:18843` is running |
95101
| .env missing | `ls ~/svc-idcreate/.env*` on server | `cp ~/.env.backup ~/.env` then restart |
96102
| Image missing | `docker images | grep svc-idcreate` | Run `40-idcreate-build.yml` first |
@@ -132,9 +138,11 @@ Delegate: ansible-playbook -i inventory.ini playbooks/45-idcreate-update.yml
132138
| `45` | `45-idcreate-update.yml` | Pull + rebuild + restart idcreate stack |
133139
| `40` | `40-idcreate-build.yml` | Build image (used by 45, rarely needed alone) |
134140
| `41` | `41-idcreate-deploy.yml` | Full deploy — writes `.env` fresh |
141+
| `47` | `47-idcreate-restart.yml` | Restart to pick up .env changes (includes postgres health wait) |
135142

136143
---
137144

138145
## History
139146

140147
- **2026-04-30** — Created. Pull/rebuild/restart pattern for svc-idcreate on VRSCTEST. `.env` is backed up before pull and restored unconditionally after to survive git merge side-effects.
148+
- **2026-05-15** — v2 postgres migration. PostgreSQL 16-alpine added to stack. Update playbook now waits for `postgres` container to be healthy before completing. `database is locked` errors from v1 are resolved.

0 commit comments

Comments
 (0)