ps, ls, top, port, volumes, events and viz only read the state of a
project: they need the Docker API, the list of the project's containers
and the concurrency bound, nothing else of composeService.
They now live in internal/inspect, which declares that need as a Backend
interface. composeService implements it in a new file of pkg/compose and
forwards the seven api.Inspector methods, so no other file of pkg/compose
changes, and neither does the behavior: the service-level tests stay in
pkg/compose and run unchanged through the forwarders.
The few tiny helpers the operations share with the rest of pkg/compose
(canonical container name, concurrency-limited errgroup, project filter)
are copied for now: the shared kernel they belong to is a later step.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
compose run only wrapped the start of its dependencies in the "run"
progress operation. The pull of the target service's image, and the
creation of the one-off container, happened once that operation was
closed, so the TTY display fell back to one plain line per event,
including every layer, instead of the compact in-place block.
Wrap the whole preparation in the operation.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Reproduces docker/compose#14287: a hook inheriting the service's
env_file (or declaring its own) runs without those variables.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Pure extraction, no behavior change: create() resolved the project
model, ensured images/models and external networks/volumes, observed
the daemon, and reconciled a Plan, all inline before calling
executePlan. That decision-making half is now its own function,
preparePlan, returning the canonical project, the daemon snapshot, and
the Plan — nothing is created, started, or otherwise touched by it.
This is Lot 1's last item (epic #14081): interactive up's eventual
create/start phase boundary needs to prepare the plan once, run the
Create phase, set up attach/printer/monitor, then run the Start phase
— which needs the plan and snapshot available between those steps,
not buried inside create()'s single call chain. create() itself is
unchanged in behavior, just now a two-line call into preparePlan
followed by the existing emitRunningEvents + executePlan.
Verified with the existing unit suite plus the create/up/down e2e
scenarios (TestLocalComposeUp, TestCreateIdempotentDefaultPlatform,
TestCreateIdempotentSharedImageMixedPlatforms, TestCreateRefusesJob,
TestCreateLocalMultiPlatformImage, TestUpWithAllResources) against a
locally built binary.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
A sync into a path that is also bind-mounted writes back to the host,
which the watcher sees as a new change and syncs again, looping
forever. isSync, which gates the bind mount check, missed sync+exec,
so only sync and sync+restart triggers were skipped with a warning.
Include sync+exec in isSync. This also makes initial_sync apply to
sync+exec triggers, as it does for the other sync+x actions.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
Grant access to SSH keys and sockets from build configuration and CLI
options, and authorize default agent forwarding, including implicit SSH
Git contexts. Serialize pathless SSH entries without an empty source so
Bake applies the agent entitlement check.
Grant read access to local cache imports and OCI layout contexts, and
write access to local cache exports. Match Bake's path and cache syntax
while excluding service, target and image references from filesystem grants.
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Buildx 0.37.2 enforces entitlements with rawjson progress, exposing missing
permissions in Compose's Bake invocation. Grant read access to Dockerfiles
and file secrets, including local Dockerfiles used with remote contexts,
and forward requested entitlements and host network access.
Deduplicate grants and preserve environment secrets and privileged builds.
Add regression coverage for the generated Bake configuration and arguments.
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Compose is now composed by embedding Lifecycle, Inspector, ImageManager,
Runner, Watcher and ProjectLoader. The method set of Compose is unchanged.
ProjectOptions.ToProject and configOptions.ToProject only need to load a
project, so they now depend on api.ProjectLoader.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
TestBuildTLS slept a fixed second after the dind daemon logged that it
listens, hoping the client certificates were written; poll for them
instead. TestForwardKeepsStreamingAfterHalfClose had 150ms of margin
between each chunk and the 300ms idle grace, which a loaded CI runner can
eat; use 100ms chunks against a 1s grace.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
pkg/compose still imported the keyboard library: it grabbed the terminal,
forwarded raw key events to the menu and released the terminal on exit.
The NavigationMenu now takes care of all of it through Open, Run and Close,
so the library no longer knows about keys or the terminal, and the menu
interface no longer exposes a third-party event type.
As a side effect, key handling no longer shares a goroutine with the
signal handling loop of `up`.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
pkg/compose imported cmd/formatter for the interactive keyboard menu of a
foreground up, so the library depended on the CLI. Define a NavigationMenu
interface (and a factory) in pkg/compose, satisfied by formatter.LogKeyboard,
and have the CLI inject it with the new WithNavigationMenu option. The terminal
code stays in cmd/formatter. Without the option no menu is displayed.
formatter.Feature moves to api.Feature so that both sides share the type, and
a depguard rule now forbids pkg/ and internal/ from importing cmd/.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The daemon's swarm mode cache, the provider variable-injection lock and
the log-stream drain bound now live on composeService, so several
services in one process (SDK users, tests) no longer share them.
startMx stays global on purpose: it protects port allocation in the
daemon, which instances sharing a daemon must still serialize.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Start and Stop guard a Watcher's own stopFn/errCh, yet the lock was a
package-level mutex shared by every Watcher in the process.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The log journal of a container is shared by all its runs, and a followed
log stream has no upper bound: it ends with the run in progress when it
opened. After a restart, compose opens a stream starting at the end of
the previous run (d834777e1), but a stream opened late, once the
container has restarted again (the restart delay is only 100ms, and the
event monitor or the daemon can be slower), also returns the next run's
lines, which that run's own stream then returns a second time.
The streams of one container now run one at a time, in start-event
order, and each starts right after the last line the previous ones
relayed. Line timestamps are the daemon's own, so no client clock is
involved. A stream opened in time still starts at the previous run's
end, as before. TTY containers, whose stream is not multiplexed, are
unchanged.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
When the inspection of an optional (required: false) dependency fails, the
dependency is reported as skipped and the wait succeeds. That also happened
when the failure came from the wait's context being done: a cancellation
was reported as a skipped dependency, and an expired deadline (the wait
timeout, or one inherited from the caller) was turned into a successful
wait, unlike the same deadline expiring between two polls.
A check failing while its context is done now reports "not done yet" for an
optional dependency, so that waitDependency decides what the end of the wait
means. Genuine inspection errors still skip the dependency, and a required
dependency is handled as before.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Shorten the doc comments added for the Docker Desktop credentials provider to what the code does not already say, and drop them from the tests.
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
Docker Hub credentials are now read first from the session of the account signed in to Docker Desktop, through the Docker Desktop secrets engine (github.com/docker/secrets-engine/client), and from the Docker CLI config file and its credential helpers otherwise. Other registries keep using the config file only.
The OAuth access token is passed as the password of the signed-in account, never as an IdentityToken, which containerd sends as a refresh token. It flows unchanged to the engine in X-Registry-Auth and through the OCI resolver as an OAuth password grant.
Compose falls back to the config file when Desktop is not running, nobody is signed in, the session is expired or about to expire, or the lookup fails (the last logged as a warning). The session is shared process wide, cached until shortly before it expires, and an unusable session is not asked for again. Lookups are bounded by a 5s timeout, as the SDK applies none by default.
Used by pull, push, publish, config --resolve-image-digests, oci:// remote resources and dry-run. The classic builder and use_api_socket keep config file credentials, as a short-lived token copied into a container would go stale.
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
Two independent reviews (Copilot CLI + a fresh-context agent) of the
previous commit converged on the same finding: execStartContainer's,
execRunPreStart's, and execRunPostStart's ctx.Err() guards still
claimed the TOCTOU window "cannot be closed" and deferred the real fix
to #14081 -- stale now that run()'s failedDependency check closes it
for a direct dependency before executeNode is ever reached. Reworded
to say what's actually still open: defense in depth for ctx canceled
by something other than a direct dependency (an unrelated branch of
the same plan, or an external cancellation).
Also: recordFailure stored the already-wrapped "dependency failed: %w"
error, compounding the prefix at every hop of a multi-node chain.
Store the original error instead, wrapping only the value returned
from this node's own goroutine.
And a stale reference to a test name that was never the one actually
added (TestExecutePlanFailedPreStartGatesStart, not ...GroupDoesNotRestart).
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Two review findings on the same root cause:
- docker-agent: a failing OpRunPreStart emitted a bare Error with no
preceding Working/Starting event, since triggersWorking only fires
on OpStartContainer. onNodeError now emits the group's Working event
first when it hasn't fired yet, keeping the progression well-formed.
- glours (following up on the docker-agent thread): worse than a
missing event -- OpStartContainer's own goroutine was unblocked by
<-done[dep.ID] and ran anyway, since close(done[node.ID]) races
ahead of errgroup's cancel() (same TOCTOU class as the ctx.Err()
guards already tracked under #14081, but deterministic here with the
default unset --parallel limiter: no semaphore wait gives cancel()
time to land first). It fired a second, spurious Starting right
after the sibling's Error, with no further event ever closing it.
Reproduced 143/143 iterations against this PR's own regression test.
run() now records each node's terminal error in a shared, mutex-guarded
map as it closes done[node.ID], and a dependent checks that map right
after its dependency wait, treating a genuine dependency failure
exactly like a context cancellation: no slot acquired, no event
emitted, its own failure recorded and propagated to its own
dependents the same way. This closes the event-ordering race outright
for this specific chain, rather than narrowing it like the existing
ctx.Err() guards -- those stay in place and still guard actual engine
calls, unrelated to event emission.
TestExecutePlanFailedPreStartGatesStart now asserts the full event
sequence (Creating, Created, Starting, Error — nothing after),
verified by reverting the executor.go fix locally and confirming the
test catches the reintroduced spurious Starting.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Same interim narrowing as execStartContainer and execRunPostStart: the
node hangs off the replica's create node, so when that create fails the
pre_start hooks could still fire in the window before errgroup cancels
the context. The structural fix stays tracked in #14081.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
docker-agent's review of the previous commit's fix correctly pointed
out that the ctx.Err() guard added to execStartContainer/execRunPostStart
narrows the race it targets but does not eliminate it: close(done[...])
still runs inside the failing node's own goroutine, strictly before
errgroup's cancel() on that goroutine's returned error. A dependent
unblocked from <-done[dep.ID] can observe ctx.Err() == nil for a brief
window even though its dependency just failed for a genuine reason.
This is exactly the structural gap the epic (#14081) already flagged
in its "failed-dependency semantics" comment before this PR existed:
the real fix carries each node's success/failure through what
dependents wait on (e.g. a chan error) instead of inferring it from
ctx.Err(), uniformly across every operation type - including the
already-merged execCreateHookContainer, which has the same limit.
That is a dedicated brick of the executor lot, not squeezed into this
PR's diff.
No behavior change: this documents the residual window explicitly at
both guard sites and in the regression test, so the next reader (and
the next PR) doesn't mistake "narrows" for "closes".
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
A node's done-channel closes strictly before errgroup cancels its
derived context on that same error - the close happens synchronously
inside the failing node's goroutine, ctx cancellation only after it
returns. A dependent blocked in run()'s
select { case <-done[dep.ID]: ...; case <-ctx.Done(): ... } therefore
always sees its dependency's done-channel ready first, regardless of
whether that dependency failed for a genuine reason or was cancelled.
execCreateHookContainer already guarded against exactly this. The two
other new dispatch functions from the previous commit did not:
execStartContainer's enriched branch could call ContainerStart right
after its OpRunPreStart failed for real (e.g. "no hook runner
container found"), contradicting pre_start.go's documented guarantee
that a non-zero hook exit gates service start - and symmetrically for
execRunPostStart after a failed OpStartContainer.
Both now bail out on ctx.Err() first, mirroring the existing guard.
Pinned by a regression test reproducing the race deterministically: no
ContainerStart expectation is registered, so the unguarded code calls
it from inside the errgroup worker goroutine, where gomock's missing-
expectation failure hangs the test binary instead of failing it
cleanly - a stronger tell than a plain assertion failure would have
been.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Wire the plan executor to the start-phase vocabulary the reconciler
already produces (#14200): OpWaitCondition, OpRunPreStart, the enriched
OpStartContainer, and OpRunPostStart all had no case in executeNode
and hit "unknown operation type".
Every operation reuses the exact imperative primitive it mirrors —
waitDependency, runPreStart, runHook, injectSecrets/injectConfigs — so
behavior and events cannot drift between the two engines: execWaitCondition
resolves the dependency's live containers and hands off to the same
polling/condition-check functions waitDependencies uses; the enriched
OpStartContainer resolves its target either from the observed container
or, for a replica the plan itself creates, from the CreateContainer
node's result (the mechanism OpRenameContainer already relies on), then
injects secrets/configs before ContainerStart; OpRunPreStart re-checks
the daemon first so a replica that started in the observe-to-execute
window skips a redundant hook run.
A replica's pre_start/start/post_start chain shares one event group,
reporting a single Starting→Started progression exactly like
startServiceContainer does today — Starting fires specifically at
StartContainer, not at the (silent) pre_start hooks preceding it.
pkg/api/event.go documents this per-resource progression contract.
Still inert in production: create() (executePlan's only caller never
builds a plan with start-phase scope, so none of this runs outside
tests until a later brick in epic #14081 wires a real caller.
EOF
)
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
down() validates options.Images upfront, but ImagePruner is exported
and can be driven directly with a hand-built ImagePruneOptions that
bypasses that check. Add a direct test for the Valid() guard added in
the previous commit, so the two checks can't silently drift without a
test catching it.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
ImagesToPrune's own check duplicated the same set of legal
ImagePruneMode values down() already validates upfront, risking silent
drift if a mode is ever added. Reuse Valid() instead.
Suggested-by: glours https://github.com/docker/compose/pull/14149#discussion_r4069721340
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The legal values of DownOptions.Images lived in pkg/compose
(image_pruner.go) while the field itself was a bare string in pkg/api,
and the only validation fired inside ImagesToPrune — after down had
already removed the project's containers, leaving the teardown half
done on a typo. The CLI validated its --rmi flag separately, so only
SDK callers were exposed.
ImagePruneMode and its three values now live in pkg/api next to the
field they constrain (type-aliased in pkg/compose for existing
consumers), down() rejects any other value before touching a single
resource, and the CLI check reuses the same definition. A unit test
runs Down with expectation-free mocks: one daemon call would fail it.
Epic #14074, B.6.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
docker-agent found that streamImageTo returned a plain error (channel
intact) when the announce write itself failed -- for the success
announce, and for the error announce on a platform-parse/ImageSave
failure. In both cases the provider never received anything to read
and was left blocked on ReadString, while the caller, seeing a plain
error, never closed stdin either -- a deadlock.
Both paths now return streamAbortedError when the announce write
fails, matching the existing mid-stream/close failure handling so the
caller's errors.As check closes stdin and unblocks the provider.
Pinned by two new regression tests using a writer that always errors,
verified by reverting the fix locally and confirming both fail with a
plain error instead of streamAbortedError.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Three fixes from glours' review:
- ensureProviderImages now skips a provider service declaring neither
image: nor build: (legal for a pure resource provider, e.g. one
backing a remote Amazon RDS instance). Without the guard, such a
service reached pull with a fabricated "<project>-<service>"
reference (GetImageNameOrDefault) under source=registry
(providerImageSource treats Build == nil as registry-authoritative)
-- a name that was never real. Already reachable through existing
e2e fixtures (TestDependsOnMultipleProviders' provider1/provider2),
only a no-op today because the demo pull() short-circuits on an
unset env var, not because of any guard here.
- localImageFacts now resolves --digest through the manifest-aware
localContentDigest instead of the raw ImageInspect ID. Under
BuildKit provenance attestations, the raw ID covers the attestation
manifest too and changes on every build even when the runnable image
content didn't (#13636), which would make the provider re-sync on
every up for no reason -- defeating docs/extension.md's own
"identity test" contract for --digest. Threads service.Platform
through from runProviderPull so the resolved manifest matches what
the provider will actually run.
- streamImageTo now distinguishes a failure before the success
announce (invalid platform, ImageSave error -- a clean, well-formed
error line, channel intact) from one after it (the chunked body
truncated, channel unresynchronizable) via a new streamAbortedError
type. Only the latter closes stdin; the provider protocol supports
several sequential get-image requests per pull invocation, and
closing stdin on a clean pre-stream error was killing any other
independent request in the same invocation for no reason.
Each fix is pinned by a regression test, verified by reverting the
fix locally and confirming the new test catches it.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
A service declaring only build: (no image:) answered get-service-config
with an empty "image" field: service.Image is the YAML-declared value,
and compose-go never fills it in for this case (every other caller of
GetImageNameOrDefault in this package exists precisely because of that).
The provider only ever sees this response, never the model compose
builds internally, so an sbx-style provider building its own runtime
image rejected the service outright with "defines no image".
The response now carries the resolved name (api.GetImageNameOrDefault)
instead - the same one the image phase already built and tagged by the
time a provider asks. The build directive itself is cleared before
marshaling: a provider has no builder to run it against, only an image
identity to run.
Pinned by a regression test using the existing fake-provider harness,
verified by ablation to fail on either half of the fix reverted.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
extension.md gains the Image distribution section: invocation contract
(--image/--digest/--created/--source/--policy), the get-image request
and its chunked image-stream answer (zero-chunk terminated, stdin
exclusivity and drain-before-next-answer contract), the two-branch
decision guidance (digest as identity, created as ordering fallback,
reproducible builds caveat), and the support-by-presence metadata
convention is now stated as the general rule. The example provider
implements pull end to end — request, stock chunked reader, hash
recorded at PROVIDER_PULL_MARKER — and the e2e scenario locks the
whole path: up builds the service image and streams it to the provider
under the local verdict, compose pull re-invokes it under the
freshness contract.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
startService errored with 'no container to start' whenever the
project-wide container listing came back empty, before the per-service
filtering that lets provider services pass through. A project whose
services are all provider-backed legitimately reaches the start phase
with zero containers. The empty-list error is now softened for
provider services only — a relay container deployed for published
endpoints still goes through the regular start path.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
ensureImagesExists and docker compose pull now give provider-backed
services their turn: compose invokes the provider's pull command with
the image identity and the state of the local daemon cache
(--image/--digest/--created), plus two verdicts compose alone can
compute so providers never re-implement that arbitration:
- --source: the authority for this invocation — local (the daemon's
image is the desired state: build-only service, pull_policy build,
or an image the current run just built) or registry (resolve the
reference upstream — including the CI workflow where build is only
the recipe used to publish the image consumers pull);
- --policy: missing on the up path (a usable version suffices) or
always on compose pull (ensure freshness of the authority).
digest/created describe the cache, they are not instructions: the
provider persists them as the bookkeeping keys of what it ingested —
digest as identity test, created as the ordering fallback for backends
that cannot preserve digests. Providers without the metadata block are
skipped: behavior unchanged.
Providers are independent, so their pulls run without fail-fast
cancellation — the first failure no longer kills its siblings mid-run
and mangles their reports into context-canceled noise; every provider
runs to completion and every failure is reported, prefixed by service.
On the pull path the provider phase runs unconditionally — skipping it
because an unrelated service failed to pull would silently leave
provider runtimes stale — and its error is a per-service pull error,
following their exact regime: reported with them, suppressed by
IgnoreFailures. A fatal errgroup error is reported joined with the
accumulated per-service context instead of dropping it. The provider
runs under the root context: the errgroup context is canceled once
Wait returns and would kill the provider process on the spot.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Providers opt into image distribution by declaring a pull block in
their metadata — the presence of the command block is the declaration
of support, generalizing the stop precedent. During its pull command a
provider can request the service image from the local daemon with a
get-image message (optionally platform-narrowed); compose answers on
stdin with one image-stream JSON line then the tar as HTTP/1.1 chunked
data (RFC 9112): length-prefixed blocks need no in-band delimiter in
binary data, the zero-length chunk marks a COMPLETE transfer, and any
stock chunked reader consumes it. There is deliberately no trailer nor
final CRLF after the zero chunk — a stock reader stops there without
consuming further bytes, so the next stdin answer starts clean for a
provider requesting several images. An export failure is announced
in-band through the error field so the provider is never left waiting;
a failure after the announce closes the answer channel so the
truncation is observable as EOF mid-chunk instead of a stream nobody
will finish. The stream is exclusive on stdin for its whole duration —
the framing invariant behind the lock.
get-image is scoped to the pull command: emitted during up, down or
stop it is a protocol error rather than served, so an image export can
never stall another lifecycle command.
Message dispatch moves out of executePlugin into handlePluginMessage,
which also keeps the function under the complexity threshold.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Binding the announced gateway alone restricts by destination address, not
by the interface traffic arrives on, so another bridge can still reach it
by IP. A provider that pins the socket to the relay-link bridge's own
interface (SO_BINDTODEVICE on Linux) keeps the endpoint relay-only.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Unify the up and down paths on one removal helper that tolerates both
NotFound and Conflict and emits the same progress events as removeNetwork,
build one down op per relay-link network gated on the shared limiter (so
the empty-ops warning is reachable again), and share the label filter.
Reword the isolation claim: the relay-link network is joined by nothing
else, but its gateway is a host address that local containers can still
reach by IP; only a provider binding exclusively that address keeps the
endpoint off loopback and LAN-facing addresses.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
get-relay-info answers pointed a locally-bound provider at one of the
dependents' own networks: shared infrastructure every other service on
it could also reach, and no more isolated than any project bridge.
Provision a dedicated, internal:true bridge network scoped to that one
provider service instead, created only when the provider itself sends
get-relay-info -- the provider's own declaration that it binds locally,
never for a provider backing a remote resource. The relay container
joins it alongside the dependents' networks it already joins; it is
torn down with the relay on endpoint changes and on down, including
the no-compose-file down path.
The network's lifecycle is hardened against the races a shared,
project-scoped resource runs into:
- a NetworkCreate conflict on the deterministic name re-checks by
label (not just by name) before adopting the existing network, so a
genuine name clash with an unrelated, user-declared network fails
loudly instead of being silently adopted into the relay's isolation
boundary;
- a NotFound gateway lookup after losing that conflict falls back to
an unresolved answer instead of propagating the error;
- removeRelayLinkNetwork and ensureRelayLinkNetworksDown both tolerate
a NetworkRemove conflict from the daemon's asynchronous endpoint
disconnect, which can race the relay container's own removal;
- ensureRelayLinkNetworksDown accumulates failures with errors.Join
across every relay-link network of a project instead of aborting on
the first one, and skips (warn-only) a network that still has active
endpoints, mirroring removeNetwork's existing tolerance for regular
project networks.
docs/extension.md documents that the "desktop" network name in the
get-relay-info answer (under Docker Desktop) is an opaque placeholder,
never a real Docker network a provider can inspect or connect to.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
compose-go's loader now silently renames both deprecated
x-initialSync and x-develop extensions to their official
initial_sync and develop attributes before compose ever sees them
as extensions, so the legacy lookups and deprecation warnings for
both can no longer be reached. That's why the e2e test asserting on
the x-initialSync warning broke under the bump.
Simplify both lookups to rely on the promoted fields directly, and
rewrite the e2e test to check the legacy attribute still triggers a
real initial sync instead of asserting on an unreachable message.
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
down's outer ops dispatch bounded only how many ops ran concurrently,
separate from the semaphore already shared by image removal -- a
single network plus --rmi could spend up to 2x the configured
budget. Network and volume removal now share that same semaphore.
up's post-attach log streaming called ContainerInspect directly and
passed no limiter to doLogContainer, unlike `compose logs --follow`'s
equivalent path, so it never shared --parallel's budget either.
The plan executor also held a node's slot for its whole dependency
wait instead of just its own work, and internal/sync/tar.go's file
sync used a hardcoded cap of 16 instead of --parallel.
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
`docker compose cp` fanned out to every matched container through a
bare unbounded errgroup, ignoring --parallel entirely -- the same
class of gap already closed everywhere else in this package. Routed
it through the existing forEachContainerConcurrent helper instead of
a bespoke fan-out.
inspectWithSlot and doLogContainer both release a semaphore slot
early via an explicit call rather than a defer, so a panic between
acquire and that release leaked the slot forever. Guarded both with
a panic-safe release, scoped tightly in doLogContainer so a later
panic in the same function can't trigger a double release.
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
down and stop rebuilt their per-container limiter on every service
visit, so independent services could each spend a full budget
concurrently -- the same leak already fixed on restart. start's
InDependencyOrder call had no concurrency option, leaving every
`up`'s container-start phase fully unbounded. wait.go goes back to
unbounded on purpose: ContainerWait blocks per container
indefinitely, so capping it would serialize waits meant to run
concurrently.
Also extracts the shared per-container fan-out into one helper reused
by restart/down/stop, and dedupes the concurrency-guard test fixtures.
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
Logs --follow reused the bounded errgroup for both the indefinite log
streams and the monitor goroutine, so once maxConcurrency streams
opened the monitor never started and further services never showed
logs. restart gave each service its own budget, so ready services
could multiply maxConcurrency instead of sharing it.
Bound both with a semaphore that gates only the connect/restart call,
never the indefinite work that follows, sharing one instance across
restart's services. Adds regression tests, plus one guarding the
topological node order a bounded errgroup now relies on in executor.
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
errgroup.SetLimit(0) means "allow zero goroutines", not "unlimited",
and maxConcurrency's Go zero-value is 0 — only NewComposeService sets
it to -1 explicitly. Any composeService{} literal built without it
(common in tests) silently deadlocked at every call site that called
SetLimit unconditionally.
Separately, --parallel/COMPOSE_PARALLEL_LIMIT was only ever wired
into pull, push, and the dependency-graph traversal, despite the docs
promising a generic bound on "concurrent engine calls". Every other
bulk operation (kill, pause, down, the up/create plan executor, logs,
ps, top, wait, restart, remove, images, model pulls, watch) launched
one goroutine per container/image/DAG-node with no cap at all.
Fix both via a shared newLimitedErrgroup helper applied at every
fan-out site, threading maxConcurrency through forEachContainerConcurrent
and ImagePruner, which had no access to composeService. Add a
regression test for the zero-value case.
service_containers.go's waitDependencies is intentionally left
unguarded: it's a per-dependency ticker poll, not a burst of engine
calls.
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
Wait has no real container to observe in dry-run: getContainers
falls back to the live daemon and finds nothing, so the command
failed with a misleading "no containers for project" error instead
of signaling upfront that the operation doesn't apply under
simulation.
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
DryRunClient fakes container state as permanently running/healthy,
which never satisfies the exited-state check that
service_completed_successfully waits for. With up -d passing no
default timeout, the wait loop polled forever and dry-run never
returned, even though no container was ever really started.
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
The start flow hand-rolled its ContainerList without the ConfigHashLabel
presence filter every other listing applies (getDefaultFilters) — the
actual source of pre_start hook runners leaking into startService and
waitDependencies, patched downstream by isNotHookContainer. Routing
through getContainers fixes the leak at the source, like
getContainersByService already does; the isNotHookContainer guards stay
as defense-in-depth.
The dry-run client keyed its ContainerList interception on the calling
function: caller "start" answered from the faked-creations cache, while
caller "getContainers" fell back to the real daemon once the cache was
seeded — so routing start through getContainers made dry-run-created
containers invisible to the start phase ("service has no container to
start", TestUpDryRunMissingImage). The getContainers case now keeps
answering from the seeded cache, where faked creations land.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Five more findings landed on the previous commit (three from a fresh
copilot-pull-request-reviewer pass, two from docker-agent):
- **Duplicate hook containers** (observed_state.go): a runner created
before the ConfigHashLabel exclusion existed (or by an older compose
version) still carries that label, so it matches getContainers' own
filters and is already present in `raw` -- appending getHookContainers'
result unconditionally classified it twice, scheduling two removals for
one ID. Deduplicated by container ID before classification. Locked in by
TestCollectObservedState_LegacyHookRunnerNotDuplicated.
- **Hook runners misjudged as a satisfied dependency** (service_containers.go):
waitDependencies filtered a dependency's containers the same way
startService's own replica filter used to (isService + isNotOneOff, no
hook exclusion) -- a dependency's retained/exited runner could be read as
the dependency itself, either masking a genuinely missing dependency or
reporting an unhealthy one that's really just a diagnostic leftover.
Added isNotHookContainer there too.
- **per_replica bypassing the stale-runner purge** (reconcile.go): the
early return added for #14259 skipped the purge loop entirely, so
runners from a prior per_replica: false generation would never be
cleaned up once a hook switched to per_replica: true. Reordered: the
purge always runs when there's a service to reconcile; only the create
loop is skipped for per_replica. Locked in by
TestReconcileContainers_StaleHookRunnersPurgedEvenWhenPerReplica.
- **keptRunning ignores stops already planned elsewhere** (reconcile.go):
a replica reported running in the observed-state snapshot but already
scheduled for a stop by planRecreateNetworks or planStopDependents
(network recreate, a restart: true dependency cascade) would not
actually be running by the time the start phase evaluates pre_start --
but keptRunning didn't know that, so no runner got planned and start
later failed with "no hook runner container found". Only counts a
replica as kept when stoppedByPlan has no entry for it. Locked in by
TestReconcileContainers_HookRunnerPlannedWhenCascadeStopsRunningReplica.
- **Success-removal uses the cancellable ctx** (pre_start.go): inconsistent
with the cancellation-cleanup path in the same file, which already uses
context.WithoutCancel to guarantee removal survives a Ctrl-C landing in
the narrow window right after a hook's success. Matched the pattern.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
A GitHub Copilot PR review (docker/compose#14221#pullrequestreview-5300897216)
found three real issues in the reconciliation-plan-based hook runners, all
confirmed by direct reproduction against a live daemon before being fixed:
- **Hook runners excluded from discovery, stale runners persist.**
collectObservedState's single getContainers call requires ConfigHashLabel
(getDefaultFilters), which hook runners deliberately never carry -- so they
never reached the classification loop that populates HookContainers, and
planPreStartHookRunners never saw a stale runner to purge. Reproduced: a
failed hook run followed by a second `up` failed with "container name ...
already in use" instead of recovering. Fixed by listing hook containers
separately, by project+hook label alone (new getHookContainers), and
merging them in before classification. Locked in by a new e2e scenario,
TestPreStartHookRetryAfterFailureSucceeds, that reproduces the exact
failure-then-retry sequence.
- **Prepared hook runners misclassified as service replicas.** start's
containers.filter(isService(name), isNotOneOff) has no reason to exclude a
hook runner: it carries the same project/service labels as a real replica
and no one-off label either. Added isNotHookContainer to the filter chain
in startService, so a hook runner is never counted as (or started as) a
surviving replica.
- **Per-replica hooks create runners before unsupported configuration is
rejected.** per_replica is not yet supported (#14259): runPreStart
validates every hook up front and rejects the whole service before
executing any of them, but planPreStartHookRunners had no equivalent
check, so create/up would plan (and leave behind) runners for a service
whose hooks could never run. Mirrored the same up-front, all-or-nothing
validation in planPreStartHookRunners.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
pre_start hook containers become first-class resources of the
reconciliation plan. The reconciler plans one OpCreateHookContainer per
declared hook — gated on the same predicate the start phase uses to run
the hooks: a replica to start and no running replica SURVIVING the plan
(a recreated replica is not running at start time, so its runners are
planned too). Runner creation depends on every replica node (the
executor resolves the VolumesFrom target against a final live view),
on the infrastructure, and on the purge of previously observed runners:
names are deterministic (<project>-<service>-pre_start-<i>) so repeated
plans converge on the same container instead of accumulating anonymous
ones, and a new HookIndexLabel ties each runner to its hook.
runPreStart becomes pure execution: it looks up the created-state
runner for each hook by label and never creates one. A declared hook
without a prepared runner is an actionable error naming the
reconciliation command (docker compose up <service>) — the accepted
consequence is that stop-then-start of a hooked service errors, since
runners are consumed on success (locked by e2e). Success removal,
failure retention and cancellation cleanup are unchanged.
Runners stay invisible to the start/ps container listings — they carry
no ConfigHashLabel, which getDefaultFilters requires — and down keeps
removing them by hook label.
Rebased onto main, which diverged substantially since this branch was
opened (the unrelated container-spec-layering refactor, #14093,
restructured compose-go's ServiceConfig/PreStartHook types this PR also
touches). Reconciling pre_start.go/pre_start_test.go against that
refactor surfaced a real bug: createPreStartContainer builds the hook's
config via the shared getCreateConfigs, which unconditionally stamps a
ConfigHashLabel — silently contradicting this same commit's own
"invisible to ps/start" guarantee above, since that label is exactly
what getDefaultFilters requires. Fixed by deleting the label after
getCreateConfigs returns, with a test asserting its absence (an
independent local review, via the GitHub Copilot CLI, and a
fresh-context review agent both converged on catching this during
rebase verification). Also restored two security/label tests that only
existed on one side of the rebase (SecuritySensitiveFieldsHonored,
HookLabelsMerged), ported to call createPreStartContainer directly.
Also addresses glours' three review comments on this PR: hook-container
create operations for a service no longer chain serially (each depends
on the same shared containerNodes+infraDeps+purges set, letting the
executor create them in parallel), the corresponding plan-string test
assertion, and a clearer missing-runner error message hinting this
isn't necessarily a planning bug.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>