mirror of
https://github.com/docker/compose.git
synced 2025-04-08 17:05:13 +02:00
project name MUST be lowercase
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
672e2367fb
commit
9668f600d1
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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)),
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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),
|
||||
),
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user