Skip to content

Add pv service — containerized service management#24

Merged
munezaclovis merged 6 commits intomainfrom
feat/service-management
Mar 6, 2026
Merged

Add pv service — containerized service management#24
munezaclovis merged 6 commits intomainfrom
feat/service-management

Conversation

@munezaclovis
Copy link
Copy Markdown
Contributor

Summary

  • Adds pv service commands for managing backing services (MySQL, PostgreSQL, Redis, RustFS) via Colima + Docker Engine
  • Services are managed entirely through pv's CLI — users never interact with Docker or Colima directly
  • Integrates with pv link (auto-detect services from .env), pv doctor (health checks), pv install (Colima download), and pv uninstall (teardown)

New commands

  • pv service add <name> [version] — pull image, create container, wait healthy
  • pv service list — table with service, status, port, projects
  • pv service start/stop [service] — start/stop one or all
  • pv service remove <service> — stop + remove container, keep data
  • pv service destroy <service> — stop + remove + delete data (no prompt)
  • pv service status <service> — detailed info
  • pv service env [service] — print connection env vars
  • pv service logs <service> — tail container logs

Key decisions

  • MySQL defaults to latest tag when no version specified
  • pv service destroy has no confirmation prompt
  • Health checks use Docker's built-in HEALTHCHECK config
  • Port scheme: MySQL 33000+patch, PostgreSQL 54000+major, Redis 6379, RustFS 9000/9001

Test plan

  • go test ./... — all existing + new tests pass
  • Registry backward compat: old JSON without services field loads fine
  • Service definitions: port calculations, image names, env vars
  • Dotenv merge: replace in-place, append new, backup original
  • E2E: scripts/e2e/services.sh — full service lifecycle
  • E2E: scripts/e2e/service-link.sh — auto-wiring during pv link

Introduce `pv service` commands for managing backing services (MySQL,
PostgreSQL, Redis, RustFS) via Colima + Docker Engine. Users never
interact with Docker or Colima directly — pv manages everything.

Foundation:
- Config paths for services dir, Colima binary, Docker socket
- Registry extended with ServiceInstance, ProjectServices, service CRUD
- Service definitions with port schemes, health checks, env vars
- Dotenv read/write/merge helper for .env auto-wiring
- Colima binary management (download, start/stop, profile isolation)
- Docker Engine wrapper (container.CreateOpts with health config)

Commands:
- pv service add <name> [version] — pull image, create container, wait healthy
- pv service list — table with service, status, port, projects
- pv service start/stop [service] — start/stop one or all
- pv service remove <service> — stop + remove container, keep data
- pv service destroy <service> — stop + remove + delete data (no prompt)
- pv service status <service> — detailed info
- pv service env [service] — print connection env vars
- pv service logs <service> — tail container logs

Integrations:
- pv link: auto-detect services from .env, bind to project, create DB
- pv doctor: services health section (Colima, Docker, containers)
- pv install: download Colima binary alongside PHP
- pv uninstall: stop service containers and Colima before cleanup

Tests:
- Registry service CRUD + backward compat (old JSON loads fine)
- Service definitions: ports, images, container names, env vars
- Dotenv merge: replace in-place, append new, backup original
- E2E scripts for service lifecycle and auto-wiring
Service commands now skip container operations when Colima isn't
installed, allowing the registry plumbing to work independently.
This fixes E2E failures on GitHub Actions where Colima is not
available. Updated E2E assertions to match actual output patterns.
Colima release assets use different arch naming per platform:
- Darwin: colima-Darwin-arm64, colima-Darwin-x86_64
- Linux: colima-Linux-aarch64, colima-Linux-x86_64

The previous code mapped arm64 -> aarch64 unconditionally, which
produced a 404 on macOS (colima-Darwin-aarch64 doesn't exist).
Colima may be installed but unable to start (e.g. no virtualization
on GH Actions runners). Service add/start now degrade gracefully:
the service is registered in the registry even when the container
runtime is unavailable.

Also improved E2E script to print command output on failure for
better debugging, and added service diagnostics to the dump script.
macOS GH Actions runners don't support nested VMs, so Colima/Docker
can never run there. Service functionality is covered by unit tests.
- Add WebRoutes() to Service interface for *.pv.{tld} subdomain routing
- Generate Caddy reverse_proxy configs for service HTTP endpoints
- Rename rustfs service to s3 (image stays rustfs/rustfs under the hood)
- Add mail service backed by Mailpit (SMTP :1025, web UI :8025)
- Wire Caddy config regeneration into service add/remove/destroy
- Auto-detect MAIL_HOST in pv link for mail service binding
@munezaclovis munezaclovis merged commit 248dee6 into main Mar 6, 2026
2 checks passed
@munezaclovis munezaclovis deleted the feat/service-management branch March 6, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant