Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cmd/compose/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ func runPs(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOp
})

if opts.Quiet {
for _, c := range containers {
_, _ = fmt.Fprintln(dockerCli.Out(), c.ID)
for _, ctr := range containers {
_, _ = fmt.Fprintln(dockerCli.Out(), ctr.ID)
}
return nil
}

if opts.Services {
services := []string{}
for _, c := range containers {
s := c.Service
for _, ctr := range containers {
s := ctr.Service
if !slices.Contains(services, s) {
services = append(services, s)
}
Expand All @@ -166,9 +166,9 @@ func runPs(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOp

func filterByStatus(containers []api.ContainerSummary, statuses []string) []api.ContainerSummary {
var filtered []api.ContainerSummary
for _, c := range containers {
if slices.Contains(statuses, string(c.State)) {
filtered = append(filtered, c)
for _, ctr := range containers {
if slices.Contains(statuses, string(ctr.State)) {
filtered = append(filtered, ctr)
}
}
return filtered
Expand Down
14 changes: 7 additions & 7 deletions cmd/display/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ type jsonMessage struct {
Percent int `json:"percent,omitempty"`
}

func (p *jsonWriter) Start(ctx context.Context, operation string) {
func (w *jsonWriter) Start(ctx context.Context, operation string) {
}

func (p *jsonWriter) Event(e api.Resource) {
func (w *jsonWriter) Event(e api.Resource) {
message := &jsonMessage{
DryRun: p.dryRun,
DryRun: w.dryRun,
Tail: false,
ID: e.ID,
Status: e.StatusText(),
Expand All @@ -67,15 +67,15 @@ func (p *jsonWriter) Event(e api.Resource) {
}
marshal, err := json.Marshal(message)
if err == nil {
_, _ = fmt.Fprintln(p.out, string(marshal))
_, _ = fmt.Fprintln(w.out, string(marshal))
}
}

func (p *jsonWriter) On(events ...api.Resource) {
func (w *jsonWriter) On(events ...api.Resource) {
for _, e := range events {
p.Event(e)
w.Event(e)
}
}

func (p *jsonWriter) Done(_ string, _ bool) {
func (w *jsonWriter) Done(_ string, _ bool) {
}
18 changes: 9 additions & 9 deletions pkg/compose/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis
containers.sorted() // This enforces predictable colors assignment

var names []string
for _, c := range containers {
names = append(names, getContainerNameWithoutProject(c))
for _, ctr := range containers {
names = append(names, getContainerNameWithoutProject(ctr))
}

_, err = fmt.Fprintf(s.stdout(), "Attaching to %s\n", strings.Join(names, ", "))
Expand Down Expand Up @@ -96,8 +96,8 @@ func (s *composeService) doAttachContainer(ctx context.Context, service, id, nam
return nil
}

func (s *composeService) attachContainerStreams(ctx context.Context, container string, tty bool, stdout, stderr io.WriteCloser) error {
streamOut, err := s.getContainerStreams(ctx, container)
func (s *composeService) attachContainerStreams(ctx context.Context, containerID string, tty bool, stdout, stderr io.WriteCloser) error {
streamOut, err := s.getContainerStreams(ctx, containerID)
if err != nil {
return err
}
Expand All @@ -123,28 +123,28 @@ func (s *composeService) attachContainerStreams(ctx context.Context, container s
_, err = stdcopy.StdCopy(stdout, stderr, streamOut)
}
if err != nil && !errors.Is(err, io.EOF) {
logrus.Debugf("stream copy error for container %s: %v", container, err)
logrus.Debugf("stream copy error for container %s: %v", containerID, err)
}
}()
}
return nil
}

func (s *composeService) getContainerStreams(ctx context.Context, container string) (io.ReadCloser, error) {
cnx, err := s.apiClient().ContainerAttach(ctx, container, client.ContainerAttachOptions{
func (s *composeService) getContainerStreams(ctx context.Context, containerID string) (io.ReadCloser, error) {
attachResponse, err := s.apiClient().ContainerAttach(ctx, containerID, client.ContainerAttachOptions{
Stream: true,
Stdin: false,
Stdout: true,
Stderr: true,
Logs: false,
})
if err == nil {
stdout := ContainerStdout{HijackedResponse: cnx.HijackedResponse}
stdout := ContainerStdout{HijackedResponse: attachResponse.HijackedResponse}
return stdout, nil
}

// Fallback to logs API
logs, err := s.apiClient().ContainerLogs(ctx, container, client.ContainerLogsOptions{
logs, err := s.apiClient().ContainerLogs(ctx, containerID, client.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
Follow: true,
Expand Down
4 changes: 2 additions & 2 deletions pkg/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ func (s *composeService) getLocalImagesDigests(ctx context.Context, project *typ
//
// Finally, standard proxy variables based on the Docker client configuration are added, but will not overwrite
// any values if already present.
func resolveAndMergeBuildArgs(proxyConfig map[string]string, project *types.Project, service types.ServiceConfig, opts api.BuildOptions) types.MappingWithEquals {
func resolveAndMergeBuildArgs(proxyConfig map[string]string, project *types.Project, service types.ServiceConfig, options api.BuildOptions) types.MappingWithEquals {
result := make(types.MappingWithEquals).
OverrideBy(service.Build.Args).
OverrideBy(opts.Args).
OverrideBy(options.Args).
Resolve(envResolver(project.Environment))

// proxy arguments do NOT override and should NOT have env resolution applied,
Expand Down
6 changes: 3 additions & 3 deletions pkg/compose/build_classic.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func (s *composeService) doBuildClassic(ctx context.Context, project *types.Proj
// Not using bake, additional_context: service:xx is implemented by building images in dependency order
project, err := project.WithServicesTransform(func(serviceName string, service types.ServiceConfig) (types.ServiceConfig, error) {
if service.Build != nil {
for _, c := range service.Build.AdditionalContexts {
if t, found := strings.CutPrefix(c, types.ServicePrefix); found {
for _, additionalContext := range service.Build.AdditionalContexts {
if targetService, found := strings.CutPrefix(additionalContext, types.ServicePrefix); found {
if service.DependsOn == nil {
service.DependsOn = map[string]types.ServiceDependency{}
}
service.DependsOn[t] = types.ServiceDependency{
service.DependsOn[targetService] = types.ServiceDependency{
Condition: "build", // non-canonical, but will force dependency graph ordering
}
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,17 +365,17 @@ func (s *composeService) projectFromName(containers Containers, projectName stri
return project, fmt.Errorf("no container found for project %q: %w", projectName, api.ErrNotFound)
}
set := types.Services{}
for _, c := range containers {
serviceLabel, ok := c.Labels[api.ServiceLabel]
for _, ctr := range containers {
serviceLabel, ok := ctr.Labels[api.ServiceLabel]
if !ok {
serviceLabel = getCanonicalContainerName(c)
serviceLabel = getCanonicalContainerName(ctr)
}
service, ok := set[serviceLabel]
if !ok {
service = types.ServiceConfig{
Name: serviceLabel,
Image: c.Image,
Labels: c.Labels,
Image: ctr.Image,
Labels: ctr.Labels,
}
}
service.Scale = increment(service.Scale)
Expand Down Expand Up @@ -433,10 +433,10 @@ func increment(scale *int) *int {
}

func (s *composeService) actualVolumes(ctx context.Context, projectName string) (types.Volumes, error) {
opts := client.VolumeListOptions{
options := client.VolumeListOptions{
Filters: projectFilter(projectName),
}
volumes, err := s.apiClient().VolumeList(ctx, opts)
volumes, err := s.apiClient().VolumeList(ctx, options)
if err != nil {
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/compose/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const (
oneOffOnly
)

func (s *composeService) getContainers(ctx context.Context, project string, oneOff oneOff, all bool, selectedServices ...string) (Containers, error) {
func (s *composeService) getContainers(ctx context.Context, projectName string, oneOff oneOff, all bool, selectedServices ...string) (Containers, error) {
res, err := s.apiClient().ContainerList(ctx, client.ContainerListOptions{
Filters: getDefaultFilters(project, oneOff, selectedServices...),
Filters: getDefaultFilters(projectName, oneOff, selectedServices...),
All: all,
})
if err != nil {
Expand All @@ -64,9 +64,9 @@ func (s *composeService) getContainersByService(ctx context.Context, projectName
return nil, err
}
result := map[string]Containers{}
for _, c := range all.filter(isNotOneOff) {
svc := c.Labels[api.ServiceLabel]
result[svc] = append(result[svc], c)
for _, ctr := range all.filter(isNotOneOff) {
serviceName := ctr.Labels[api.ServiceLabel]
result[serviceName] = append(result[serviceName], ctr)
}
return result, nil
}
Expand Down Expand Up @@ -169,9 +169,9 @@ func isNotRunning(c container.Summary) bool {
// filter return Containers with elements to match predicate
func (containers Containers) filter(predicates ...containerPredicate) Containers {
var filtered Containers
for _, c := range containers {
if matches(c, predicates...) {
filtered = append(filtered, c)
for _, ctr := range containers {
if matches(ctr, predicates...) {
filtered = append(filtered, ctr)
}
}
return filtered
Expand Down
38 changes: 19 additions & 19 deletions pkg/compose/convergence.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,14 @@ func shouldWaitForDependency(serviceName string, dependencyConfig types.ServiceD

func nextContainerNumber(containers []container.Summary) int {
maxNumber := 0
for _, c := range containers {
s, ok := c.Labels[api.ContainerNumberLabel]
for _, ctr := range containers {
s, ok := ctr.Labels[api.ContainerNumberLabel]
if !ok {
logrus.Warnf("container %s is missing %s label", c.ID, api.ContainerNumberLabel)
logrus.Warnf("container %s is missing %s label", ctr.ID, api.ContainerNumberLabel)
}
n, err := strconv.Atoi(s)
if err != nil {
logrus.Warnf("container %s has invalid %s label: %s", c.ID, api.ContainerNumberLabel, s)
logrus.Warnf("container %s has invalid %s label: %s", ctr.ID, api.ContainerNumberLabel, s)
continue
}
if n > maxNumber {
Expand All @@ -304,11 +304,11 @@ func nextContainerNumber(containers []container.Summary) int {
}

func (s *composeService) createContainer(ctx context.Context, project *types.Project, service types.ServiceConfig,
name string, number int, opts createOptions,
name string, number int, options createOptions,
) (ctr container.Summary, err error) {
eventName := "Container " + name
s.events.On(creatingEvent(eventName))
ctr, err = s.createMobyContainer(ctx, project, service, name, number, nil, opts)
ctr, err = s.createMobyContainer(ctx, project, service, name, number, nil, options)
if err != nil {
if ctx.Err() == nil {
s.events.On(api.Resource{
Expand All @@ -327,10 +327,10 @@ func (s *composeService) createContainer(ctx context.Context, project *types.Pro
var startMx sync.Mutex

func (s *composeService) createMobyContainer(ctx context.Context, project *types.Project, service types.ServiceConfig,
name string, number int, inherit *container.Summary, opts createOptions,
name string, number int, inherit *container.Summary, options createOptions,
) (container.Summary, error) {
var created container.Summary
cfgs, err := s.getCreateConfigs(ctx, project, service, number, inherit, opts)
cfgs, err := s.getCreateConfigs(ctx, project, service, number, inherit, options)
if err != nil {
return created, err
}
Expand Down Expand Up @@ -381,7 +381,7 @@ func (s *composeService) createMobyContainer(ctx context.Context, project *types
// primary network already configured as part of ContainerCreate
continue
}
epSettings, err := createEndpointSettings(project, service, number, networkKey, cfgs.Links, opts.UseNetworkAliases)
epSettings, err := createEndpointSettings(project, service, number, networkKey, cfgs.Links, options.UseNetworkAliases)
if err != nil {
_, _ = s.apiClient().ContainerRemove(ctx, response.ID, client.ContainerRemoveOptions{Force: true})
return created, err
Expand Down Expand Up @@ -428,12 +428,12 @@ func (s *composeService) getLinks(ctx context.Context, projectName string, servi
if !ok {
linkName = linkServiceName
}
cnts, err := getServiceContainers(linkServiceName)
serviceContainers, err := getServiceContainers(linkServiceName)
if err != nil {
return nil, err
}
for _, c := range cnts {
containerName := getCanonicalContainerName(c)
for _, ctr := range serviceContainers {
containerName := getCanonicalContainerName(ctr)
links = append(links,
format(containerName, linkName),
format(containerName, linkServiceName+api.Separator+strconv.Itoa(number)),
Expand All @@ -443,12 +443,12 @@ func (s *composeService) getLinks(ctx context.Context, projectName string, servi
}

if service.Labels[api.OneoffLabel] == "True" {
cnts, err := getServiceContainers(service.Name)
serviceContainers, err := getServiceContainers(service.Name)
if err != nil {
return nil, err
}
for _, c := range cnts {
containerName := getCanonicalContainerName(c)
for _, ctr := range serviceContainers {
containerName := getCanonicalContainerName(ctr)
links = append(links,
format(containerName, service.Name),
format(containerName, strings.TrimPrefix(containerName, projectName+api.Separator)),
Expand All @@ -468,8 +468,8 @@ func (s *composeService) getLinks(ctx context.Context, projectName string, servi
}

func (s *composeService) isServiceHealthy(ctx context.Context, containers Containers, fallbackRunning bool) (bool, error) {
for _, c := range containers {
res, err := s.apiClient().ContainerInspect(ctx, c.ID, client.ContainerInspectOptions{})
for _, ctr := range containers {
res, err := s.apiClient().ContainerInspect(ctx, ctr.ID, client.ContainerInspectOptions{})
if err != nil {
return false, err
}
Expand Down Expand Up @@ -504,8 +504,8 @@ func (s *composeService) isServiceHealthy(ctx context.Context, containers Contai
}

func (s *composeService) isServiceCompleted(ctx context.Context, containers Containers) (bool, int, error) {
for _, c := range containers {
res, err := s.apiClient().ContainerInspect(ctx, c.ID, client.ContainerInspectOptions{})
for _, ctr := range containers {
res, err := s.apiClient().ContainerInspect(ctx, ctr.ID, client.ContainerInspectOptions{})
if err != nil {
return false, 0, err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/compose/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a

var direction copyDirection
var serviceName string
var copyFunc func(ctx context.Context, containerID string, srcPath string, dstPath string, opts api.CopyOptions) error
var copyFunc func(ctx context.Context, containerID string, srcPath string, dstPath string, options api.CopyOptions) error
if srcService != "" {
direction |= fromService
serviceName = srcService
Expand Down Expand Up @@ -142,7 +142,7 @@ func (s *composeService) listContainersTargetedForCopy(ctx context.Context, proj
}
}

func (s *composeService) copyToContainer(ctx context.Context, containerID string, srcPath string, dstPath string, opts api.CopyOptions) error {
func (s *composeService) copyToContainer(ctx context.Context, containerID string, srcPath string, dstPath string, options api.CopyOptions) error {
var err error
if srcPath != "-" {
// Get an absolute source path.
Expand Down Expand Up @@ -208,7 +208,7 @@ func (s *composeService) copyToContainer(ctx context.Context, containerID string
}
} else {
// Prepare source copy info.
srcInfo, err := archive.CopyInfoSourcePath(srcPath, opts.FollowLink)
srcInfo, err := archive.CopyInfoSourcePath(srcPath, options.FollowLink)
if err != nil {
return err
}
Expand Down Expand Up @@ -248,12 +248,12 @@ func (s *composeService) copyToContainer(ctx context.Context, containerID string
DestinationPath: resolvedDstPath,
Content: content,
AllowOverwriteDirWithFile: false,
CopyUIDGID: opts.CopyUIDGID,
CopyUIDGID: options.CopyUIDGID,
})
return err
}

func (s *composeService) copyFromContainer(ctx context.Context, containerID, srcPath, dstPath string, opts api.CopyOptions) error {
func (s *composeService) copyFromContainer(ctx context.Context, containerID, srcPath, dstPath string, options api.CopyOptions) error {
var err error
if dstPath != "-" {
// Get an absolute destination path.
Expand All @@ -269,7 +269,7 @@ func (s *composeService) copyFromContainer(ctx context.Context, containerID, src

// if client requests to follow symbol link, then must decide target file to be copied
var rebaseName string
if opts.FollowLink {
if options.FollowLink {
var srcStat container.PathStat
res, err := s.apiClient().ContainerStatPath(ctx, containerID, client.ContainerStatPathOptions{
Path: srcPath,
Expand Down
Loading
Loading