Move the documentation to the line that ships, and correct it against the code
The docs lived on one lineage and the fleet code on another. That is why six pages described a shared fleet key as how an agent authenticates, why COLLECTOR-AUTH had to warn that the per-PC credential code was not in the repository it sat in, and why ADR-019 recorded a decision whose implementation was somewhere else. Documentation that cannot see the code it documents goes stale by construction, and no amount of editing fixes that. So the corpus moves here: 84 files, 56 pages, 20 ADRs, the proposals, INDEX.md, llms.txt and both gates. Filenames are unchanged, because a wiki page name is derived from the filename and a rename breaks every link anybody saved. THE POINT OF THE MOVE IS THE CORRECTION IT ENABLES. Every caveat that said "not in this tree" was false the moment the files landed beside the code, so each was rewritten from what is actually here: - COLLECTOR-AUTH gained the real enroll request body, the two bounds on the unauthenticated route (per-IP rate limit, pending cap with stale rows dropped before a real PC is refused), and the rejected pending reason that binds to the endpoint identity rather than the nonce. - ADR-019 now describes an implementation that is present, including its tests, and says plainly that what remains is the FLEET migration, not the code. - proposals/device-identity claimed phase 1 was unbuilt. plugins/computers declares deviceid on the collector schema and prefers it over the older fallbacks. Corrected in the page, its summary and the index. WINDOWS/IIS IS NOW DOCUMENTED AS THE LEGACY PATH, per the product decision, and carefully: it is what production runs today. Every Windows page opens by saying it is supported, not for a new site, and where a new site should go instead. No procedure was cut - an operator on an IIS box at 2am needs these pages to work exactly as well tomorrow. MIGRATE-TOPOLOGY stops being a footnote and becomes the off-ramp, which is why it nearly doubled: what was there did not match how the Docker stack really works here. The Docker material that already lived on this line was kept and given ownership rather than buried under the ported Windows-centric prose: DEPLOY now describes the four services, the migrate service that runs the upgrade chain before api starts, TLS terminated by nginx, and the plugin count corrected from thirteen to seventeen - a number both lineages had wrong. ROADMAP is rewritten from evidence rather than memory: what has shipped, read out of the changelog, the ADRs and the manifests, and ahead of it exactly two items - finalize a distributed release and polish the setup wizard. PROJECT-MAP is generated and was stale; the GENERATOR was what was wrong. --check passes now. API-REFERENCE is retired to a pointer. /api/docs serves 573 operations with derived auth, query parameters and harvested examples, and a hand-written page competing with that is a liability. The file stays so its wiki page and its inbound links survive. AND THE MOVE TURNED ON A SCRUB THAT HAD NEVER RUN HERE. test_docs_publishable keys on docs/*.md, which this line did not have, so it skipped - its own comment predicted what would surface. Porting the corpus activated it and it found 48 lines that must not reach a published wiki: branch names abbreviating the site, assistant-tooling paths, the site name in two deployment pages, and an employee ID in a Windows path that the scrub does not even look for.
This commit is contained in:
@@ -1,177 +1,136 @@
|
||||
# Deploy ShopDB to Hyper-V VM
|
||||
<!-- docmeta
|
||||
purpose: howto
|
||||
audience: adopter, developer
|
||||
status: current
|
||||
summary: Put the Docker stack on a throwaway Windows VM to try it or rehearse a deploy, and what the helper script gets wrong.
|
||||
loadwith: none
|
||||
-->
|
||||
# Deploying the stack to a Windows VM
|
||||
|
||||
Quick guide to deploy the Docker stack to a Windows 11 Hyper-V VM.
|
||||
> **Where this sits:** a rehearsal, not a site. For a real site follow
|
||||
> [DEPLOY](../DEPLOY.md). To only LOOK at a build with no source at all,
|
||||
> [DEV-BUILD-TEST](../DEV-BUILD-TEST.md) pulls a published image and is one
|
||||
> script.
|
||||
|
||||
## Prerequisites on VM
|
||||
A Windows VM with Docker Desktop is the cheapest way to prove a deploy before
|
||||
doing it for real: the stack is identical to a site's, the VM can be reverted,
|
||||
and nothing on it matters. This page is the VM-specific part - getting the code
|
||||
there, the firewall, reaching it from the host. Everything else is
|
||||
[DEPLOY](../DEPLOY.md).
|
||||
|
||||
1. **Docker Desktop** installed and running
|
||||
2. **Git Bash** or **WSL** installed (for bash commands)
|
||||
3. **PowerShell** (already on Windows 11)
|
||||
## On the VM
|
||||
|
||||
## Step 1: Copy Files to VM
|
||||
1. **Docker Desktop**, installed and running.
|
||||
2. **Git Bash or WSL**, for the bash commands.
|
||||
3. Enough RAM given to Docker. The stack is MySQL plus a Python container plus
|
||||
nginx; 8GB to Docker is comfortable.
|
||||
|
||||
## Step 1: Get the code onto the VM
|
||||
|
||||
**Method A: Shared Folder**
|
||||
```powershell
|
||||
# On host PC, share the repo
|
||||
# Then on VM, copy from network share
|
||||
Copy-Item -Recurse \\host-pc\shopdb-flask C:\shopdb
|
||||
```
|
||||
# From a network share
|
||||
Copy-Item -Recurse \\<host>\shopdb-flask C:\shopdb
|
||||
|
||||
**Method B: Git Clone**
|
||||
```bash
|
||||
# On VM
|
||||
cd C:\
|
||||
git clone git@github.com:ge-aero/shopdb-flask.git
|
||||
cd shopdb-flask
|
||||
git checkout wj
|
||||
```
|
||||
# Or clone it
|
||||
git clone <your-remote>/shopdb-flask.git C:\shopdb
|
||||
|
||||
**Method C: Export/Import**
|
||||
```powershell
|
||||
# On host PC
|
||||
Compress-Archive -Path C:\Users\270015376\Documents\github\flask-shopdb -DestinationPath C:\shopdb-deploy.zip
|
||||
|
||||
# Copy shopdb-deploy.zip to VM, then on VM:
|
||||
# Or hand it over as a zip, which is what an isolated VM usually wants
|
||||
Expand-Archive -Path C:\shopdb-deploy.zip -DestinationPath C:\shopdb
|
||||
```
|
||||
|
||||
## Step 2: Run Deployment Script
|
||||
## Step 2: Bring it up
|
||||
|
||||
The pre-built path is the one to use on a VM: npm inside the image is slow and
|
||||
is the step most likely to fail behind a proxy. Build the frontend once on the
|
||||
host or on the VM, then build the image from it -
|
||||
[DOCKER-PREBUILT-APPROACH](DOCKER-PREBUILT-APPROACH.md).
|
||||
|
||||
```powershell
|
||||
# On VM, open PowerShell as Administrator
|
||||
cd C:\shopdb
|
||||
copy .env.example .env
|
||||
# Edit .env: SECRET_KEY, JWT_SECRET_KEY, MYSQL_ROOT_PASSWORD, MYSQL_PASSWORD,
|
||||
# CORS_ORIGINS. Generate a secret with:
|
||||
# python -c "import secrets; print(secrets.token_urlsafe(64))"
|
||||
|
||||
# Option 1: Quick deploy with defaults
|
||||
.\deploy-to-vm.ps1
|
||||
cd frontend; npm ci; npm run build; cd ..
|
||||
|
||||
# Option 2: Specify site name and password
|
||||
.\deploy-to-vm.ps1 -SiteName "west-jefferson" -AdminPassword "YourSecurePassword123!"
|
||||
|
||||
# Option 3: See all options
|
||||
.\deploy-to-vm.ps1 -Help
|
||||
```
|
||||
|
||||
## What the Script Does
|
||||
|
||||
1. [OK] Checks Docker Desktop is running
|
||||
2. [OK] Creates .env from template
|
||||
3. [OK] Builds frontend (if needed)
|
||||
4. [OK] Builds Docker images (2-3 minutes, offline packages)
|
||||
5. [OK] Starts all services (db + api + backup)
|
||||
6. [OK] Runs database migrations
|
||||
7. [OK] Sets admin password
|
||||
|
||||
## Manual Deployment (Alternative)
|
||||
|
||||
If you prefer to run commands manually:
|
||||
|
||||
```bash
|
||||
# 1. Create environment
|
||||
cp .env.docker-dev .env
|
||||
|
||||
# 2. Build frontend (if not already built)
|
||||
cd frontend
|
||||
npm ci
|
||||
npm run build
|
||||
cd ..
|
||||
|
||||
# 3. Build and start Docker stack
|
||||
docker compose -f docker-compose.prebuilt.yml -f docker-compose.backup.yml --profile backup build
|
||||
docker compose -f docker-compose.prebuilt.yml -f docker-compose.backup.yml --profile backup up -d
|
||||
|
||||
# 4. Initialize database
|
||||
docker exec flask-shopdb-api-1 flask db upgrade
|
||||
|
||||
# 5. Reset admin password (optional)
|
||||
docker exec flask-shopdb-db-1 mysql -uroot -proot-dev-password-not-for-production shopdb_flask -e \
|
||||
"UPDATE users SET passwordhash='scrypt:32768:8:1\$B4LhpPrM6qxijInK\$b99b47a0bb5fd45761a1823f401f70a3ceccf71a5d38dc433378aa07426ef8eaf7e679ff3dd7b0ce9772600f83368ac642e9419b9beaa49f87483318bae34547', failedlogins=0, lockeduntil=NULL WHERE username='admin';"
|
||||
# (Password is: admin)
|
||||
```
|
||||
|
||||
## Access
|
||||
The `migrate` service runs the schema, the plugin bootstrap and the seeders
|
||||
before `api` starts, so there is no separate migration step. Watch it with
|
||||
`docker compose logs migrate`.
|
||||
|
||||
**URL:** https://localhost:5001 (or https://vm-ip-address:5001 from host)
|
||||
|
||||
**Login:**
|
||||
- Username: `admin`
|
||||
- Password: Whatever you set in deploy script (default: `ChangeMe123!`)
|
||||
|
||||
## Verify Deployment
|
||||
Create the first admin at `https://localhost:5001/setup`, or headlessly:
|
||||
|
||||
```powershell
|
||||
# Check all services are running
|
||||
docker ps
|
||||
|
||||
# Should see:
|
||||
# - flask-shopdb-db-1
|
||||
# - flask-shopdb-api-1
|
||||
# - flask-shopdb-backup-store-1
|
||||
# - flask-shopdb-backup-watcher-1
|
||||
|
||||
# View logs
|
||||
docker logs -f flask-shopdb-api-1
|
||||
|
||||
# Test backup
|
||||
# Go to https://localhost:5001/settings/shopdbbackups
|
||||
# Click "Back Up Now"
|
||||
# Wait 30 seconds, should show as "Checked"
|
||||
docker compose exec api flask seed admin --username admin --email admin@example.com
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
The password is generated and printed once.
|
||||
|
||||
**Docker not running:**
|
||||
```powershell
|
||||
# Start Docker Desktop manually
|
||||
& "C:\Program Files\Docker\Docker\Docker Desktop.exe"
|
||||
Start-Sleep -Seconds 30
|
||||
```
|
||||
## Step 3: Reach it from the host
|
||||
|
||||
**Port 5001 already in use:**
|
||||
```powershell
|
||||
# Edit .env and change API_PORT
|
||||
# API_PORT=5002
|
||||
```
|
||||
|
||||
**Can't access from host PC:**
|
||||
```powershell
|
||||
# On VM, check Windows Firewall
|
||||
New-NetFirewallRule -DisplayName "ShopDB" -Direction Inbound -LocalPort 5001 -Protocol TCP -Action Allow
|
||||
```
|
||||
|
||||
**SSL certificate warnings:**
|
||||
- Normal for self-signed certs
|
||||
- Click "Advanced" -> "Proceed to localhost (unsafe)"
|
||||
Then `https://<vm-ip>:5001` from the host. The certificate is self-signed until
|
||||
you replace the pair in `certs/`, so the browser warns; that is expected on a
|
||||
VM.
|
||||
|
||||
## Stop/Start
|
||||
`CORS_ORIGINS` is an exact origin match, so it has to name the address the
|
||||
browser really uses. Reaching the VM by IP while `CORS_ORIGINS` names
|
||||
`localhost` is the usual cause of "the page loads and every request fails".
|
||||
|
||||
## About `deploy-to-vm.ps1`
|
||||
|
||||
The repository root carries `deploy-to-vm.ps1`, which wraps the above into eight
|
||||
steps with `-SiteName` and `-AdminPassword` parameters. **Read it before you run
|
||||
it.** As it stands it does not work on a clean clone, and neither problem is
|
||||
subtle:
|
||||
|
||||
- It copies `.env.docker-dev` to create `.env`. That file is not in the
|
||||
repository, so step 3 fails on a fresh checkout. Create `.env` from
|
||||
`.env.example` yourself first and the script skips that branch.
|
||||
- It addresses containers by the fixed names `flask-shopdb-api-1` and
|
||||
`flask-shopdb-db-1`. Compose names containers after the project, which is the
|
||||
directory name, so on a clone called `shopdb` those `docker exec` calls
|
||||
miss. Use `docker compose exec api` instead, or `docker compose ps` to see
|
||||
the real names.
|
||||
|
||||
It also runs only `flask db upgrade` for the database, which predates the
|
||||
`migrate` service and is now redundant rather than wrong.
|
||||
|
||||
Its default `-AdminPassword` is a literal in the file and therefore public.
|
||||
Pass your own, and never leave the default on anything reachable.
|
||||
|
||||
## Stop, start, update
|
||||
|
||||
```bash
|
||||
# Stop
|
||||
docker compose -f docker-compose.prebuilt.yml -f docker-compose.backup.yml down
|
||||
|
||||
# Start (after first deployment)
|
||||
docker compose -f docker-compose.prebuilt.yml -f docker-compose.backup.yml --profile backup up -d
|
||||
```
|
||||
|
||||
## Update After Code Changes
|
||||
`down` keeps the volumes. `down -v` deletes them, which is the database and
|
||||
`instance/` together, with no prompt.
|
||||
|
||||
To take new code:
|
||||
|
||||
```bash
|
||||
# 1. Pull latest code
|
||||
git pull origin wj
|
||||
|
||||
# 2. Rebuild frontend (if changed)
|
||||
cd frontend && npm run build && cd ..
|
||||
|
||||
# 3. Rebuild and restart
|
||||
git pull
|
||||
cd frontend; npm run build; cd ..
|
||||
docker compose -f docker-compose.prebuilt.yml -f docker-compose.backup.yml build
|
||||
docker compose -f docker-compose.prebuilt.yml -f docker-compose.backup.yml up -d
|
||||
```
|
||||
|
||||
## Offline Deployment Notes
|
||||
Rebuilding the frontend is not optional on the pre-built path: the image copies
|
||||
whatever is in `frontend/dist/`, so a skipped `npm run build` ships the old UI
|
||||
with no warning.
|
||||
|
||||
**This deployment works completely offline** because:
|
||||
- [OK] Frontend pre-built and checked into repo
|
||||
- [OK] Restic binary pre-downloaded (8.6MB in repo)
|
||||
- [OK] No npm/pip downloads during Docker build
|
||||
- [OK] All dependencies baked into images
|
||||
## Why this works with no network
|
||||
|
||||
Perfect for air-gapped or restricted network environments!
|
||||
With `frontend/dist/` already built and the Python wheels vendored, the image
|
||||
build downloads nothing, which is what makes the same procedure the rehearsal
|
||||
for [DEPLOY-AIRGAP](../DEPLOY-AIRGAP.md).
|
||||
|
||||
Reference in New Issue
Block a user