compose/pkg/api
Guillaume Lours 674010661a feat(hooks): retain failed pre_start containers for post-mortem
A failing pre_start hook container is now retained (AutoRemove: false)
so operators can run 'docker logs <id>' and 'docker ps -a' to diagnose
the failure. On success the container is removed explicitly, mirroring
the old AutoRemove behaviour including anonymous volumes.

Before each pre_start run, stale hook containers from a previous failed
run are detected via project+service+HookLabel filters and force-removed
so they do not accumulate.

Changes:
- pkg/api/labels.go: add HookLabel (com.docker.compose.hook)
- pkg/compose/filters.go: add hookFilter helper
- pkg/compose/pre_start.go:
  - AutoRemove: false in createPreStartContainer
  - HookLabel added to container labels
  - runPreStartHook: explicit ContainerRemove on success; retain on failure
  - removeOrphanPreStartContainers: new helper called in runPreStart
- Tests: update all existing pre_start tests for the new flow; add
  feature tests (success removes, failure retains, orphan cleanup) and
  coverage-gap tests (lowestNumberedContainer, waitPreStart cancel,
  preStartResultErr, streamPreStartLogs error paths, old-API network
  paths, ExecCreate/Attach/Inspect errors, hookExitError branches)

Coverage after: hook.go 100%, pre_start.go most functions 100%
(was 89% and 64% respectively per Codecov delta).

Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
2026-08-20 18:57:02 +02:00
..
api.go api: RunOptions documents its partial embedding and its double life as ExecOptions 2026-08-20 12:32:25 +02:00
api_test.go Dedup pre_start hook images against service and each other 2026-07-30 10:40:06 +02:00
context.go Introduce abstractions to support SDK usage without requiring Docker CLI 2025-10-27 16:17:50 +01:00
env.go restore support for COMPOSE_COMPATIBILITY 2025-12-07 18:42:04 +01:00
errors.go move progress UI components into cmd 2025-11-12 11:17:28 +01:00
errors_test.go deps: remove deprecated github.com/pkg/errors 2023-09-29 06:28:58 +02:00
event.go add 'configured' event at the end of model configuration phase 2025-12-15 10:14:21 +01:00
labels.go feat(hooks): retain failed pre_start containers for post-mortem 2026-08-20 18:57:02 +02:00
labels_test.go golangci-lint: use gci formatter instead of goimports 2025-12-01 12:21:50 +01:00