Skip to content

feat: multi-instance overlay pattern — kennung + port collision check#7

Merged
typelicious merged 5 commits into
mainfrom
feat/multi-instance-overlay-pattern
Jun 4, 2026
Merged

feat: multi-instance overlay pattern — kennung + port collision check#7
typelicious merged 5 commits into
mainfrom
feat/multi-instance-overlay-pattern

Conversation

@typelicious

Copy link
Copy Markdown
Contributor

Why

wp-test-env v2.0.0 already supports per-instance state via COMPOSE_PROJECT_NAME + COMPOSE_PROJECT_DIR, but it didn't:

  1. Codify the convention for overlays to declare their kennung
  2. Fail fast when overlays pick colliding ports
  3. Document how two overlays coexist on the same machine

Today we hit this in practice: deploying capacium-bridge for testing accidentally polluted the running elementeer test env because both use the same container names (default wptesting-*).

What changed

  • scripts/check-ports.sh (NEW) — pre-flight port collision check. Reads .env (or accepts arg ports). Probes Docker containers AND host processes (lsof / ss / netstat). Reports each occupied port + what holds it. Exit 1 + actionable resolution hints on collision.
  • scripts/setup.sh — calls check_ports() before docker compose up. Skipped on --fresh (own containers will be torn down anyway).
  • .env.example — documents the kennung convention in-line with concrete examples (elementeer-wptest, capacium-wptest).
  • docs/overlay-pattern.md (NEW) — codifies the convention: naming, port allocation table, required overlay structure, coexistence example, decision log.

Test plan

  • check-ports.sh detects existing wptesting-wordpress container on 8082 (verified locally)
  • check-ports.sh reports clear actionable error when port held by docker container vs host process
  • check-ports.sh passes when given known-unused ports (8999, 9000, 9001)
  • setup.sh's check_ports() correctly aborts before docker compose up when collision detected
  • Capacium-bridge-tests overlay can run on port 8083 in parallel with elementeer on 8082 (follow-up PR on capacium-bridge-tests)

André Lange added 2 commits June 3, 2026 21:58
wp-test-env v2.0.0 already supported per-instance state via
COMPOSE_PROJECT_NAME + COMPOSE_PROJECT_DIR, but it didn't:
1. Codify the "overlay declares its kennung" convention.
2. Fail fast when overlays pick colliding ports.
3. Document how two overlays coexist on the same machine.

This commit adds:

- `scripts/check-ports.sh` — pre-flight port collision check. Reads
  ports from .env (or accepts args). Probes Docker containers AND host
  processes (via lsof/ss/netstat). Reports each occupied port with what
  holds it. Exit 1 + actionable resolution hints on collision.

- `scripts/setup.sh` — calls check-ports.sh before `docker compose up`.
  Skipped on --fresh (own containers will be torn down anyway).

- `docs/overlay-pattern.md` — codifies the convention:
    * COMPOSE_PROJECT_NAME = "kennung" (kebab-case, `-wptest` suffix)
    * Port band table for sequential overlays
    * Required overlay structure
    * Coexistence example (elementeer + capacium running in parallel)
    * Decision log (why these choices)

- `.env.example` — documents the kennung convention in-line; adds
  capacium-wptest as a second concrete example next to elementeer.

This is the template-level foundation for letting plugin/theme overlays
ship their own `.env.overlay` with a unique kennung + port band, run
`check-ports.sh`, then `setup.sh` — coexisting cleanly with any other
overlay's stack on the same dev machine.

Verified locally:
- check-ports.sh detects existing wptesting-wordpress container holding 8082
- check-ports.sh passes when given unused ports (8999/9000/9001)
- setup.sh's check_ports() invocation correctly aborts when port taken
… in .env.example

Follow-up to the previous commit:
- setup.sh now calls check_ports() before docker compose up (skipped on
  --fresh since own containers will be torn down).
- .env.example documents the kennung convention in-line: kebab-case
  COMPOSE_PROJECT_NAME with `-wptest` suffix, distinct per overlay,
  e.g. `elementeer-wptest` vs `capacium-wptest`.

These two changes complete the template-level support for the overlay
pattern. Overlay setup scripts can now rely on:
- Their kennung being honored (COMPOSE_PROJECT_NAME applied via .env)
- Port collisions failing fast with a clear error before docker compose
  fights itself
@dev-bot-langevc dev-bot-langevc added enhancement New feature or request needs-triage labels Jun 3, 2026
André Lange added 3 commits June 3, 2026 22:05
…HEMES_DIR/UPLOADS_DIR

The previous multi-instance support (COMPOSE_PROJECT_NAME + COMPOSE_PROJECT_DIR)
isolated container names, networks, and Docker-managed volumes — but left
the HOST BIND MOUNTS pointing at ./plugins, ./themes, ./uploads
unconditionally. Two overlays sharing the same wp-test-env checkout
would mount the SAME host plugins/ dir into both wordpress containers
→ overlay A's plugin install pollutes overlay B's filesystem.

This commit fixes that:

- docker-compose.yml: bind-mount paths now use ${PLUGINS_DIR:-./plugins},
  ${THEMES_DIR:-./themes}, ${UPLOADS_DIR:-./uploads}. Default behavior
  for the first/primary instance is unchanged (uses repo-root dirs).

- .env.example: documents the new vars with a per-overlay example
  (envs/<name>/plugins) + explains why they exist (CRITICAL for isolation).

- scripts/setup.sh: creates the per-instance dirs on first run if they
  don't exist, and seeds PLUGINS_DIR with the canonical free plugin
  bundle from ./plugins so the overlay starts with a working baseline
  (Query Monitor, Debug Bar, User Switching, WP Importer).

Together with check-ports.sh (port collision pre-flight), wp-test-env
now provides genuine multi-instance isolation:
  - Distinct container/network/volume names (via COMPOSE_PROJECT_NAME)
  - Distinct state dirs (via COMPOSE_PROJECT_DIR)
  - Distinct plugins/themes/uploads bind mounts (via *_DIR vars)
  - Distinct ports (via PORT vars + check-ports.sh)

Verified by running capacium-bridge-tests overlay alongside elementeer
overlay on the same machine — no cross-pollution, both stacks usable.
…erlays only)

Two related hygiene fixes:

1. AGENTS.md (NEW, top-level) — clear guidance for AI dev agents and
   humans landing here: this is a template, you consume it from your
   project's overlay, you don't fork it to add project-specific stuff.
   Includes:
   - Visual diagram of template → overlay relationship
   - Minimum `.env.overlay` example with kennung + port band + paths
   - Minimum `setup-overlay.sh` shape
   - Common pitfalls table (e.g. `docker exec wptesting-wordpress`
     blindly hitting whatever overlay holds the default container name)
   - "Can I change this in the template?" decision table
   - Reference to capacium-bridge-tests + elementeer-ops/wp-testing-env
     as real-world overlay examples

2. .gitignore + remove tracked plugin zips: the 4 free-tool zips
   (Query Monitor, Debug Bar, User Switching, WP Importer) that lived
   in plugins/ were tracked in git. The template must stay GENERIC —
   it shouldn't bake in a particular plugin selection. Overlays bring
   their own via config/plugins.yaml (which uses source: wordpress.org
   to fetch them at install time anyway).
   - .gitignore now excludes plugins/* but allows plugins/README.md
     as the dir marker
   - 4 zips removed via `git rm --cached`; remain on disk for any
     existing local checkouts that already had them

3. setup.sh: dropped the "seed plugins/ from ./plugins" logic that
   relied on the template having a plugins/ bundle. Now just creates
   the per-instance bind-mount dirs and lets the overlay's
   `setup-overlay.sh` populate them (via config/plugins.yaml install
   step or direct cp from the project source dir).

Verified with capacium-bridge-tests overlay: setup-overlay.sh creates
PLUGINS_DIR, runs base setup.sh, then overlay drops the bridge plugin
into the isolated dir — no reliance on template-shipped plugins.

@dev-bot-capacium dev-bot-capacium left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed locally with capacium-bridge-tests overlay running alongside elementeer's wptesting on the same machine — full isolation verified (distinct kennung, distinct ports, distinct plugins dir, no cross-pollution). AGENTS.md gives dev agents a clear hands-off-template / work-in-overlay rule. Approved via dev-bot.

@typelicious typelicious merged commit 18aa9d5 into main Jun 4, 2026
3 checks passed
@typelicious typelicious deleted the feat/multi-instance-overlay-pattern branch June 4, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request needs-triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants