hyperdx/docker-compose.dev.yml
Warren Lee 6e8ddd3736
feat: isolate dev environment for multi-agent worktree support (#1994)
## Summary
- Isolate dev, E2E, and integration test environments so multiple git worktrees can run all three simultaneously without port conflicts
- Each worktree gets a deterministic slot (0-99) with unique port ranges: dev (30100-31199), E2E (20320-21399), CI integration (14320-40098)
- Dev portal dashboard (http://localhost:9900) auto-discovers all running stacks, streams logs, and provides a History tab for past run logs

## Port Isolation

| Environment | Port Range | Project Name |
|---|---|---|
| Dev stack | 30100-31199 | `hdx-dev-<slot>` |
| E2E tests | 20320-21399 | `e2e-<slot>` |
| CI integration | 14320-40098 | `int-<slot>` |

All three can run simultaneously from the same worktree with zero port conflicts.

## Dev Portal Features

**Live tab:**
- Auto-discovers dev, E2E, and integration Docker containers + local services (API, App)
- Groups all environments for the same worktree into a single card
- SSE log streaming with ANSI color rendering, capped at 5000 lines
- Auto-starts in background from `make dev`, `make dev-e2e`, `make dev-int`

**History tab:**
- Logs archived to `~/.config/hyperdx/dev-slots/<slot>/history/` on exit (instead of deleted)
- Each archived run includes `meta.json` with worktree/branch metadata
- Grouped by worktree with collapsible cards, search by worktree/branch
- View any past log file in the same log panel, delete individual runs or clear all
- Custom dark-themed confirm modal (no native browser dialogs)

## What Changed

- **`scripts/dev-env.sh`** — Slot-based port assignments, portal auto-start, log archival on exit
- **`scripts/test-e2e.sh`** — E2E port range (20320-21399), log capture via `tee`, portal auto-start, log archival
- **`scripts/ensure-dev-portal.sh`** — Shared singleton portal launcher (works sourced or executed)
- **`scripts/dev-portal/server.js`** — Discovery for dev/E2E/CI containers, history API (list/read/delete), local service port probing
- **`scripts/dev-portal/index.html`** — Live/History tabs, worktree-grouped cards, search, collapse/expand, custom confirm modal, ANSI color log rendering
- **`docker-compose.dev.yml`** — Parameterized ports/volumes/project name with `hdx.dev.*` labels
- **`packages/app/tests/e2e/docker-compose.yml`** — Updated to new E2E port defaults
- **`Makefile`** — `dev-int`/`dev-e2e` targets with log capture + portal auto-start; `dev-portal-stop`; `dev-clean` stops everything + wipes slot data
- **`.env` files** — Ports use `${VAR:-default}` syntax across dev, E2E, and CI environments
- **`agent_docs/development.md`** — Full documentation for isolation, port tables, E2E/CI port ranges

## How to Use

```bash
# Start dev stack (auto-starts portal)
make dev

# Run E2E tests (auto-starts portal, separate ports)
make dev-e2e FILE=navigation

# Run integration tests (auto-starts portal, separate ports)
make dev-int FILE=alerts

# All three can run simultaneously from the same worktree
# Portal at http://localhost:9900 shows everything

# Stop portal
make dev-portal-stop

# Clean up everything (all stacks + portal + history)
make dev-clean
```

## Dev Portal

<img width="1692" height="944" alt="image" src="https://github.com/user-attachments/assets/6ed388a3-43bc-4552-aa8d-688077b79fb7" />

<img width="1689" height="935" alt="image" src="https://github.com/user-attachments/assets/8677a138-0a40-4746-93ed-3b355c8bd45e" />

## Test Plan
- [x] Run `make dev` — verify services start with slot-assigned ports
- [x] Run `make dev` in a second worktree — verify different ports, no conflicts
- [x] Run `make dev-e2e` and `make dev-int` simultaneously — no port conflicts
- [x] Open http://localhost:9900 — verify all stacks grouped by worktree
- [x] Click a service to view logs — verify ANSI colors render correctly
- [x] Stop a stack — verify logs archived to History tab with correct worktree
- [x] History tab — search, collapse/expand, view archived logs, delete
- [x] `make dev-clean` — stops everything, wipes slot data and history
2026-03-31 18:24:24 +00:00

148 lines
5.5 KiB
YAML

name: ${HDX_DEV_PROJECT:-hdx-oss-dev}
x-hdx-labels: &hdx-labels
hdx.dev.slot: '${HDX_DEV_SLOT:-0}'
hdx.dev.branch: '${HDX_DEV_BRANCH:-unknown}'
hdx.dev.worktree: '${HDX_DEV_WORKTREE:-unknown}'
services:
db:
labels:
<<: *hdx-labels
hdx.dev.service: mongodb
hdx.dev.port: '${HDX_DEV_MONGO_PORT:-27017}'
image: mongo:5.0.32-focal
volumes:
- .volumes/db_dev_${HDX_DEV_SLOT:-0}:/data/db
ports:
- '${HDX_DEV_MONGO_PORT:-27017}:27017'
networks:
- internal
otel-collector:
labels:
<<: *hdx-labels
hdx.dev.service: otel-collector
hdx.dev.port: '${HDX_DEV_OTEL_HTTP_PORT:-4318}'
hdx.dev.url: 'http://localhost:${HDX_DEV_OTEL_HTTP_PORT:-4318}'
build:
context: .
dockerfile: docker/otel-collector/Dockerfile
target: dev
environment:
CLICKHOUSE_ENDPOINT: 'tcp://ch-server:9000?dial_timeout=10s'
CLICKHOUSE_PROMETHEUS_METRICS_ENDPOINT: 'ch-server:9363'
HYPERDX_OTEL_EXPORTER_CLICKHOUSE_DATABASE: ${HYPERDX_OTEL_EXPORTER_CLICKHOUSE_DATABASE}
HYPERDX_API_KEY: ${HYPERDX_API_KEY}
HYPERDX_LOG_LEVEL: ${HYPERDX_LOG_LEVEL}
OPAMP_SERVER_URL: 'http://host.docker.internal:${HYPERDX_OPAMP_PORT:-4320}'
CUSTOM_OTELCOL_CONFIG_FILE: '/etc/otelcol-contrib/custom.config.yaml'
# Uncomment to enable stdout logging for the OTel collector
OTEL_SUPERVISOR_LOGS: 'true'
HYPERDX_OTEL_EXPORTER_TABLES_TTL: '24h'
volumes:
- ./docker/otel-collector/config.yaml:/etc/otelcol-contrib/config.yaml
- ./docker/otel-collector/supervisor_docker.yaml.tmpl:/etc/otel/supervisor.yaml.tmpl
# Add a custom config file
- ./docker/otel-collector/custom.config.yaml:/etc/otelcol-contrib/custom.config.yaml
ports:
- '${HDX_DEV_OTEL_HEALTH_PORT:-13133}:13133' # health_check extension
- '${HDX_DEV_OTEL_GRPC_PORT:-4317}:4317' # OTLP gRPC receiver
- '${HDX_DEV_OTEL_HTTP_PORT:-4318}:4318' # OTLP http receiver
- '${HDX_DEV_OTEL_METRICS_PORT:-8888}:8888' # metrics extension
restart: always
networks:
- internal
depends_on:
ch-server:
condition: service_healthy
otel-collector-json:
labels:
<<: *hdx-labels
hdx.dev.service: otel-collector-json
hdx.dev.port: '${HDX_DEV_OTEL_JSON_HTTP_PORT:-14318}'
hdx.dev.url: 'http://localhost:${HDX_DEV_OTEL_JSON_HTTP_PORT:-14318}'
build:
context: .
dockerfile: docker/otel-collector/Dockerfile
target: dev
environment:
CLICKHOUSE_ENDPOINT: 'tcp://ch-server:9000?dial_timeout=10s'
CLICKHOUSE_PROMETHEUS_METRICS_ENDPOINT: 'ch-server:9363'
HYPERDX_OTEL_EXPORTER_CLICKHOUSE_DATABASE: 'otel_json'
HYPERDX_OTEL_EXPORTER_CREATE_LEGACY_SCHEMA: 'true'
HYPERDX_API_KEY: ${HYPERDX_API_KEY}
HYPERDX_LOG_LEVEL: ${HYPERDX_LOG_LEVEL}
OPAMP_SERVER_URL: 'http://host.docker.internal:${HYPERDX_OPAMP_PORT:-4320}'
CUSTOM_OTELCOL_CONFIG_FILE: '/etc/otelcol-contrib/custom.config.yaml'
# Uncomment to enable stdout logging for the OTel collector
OTEL_SUPERVISOR_LOGS: 'true'
# Uncomment to enable JSON schema in ClickHouse
# Be sure to also set BETA_CH_OTEL_JSON_SCHEMA_ENABLED to 'true' in ch-server
OTEL_AGENT_FEATURE_GATE_ARG: '--feature-gates=clickhouse.json'
volumes:
- ./docker/otel-collector/config.yaml:/etc/otelcol-contrib/config.yaml
- ./docker/otel-collector/supervisor_docker.yaml.tmpl:/etc/otel/supervisor.yaml.tmpl
ports:
- '${HDX_DEV_OTEL_JSON_HTTP_PORT:-14318}:4318' # OTLP http receiver
restart: always
networks:
- internal
depends_on:
ch-server:
condition: service_healthy
ch-server:
labels:
<<: *hdx-labels
hdx.dev.service: clickhouse
hdx.dev.port: '${HDX_DEV_CH_HTTP_PORT:-8123}'
hdx.dev.url: 'http://localhost:${HDX_DEV_CH_HTTP_PORT:-8123}'
image: clickhouse/clickhouse-server:26.1-alpine
ports:
- '${HDX_DEV_CH_HTTP_PORT:-8123}:8123' # http api
- '${HDX_DEV_CH_NATIVE_PORT:-9000}:9000' # native
environment:
# default settings
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
HYPERDX_OTEL_EXPORTER_CLICKHOUSE_DATABASE: ${HYPERDX_OTEL_EXPORTER_CLICKHOUSE_DATABASE}
# Set to 'true' to allow for proper OTel JSON Schema creation
# Be sure to also set the OTEL_AGENT_FEATURE_GATE_ARG env in otel-collector
# BETA_CH_OTEL_JSON_SCHEMA_ENABLED: 'true'
volumes:
- ./docker/clickhouse/local/config.xml:/etc/clickhouse-server/config.xml
- ./docker/clickhouse/local/users.xml:/etc/clickhouse-server/users.xml
- .volumes/ch_data_dev_${HDX_DEV_SLOT:-0}:/var/lib/clickhouse
- .volumes/ch_logs_dev_${HDX_DEV_SLOT:-0}:/var/log/clickhouse-server
restart: on-failure
networks:
- internal
healthcheck:
test:
wget -O /dev/null --no-verbose --tries=1 http://127.0.0.1:8123/ping ||
exit 1
interval: 1s
timeout: 1s
retries: 60
# nginx:
# image: nginx:alpine
# ports:
# - '4040:4040'
# volumes:
# - ./proxy/nginx/nginx.conf.template:/etc/nginx/templates/default.conf.template:ro
# environment:
# HYPERDX_BASE_PATH: ${HYPERDX_BASE_PATH:-/}
# network_mode: host
# restart: always
# traefik:
# image: traefik:latest
# ports:
# - '4040:4040'
# volumes:
# - ./proxy/traefik/traefik.yml:/etc/traefik/traefik.yml:ro
# - ./proxy/traefik/config.yml:/etc/traefik/dynamic/config.yml:ro
# environment:
# HYPERDX_BASE_PATH: ${HYPERDX_BASE_PATH:-/}
# network_mode: host
# restart: always
networks:
internal: