diff --git a/pkg/api/api.go b/pkg/api/api.go index 510a1391e..08f6433d8 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -32,9 +32,9 @@ type Service interface { // Push executes the equivalent ot a `compose push` Push(ctx context.Context, project *types.Project, options PushOptions) error // Pull executes the equivalent of a `compose pull` - Pull(ctx context.Context, project *types.Project, opts PullOptions) error + Pull(ctx context.Context, project *types.Project, options PullOptions) error // Create executes the equivalent to a `compose create` - Create(ctx context.Context, project *types.Project, opts CreateOptions) error + Create(ctx context.Context, project *types.Project, options CreateOptions) error // Start executes the equivalent to a `compose start` Start(ctx context.Context, projectName string, options StartOptions) error // Restart restarts containers @@ -54,25 +54,25 @@ type Service interface { // Convert translate compose model into backend's native format Convert(ctx context.Context, project *types.Project, options ConvertOptions) ([]byte, error) // Kill executes the equivalent to a `compose kill` - Kill(ctx context.Context, project string, options KillOptions) error + Kill(ctx context.Context, projectName string, options KillOptions) error // RunOneOffContainer creates a service oneoff container and starts its dependencies RunOneOffContainer(ctx context.Context, project *types.Project, opts RunOptions) (int, error) // Remove executes the equivalent to a `compose rm` - Remove(ctx context.Context, project string, options RemoveOptions) error + Remove(ctx context.Context, projectName string, options RemoveOptions) error // Exec executes a command in a running service container - Exec(ctx context.Context, project string, opts RunOptions) (int, error) + Exec(ctx context.Context, projectName string, options RunOptions) (int, error) // Copy copies a file/folder between a service container and the local filesystem - Copy(ctx context.Context, project string, options CopyOptions) error + Copy(ctx context.Context, projectName string, options CopyOptions) error // Pause executes the equivalent to a `compose pause` - Pause(ctx context.Context, project string, options PauseOptions) error + Pause(ctx context.Context, projectName string, options PauseOptions) error // UnPause executes the equivalent to a `compose unpause` - UnPause(ctx context.Context, project string, options PauseOptions) error + UnPause(ctx context.Context, projectName string, options PauseOptions) error // Top executes the equivalent to a `compose top` Top(ctx context.Context, projectName string, services []string) ([]ContainerProcSummary, error) // Events executes the equivalent to a `compose events` - Events(ctx context.Context, project string, options EventsOptions) error + Events(ctx context.Context, projectName string, options EventsOptions) error // Port executes the equivalent to a `compose port` - Port(ctx context.Context, project string, service string, port int, options PortOptions) (string, int, error) + Port(ctx context.Context, projectName string, service string, port int, options PortOptions) (string, int, error) // Images executes the equivalent of a `compose images` Images(ctx context.Context, projectName string, options ImagesOptions) ([]ImageSummary, error) } diff --git a/pkg/api/proxy.go b/pkg/api/proxy.go index 44adf646e..5dcfa0e7f 100644 --- a/pkg/api/proxy.go +++ b/pkg/api/proxy.go @@ -219,11 +219,11 @@ func (s *ServiceProxy) Convert(ctx context.Context, project *types.Project, opti } // Kill implements Service interface -func (s *ServiceProxy) Kill(ctx context.Context, project string, options KillOptions) error { +func (s *ServiceProxy) Kill(ctx context.Context, projectName string, options KillOptions) error { if s.KillFn == nil { return ErrNotImplemented } - return s.KillFn(ctx, project, options) + return s.KillFn(ctx, projectName, options) } // RunOneOffContainer implements Service interface @@ -238,43 +238,43 @@ func (s *ServiceProxy) RunOneOffContainer(ctx context.Context, project *types.Pr } // Remove implements Service interface -func (s *ServiceProxy) Remove(ctx context.Context, project string, options RemoveOptions) error { +func (s *ServiceProxy) Remove(ctx context.Context, projectName string, options RemoveOptions) error { if s.RemoveFn == nil { return ErrNotImplemented } - return s.RemoveFn(ctx, project, options) + return s.RemoveFn(ctx, projectName, options) } // Exec implements Service interface -func (s *ServiceProxy) Exec(ctx context.Context, project string, options RunOptions) (int, error) { +func (s *ServiceProxy) Exec(ctx context.Context, projectName string, options RunOptions) (int, error) { if s.ExecFn == nil { return 0, ErrNotImplemented } - return s.ExecFn(ctx, project, options) + return s.ExecFn(ctx, projectName, options) } // Copy implements Service interface -func (s *ServiceProxy) Copy(ctx context.Context, project string, options CopyOptions) error { +func (s *ServiceProxy) Copy(ctx context.Context, projectName string, options CopyOptions) error { if s.CopyFn == nil { return ErrNotImplemented } - return s.CopyFn(ctx, project, options) + return s.CopyFn(ctx, projectName, options) } // Pause implements Service interface -func (s *ServiceProxy) Pause(ctx context.Context, project string, options PauseOptions) error { +func (s *ServiceProxy) Pause(ctx context.Context, projectName string, options PauseOptions) error { if s.PauseFn == nil { return ErrNotImplemented } - return s.PauseFn(ctx, project, options) + return s.PauseFn(ctx, projectName, options) } // UnPause implements Service interface -func (s *ServiceProxy) UnPause(ctx context.Context, project string, options PauseOptions) error { +func (s *ServiceProxy) UnPause(ctx context.Context, projectName string, options PauseOptions) error { if s.UnPauseFn == nil { return ErrNotImplemented } - return s.UnPauseFn(ctx, project, options) + return s.UnPauseFn(ctx, projectName, options) } // Top implements Service interface @@ -286,19 +286,19 @@ func (s *ServiceProxy) Top(ctx context.Context, project string, services []strin } // Events implements Service interface -func (s *ServiceProxy) Events(ctx context.Context, project string, options EventsOptions) error { +func (s *ServiceProxy) Events(ctx context.Context, projectName string, options EventsOptions) error { if s.EventsFn == nil { return ErrNotImplemented } - return s.EventsFn(ctx, project, options) + return s.EventsFn(ctx, projectName, options) } // Port implements Service interface -func (s *ServiceProxy) Port(ctx context.Context, project string, service string, port int, options PortOptions) (string, int, error) { +func (s *ServiceProxy) Port(ctx context.Context, projectName string, service string, port int, options PortOptions) (string, int, error) { if s.PortFn == nil { return "", 0, ErrNotImplemented } - return s.PortFn(ctx, project, service, port, options) + return s.PortFn(ctx, projectName, service, port, options) } // Images implements Service interface diff --git a/pkg/compose/cp.go b/pkg/compose/cp.go index b2123e601..b43a98f8b 100644 --- a/pkg/compose/cp.go +++ b/pkg/compose/cp.go @@ -42,9 +42,10 @@ const ( acrossServices = fromService | toService ) -func (s *composeService) Copy(ctx context.Context, project string, opts api.CopyOptions) error { - srcService, srcPath := splitCpArg(opts.Source) - destService, dstPath := splitCpArg(opts.Destination) +func (s *composeService) Copy(ctx context.Context, projectName string, options api.CopyOptions) error { + projectName = strings.ToLower(projectName) + srcService, srcPath := splitCpArg(options.Source) + destService, dstPath := splitCpArg(options.Destination) var direction copyDirection var serviceName string @@ -53,7 +54,7 @@ func (s *composeService) Copy(ctx context.Context, project string, opts api.Copy serviceName = srcService // copying from multiple containers of a services doesn't make sense. - if opts.All { + if options.All { return errors.New("cannot use the --all flag when copying from a service") } } @@ -62,7 +63,7 @@ func (s *composeService) Copy(ctx context.Context, project string, opts api.Copy serviceName = destService } - containers, err := s.getContainers(ctx, project, oneOffExclude, true, serviceName) + containers, err := s.getContainers(ctx, projectName, oneOffExclude, true, serviceName) if err != nil { return err } @@ -71,8 +72,8 @@ func (s *composeService) Copy(ctx context.Context, project string, opts api.Copy return fmt.Errorf("no container found for service %q", serviceName) } - if !opts.All { - containers = containers.filter(indexed(opts.Index)) + if !options.All { + containers = containers.filter(indexed(options.Index)) } g := errgroup.Group{} @@ -81,9 +82,9 @@ func (s *composeService) Copy(ctx context.Context, project string, opts api.Copy g.Go(func() error { switch direction { case fromService: - return s.copyFromContainer(ctx, containerID, srcPath, dstPath, opts) + return s.copyFromContainer(ctx, containerID, srcPath, dstPath, options) case toService: - return s.copyToContainer(ctx, containerID, srcPath, dstPath, opts) + return s.copyToContainer(ctx, containerID, srcPath, dstPath, options) case acrossServices: return errors.New("copying between services is not supported") default: diff --git a/pkg/compose/events.go b/pkg/compose/events.go index 4d04aaa73..172e3eec2 100644 --- a/pkg/compose/events.go +++ b/pkg/compose/events.go @@ -29,9 +29,10 @@ import ( "github.com/docker/compose/v2/pkg/utils" ) -func (s *composeService) Events(ctx context.Context, project string, options api.EventsOptions) error { +func (s *composeService) Events(ctx context.Context, projectName string, options api.EventsOptions) error { + projectName = strings.ToLower(projectName) events, errors := s.apiClient().Events(ctx, moby.EventsOptions{ - Filters: filters.NewArgs(projectFilter(project)), + Filters: filters.NewArgs(projectFilter(projectName)), }) for { select { diff --git a/pkg/compose/exec.go b/pkg/compose/exec.go index cbc6c0a11..aa1e5c58c 100644 --- a/pkg/compose/exec.go +++ b/pkg/compose/exec.go @@ -19,6 +19,7 @@ package compose import ( "context" "fmt" + "strings" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command/container" @@ -27,22 +28,23 @@ import ( "github.com/docker/docker/api/types/filters" ) -func (s *composeService) Exec(ctx context.Context, project string, opts api.RunOptions) (int, error) { - target, err := s.getExecTarget(ctx, project, opts) +func (s *composeService) Exec(ctx context.Context, projectName string, options api.RunOptions) (int, error) { + projectName = strings.ToLower(projectName) + target, err := s.getExecTarget(ctx, projectName, options) if err != nil { return 0, err } exec := container.NewExecOptions() - exec.Interactive = opts.Interactive - exec.TTY = opts.Tty - exec.Detach = opts.Detach - exec.User = opts.User - exec.Privileged = opts.Privileged - exec.Workdir = opts.WorkingDir + exec.Interactive = options.Interactive + exec.TTY = options.Tty + exec.Detach = options.Detach + exec.User = options.User + exec.Privileged = options.Privileged + exec.Workdir = options.WorkingDir exec.Container = target.ID - exec.Command = opts.Command - for _, v := range opts.Environment { + exec.Command = options.Command + for _, v := range options.Environment { err := exec.Env.Set(v) if err != nil { return 0, err diff --git a/pkg/compose/images.go b/pkg/compose/images.go index 787db8bcf..7c25b20de 100644 --- a/pkg/compose/images.go +++ b/pkg/compose/images.go @@ -32,6 +32,7 @@ import ( ) func (s *composeService) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) { + projectName = strings.ToLower(projectName) allContainers, err := s.apiClient().ContainerList(ctx, moby.ContainerListOptions{ All: true, Filters: filters.NewArgs(projectFilter(projectName)), diff --git a/pkg/compose/kill.go b/pkg/compose/kill.go index afba4f01d..aa057bc81 100644 --- a/pkg/compose/kill.go +++ b/pkg/compose/kill.go @@ -19,6 +19,7 @@ package compose import ( "context" "fmt" + "strings" moby "github.com/docker/docker/api/types" "golang.org/x/sync/errgroup" @@ -27,19 +28,19 @@ import ( "github.com/docker/compose/v2/pkg/progress" ) -func (s *composeService) Kill(ctx context.Context, project string, options api.KillOptions) error { +func (s *composeService) Kill(ctx context.Context, projectName string, options api.KillOptions) error { return progress.Run(ctx, func(ctx context.Context) error { - return s.kill(ctx, project, options) + return s.kill(ctx, strings.ToLower(projectName), options) }) } -func (s *composeService) kill(ctx context.Context, project string, options api.KillOptions) error { +func (s *composeService) kill(ctx context.Context, projectName string, options api.KillOptions) error { w := progress.ContextWriter(ctx) services := options.Services var containers Containers - containers, err := s.getContainers(ctx, project, oneOffInclude, false, services...) + containers, err := s.getContainers(ctx, projectName, oneOffInclude, false, services...) if err != nil { return err } diff --git a/pkg/compose/logs.go b/pkg/compose/logs.go index 8d58af91a..7f2520745 100644 --- a/pkg/compose/logs.go +++ b/pkg/compose/logs.go @@ -19,6 +19,7 @@ package compose import ( "context" "io" + "strings" "github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/utils" @@ -28,6 +29,7 @@ import ( ) func (s *composeService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error { + projectName = strings.ToLower(projectName) containers, err := s.getContainers(ctx, projectName, oneOffExclude, true, options.Services...) if err != nil { return err diff --git a/pkg/compose/pause.go b/pkg/compose/pause.go index 1f91217ed..3ea593eef 100644 --- a/pkg/compose/pause.go +++ b/pkg/compose/pause.go @@ -18,6 +18,7 @@ package compose import ( "context" + "strings" moby "github.com/docker/docker/api/types" "golang.org/x/sync/errgroup" @@ -26,9 +27,9 @@ import ( "github.com/docker/compose/v2/pkg/progress" ) -func (s *composeService) Pause(ctx context.Context, project string, options api.PauseOptions) error { +func (s *composeService) Pause(ctx context.Context, projectName string, options api.PauseOptions) error { return progress.Run(ctx, func(ctx context.Context) error { - return s.pause(ctx, project, options) + return s.pause(ctx, strings.ToLower(projectName), options) }) } @@ -54,14 +55,14 @@ func (s *composeService) pause(ctx context.Context, project string, options api. return eg.Wait() } -func (s *composeService) UnPause(ctx context.Context, project string, options api.PauseOptions) error { +func (s *composeService) UnPause(ctx context.Context, projectName string, options api.PauseOptions) error { return progress.Run(ctx, func(ctx context.Context) error { - return s.unPause(ctx, project, options) + return s.unPause(ctx, strings.ToLower(projectName), options) }) } -func (s *composeService) unPause(ctx context.Context, project string, options api.PauseOptions) error { - containers, err := s.getContainers(ctx, project, oneOffExclude, false, options.Services...) +func (s *composeService) unPause(ctx context.Context, projectName string, options api.PauseOptions) error { + containers, err := s.getContainers(ctx, projectName, oneOffExclude, false, options.Services...) if err != nil { return err } diff --git a/pkg/compose/port.go b/pkg/compose/port.go index d6035462c..c41781d04 100644 --- a/pkg/compose/port.go +++ b/pkg/compose/port.go @@ -19,6 +19,7 @@ package compose import ( "context" "fmt" + "strings" "github.com/docker/compose/v2/pkg/api" @@ -26,10 +27,11 @@ import ( "github.com/docker/docker/api/types/filters" ) -func (s *composeService) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) { +func (s *composeService) Port(ctx context.Context, projectName string, service string, port int, options api.PortOptions) (string, int, error) { + projectName = strings.ToLower(projectName) list, err := s.apiClient().ContainerList(ctx, moby.ContainerListOptions{ Filters: filters.NewArgs( - projectFilter(project), + projectFilter(projectName), serviceFilter(service), containerNumberFilter(options.Index), ), diff --git a/pkg/compose/ps.go b/pkg/compose/ps.go index 7a4e0b7cc..de4b25f2e 100644 --- a/pkg/compose/ps.go +++ b/pkg/compose/ps.go @@ -19,6 +19,7 @@ package compose import ( "context" "sort" + "strings" "golang.org/x/sync/errgroup" @@ -26,6 +27,7 @@ import ( ) func (s *composeService) Ps(ctx context.Context, projectName string, options api.PsOptions) ([]api.ContainerSummary, error) { + projectName = strings.ToLower(projectName) oneOff := oneOffExclude if options.All { oneOff = oneOffInclude diff --git a/pkg/compose/pull.go b/pkg/compose/pull.go index 2e8b764e1..2bd25b290 100644 --- a/pkg/compose/pull.go +++ b/pkg/compose/pull.go @@ -36,12 +36,12 @@ import ( "github.com/docker/compose/v2/pkg/progress" ) -func (s *composeService) Pull(ctx context.Context, project *types.Project, opts api.PullOptions) error { - if opts.Quiet { - return s.pull(ctx, project, opts) +func (s *composeService) Pull(ctx context.Context, project *types.Project, options api.PullOptions) error { + if options.Quiet { + return s.pull(ctx, project, options) } return progress.Run(ctx, func(ctx context.Context) error { - return s.pull(ctx, project, opts) + return s.pull(ctx, project, options) }) } diff --git a/pkg/compose/remove.go b/pkg/compose/remove.go index c5dd3dd84..cc10b71a9 100644 --- a/pkg/compose/remove.go +++ b/pkg/compose/remove.go @@ -30,6 +30,7 @@ import ( ) func (s *composeService) Remove(ctx context.Context, projectName string, options api.RemoveOptions) error { + projectName = strings.ToLower(projectName) containers, _, err := s.actualState(ctx, projectName, options.Services) if err != nil { if api.IsNotFoundError(err) { diff --git a/pkg/compose/restart.go b/pkg/compose/restart.go index 34b9d6d33..4d4f0d4cc 100644 --- a/pkg/compose/restart.go +++ b/pkg/compose/restart.go @@ -18,6 +18,7 @@ package compose import ( "context" + "strings" "github.com/docker/compose/v2/pkg/api" "golang.org/x/sync/errgroup" @@ -28,7 +29,7 @@ import ( func (s *composeService) Restart(ctx context.Context, projectName string, options api.RestartOptions) error { return progress.Run(ctx, func(ctx context.Context) error { - return s.restart(ctx, projectName, options) + return s.restart(ctx, strings.ToLower(projectName), options) }) } diff --git a/pkg/compose/start.go b/pkg/compose/start.go index 4b1e3ed2d..ff699ffb0 100644 --- a/pkg/compose/start.go +++ b/pkg/compose/start.go @@ -18,6 +18,7 @@ package compose import ( "context" + "strings" "github.com/compose-spec/compose-go/types" moby "github.com/docker/docker/api/types" @@ -30,7 +31,7 @@ import ( func (s *composeService) Start(ctx context.Context, projectName string, options api.StartOptions) error { return progress.Run(ctx, func(ctx context.Context) error { - return s.start(ctx, projectName, options, nil) + return s.start(ctx, strings.ToLower(projectName), options, nil) }) } diff --git a/pkg/compose/stop.go b/pkg/compose/stop.go index 686b852d2..520d1fa41 100644 --- a/pkg/compose/stop.go +++ b/pkg/compose/stop.go @@ -18,6 +18,7 @@ package compose import ( "context" + "strings" "github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/progress" @@ -25,7 +26,7 @@ import ( func (s *composeService) Stop(ctx context.Context, projectName string, options api.StopOptions) error { return progress.Run(ctx, func(ctx context.Context) error { - return s.stop(ctx, projectName, options) + return s.stop(ctx, strings.ToLower(projectName), options) }) } diff --git a/pkg/compose/top.go b/pkg/compose/top.go index a65b72874..1ac4cd4c4 100644 --- a/pkg/compose/top.go +++ b/pkg/compose/top.go @@ -18,12 +18,14 @@ package compose import ( "context" + "strings" "github.com/docker/compose/v2/pkg/api" "golang.org/x/sync/errgroup" ) func (s *composeService) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) { + projectName = strings.ToLower(projectName) var containers Containers containers, err := s.getContainers(ctx, projectName, oneOffInclude, false) if err != nil {