forbidigo rejects context.Background() in tests; t.Context() is the
intended replacement and carries the test's cancellation.
Signed-off-by: Zhuoming Wang <zhuomingwang0901@outlook.com>
The Engine client sends io.EOF over EventsResult.Err once the stream has
been read completely, which is what happens when `events --until` reaches
its deadline. Service.Events returned that error verbatim, so the command
printed "EOF" and exited 1 even though every event had been delivered.
Return nil for io.EOF and keep propagating real stream errors.
Signed-off-by: Zhuoming Wang <zhuomingwang0901@outlook.com>
Several places copied the keys of a map into a slice and sorted it by hand, some through their own generic helper. Use slices.Sorted(maps.Keys(m)), keeping the sorted order of the output.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
images and volumes each looped over the project containers to keep those of the selected services, as internal/inspect already did for ps and top. Use one helper for all four.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
internal/inspect and internal/containerops declared the same engine methods and one-off enum, and pkg/compose adapted them twice. Declare them in internal/engine, embed them in both Backend interfaces and keep a single adapter.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The label=key=value filter was rebuilt in pkg/compose, internal/inspect, internal/relay, cmd/compose and pkg/bridge. Build it once in internal/naming and use it everywhere.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The "errgroup bounded to maxConcurrency, where <= 0 means unlimited" helper was copied in several places (pkg/compose, internal/containerops, internal/inspect, internal/sync), together with the semaphore-based slot helpers used to share one budget across concurrent calls. Gather them in a leaf package so the extractions in progress can import it instead of duplicating it again. Behavior is unchanged.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
LoadProject and Generate (the api.ProjectLoader operations) need two things
from the engine: the Docker API, to read the containers a project is
generated from, and the Docker CLI, which resolves remote Compose files.
They now live in internal/projectloader, along with the unsupported
attributes detection only the loader uses, behind a Backend interface that
composeService implements in a new file of pkg/compose, like internal/inspect.
The tests move with the code; their assertions are unchanged, only the way
the service is built differs.
The canonical container name, which both this package and internal/inspect
need, moves to a tiny internal/naming package instead of being copied a
third time. pkg/compose keeps its own copy until the shared kernel is
extracted.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
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>