compose/internal/containerops/containerops.go
Nicolas De Loof 00316eee35 refactor: give each component only the engine families it uses
The packages extracted from pkg/compose (build, images, relay, containerops,
logstream, devwatch, inspect, projectloader, publish, provider) each received
the whole moby client through a single APIClient accessor, and the classic
image build reached the daemon through the Docker CLI.

Their Backend interfaces now ask for the client interfaces moby defines per
resource (ContainerAPI, NetworkAPI, ImageAPI, ImageBuildAPI, ExecAPI,
VolumeAPI, SystemAPI, DistributionAPI), and only for those the component
calls: containerops works on containers alone, registry only resolves
digests, and so on. The helpers they call (registry, desktop, the log stream
monitor) take the matching family. composeService implements every accessor
with its engine.

composeService gets an optional engine field, used instead of the client of
the Docker CLI when set. The CLI client still backs it by default, resolved on
first use as before, since it initializes lazily. WithDryRun refuses a service
holding an engine, as the dry-run client only wraps the CLI's one. Close
releases the engine handed to the service, while the CLI's client stays with
the CLI.

No behavior change.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-11-27 10:10:21 +01:00

55 lines
1.9 KiB
Go

/*
Copyright 2020 Docker Compose CLI authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package containerops implements the operations that act from the outside on
// the container of a service: exec, cp, export and commit.
package containerops
import (
"github.com/docker/cli/cli/command"
"github.com/moby/moby/client"
"github.com/docker/compose/v5/internal/engine"
"github.com/docker/compose/v5/pkg/api"
)
// Backend is what the operations need from the engine they act on.
//
// The terminal reaches them through CLI: stdin, stdout and the TTY all come
// from the Docker CLI's streams, the one seam through which an operation that
// talks to the user does so (exec hands the whole CLI to the Docker CLI's own
// implementation).
type Backend interface {
engine.Backend
// ContainerAPI acts on the containers: copy, export, commit.
ContainerAPI() client.ContainerAPIClient
// Events receives the progress of the operations.
Events() api.EventProcessor
// DryRun tells whether the operations only report what they would do.
DryRun() bool
// CLI is the Docker CLI Compose runs in, and the owner of the terminal streams.
CLI() command.Cli
}
// Service runs the container operations on a Backend.
type Service struct {
backend Backend
}
// New creates a Service acting on the given Backend.
func New(backend Backend) *Service {
return &Service{backend: backend}
}