Skip to content

Commit 9668f60

Browse files
committed
project name MUST be lowercase
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 672e236 commit 9668f60

File tree

17 files changed

+85
-66
lines changed

17 files changed

+85
-66
lines changed

pkg/api/api.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ type Service interface {
3232
// Push executes the equivalent ot a `compose push`
3333
Push(ctx context.Context, project *types.Project, options PushOptions) error
3434
// Pull executes the equivalent of a `compose pull`
35-
Pull(ctx context.Context, project *types.Project, opts PullOptions) error
35+
Pull(ctx context.Context, project *types.Project, options PullOptions) error
3636
// Create executes the equivalent to a `compose create`
37-
Create(ctx context.Context, project *types.Project, opts CreateOptions) error
37+
Create(ctx context.Context, project *types.Project, options CreateOptions) error
3838
// Start executes the equivalent to a `compose start`
3939
Start(ctx context.Context, projectName string, options StartOptions) error
4040
// Restart restarts containers
@@ -54,25 +54,25 @@ type Service interface {
5454
// Convert translate compose model into backend's native format
5555
Convert(ctx context.Context, project *types.Project, options ConvertOptions) ([]byte, error)
5656
// Kill executes the equivalent to a `compose kill`
57-
Kill(ctx context.Context, project string, options KillOptions) error
57+
Kill(ctx context.Context, projectName string, options KillOptions) error
5858
// RunOneOffContainer creates a service oneoff container and starts its dependencies
5959
RunOneOffContainer(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
6060
// Remove executes the equivalent to a `compose rm`
61-
Remove(ctx context.Context, project string, options RemoveOptions) error
61+
Remove(ctx context.Context, projectName string, options RemoveOptions) error
6262
// Exec executes a command in a running service container
63-
Exec(ctx context.Context, project string, opts RunOptions) (int, error)
63+
Exec(ctx context.Context, projectName string, options RunOptions) (int, error)
6464
// Copy copies a file/folder between a service container and the local filesystem
65-
Copy(ctx context.Context, project string, options CopyOptions) error
65+
Copy(ctx context.Context, projectName string, options CopyOptions) error
6666
// Pause executes the equivalent to a `compose pause`
67-
Pause(ctx context.Context, project string, options PauseOptions) error
67+
Pause(ctx context.Context, projectName string, options PauseOptions) error
6868
// UnPause executes the equivalent to a `compose unpause`
69-
UnPause(ctx context.Context, project string, options PauseOptions) error
69+
UnPause(ctx context.Context, projectName string, options PauseOptions) error
7070
// Top executes the equivalent to a `compose top`
7171
Top(ctx context.Context, projectName string, services []string) ([]ContainerProcSummary, error)
7272
// Events executes the equivalent to a `compose events`
73-
Events(ctx context.Context, project string, options EventsOptions) error
73+
Events(ctx context.Context, projectName string, options EventsOptions) error
7474
// Port executes the equivalent to a `compose port`
75-
Port(ctx context.Context, project string, service string, port int, options PortOptions) (string, int, error)
75+
Port(ctx context.Context, projectName string, service string, port int, options PortOptions) (string, int, error)
7676
// Images executes the equivalent of a `compose images`
7777
Images(ctx context.Context, projectName string, options ImagesOptions) ([]ImageSummary, error)
7878
}

pkg/api/proxy.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ func (s *ServiceProxy) Convert(ctx context.Context, project *types.Project, opti
219219
}
220220

221221
// Kill implements Service interface
222-
func (s *ServiceProxy) Kill(ctx context.Context, project string, options KillOptions) error {
222+
func (s *ServiceProxy) Kill(ctx context.Context, projectName string, options KillOptions) error {
223223
if s.KillFn == nil {
224224
return ErrNotImplemented
225225
}
226-
return s.KillFn(ctx, project, options)
226+
return s.KillFn(ctx, projectName, options)
227227
}
228228

229229
// RunOneOffContainer implements Service interface
@@ -238,43 +238,43 @@ func (s *ServiceProxy) RunOneOffContainer(ctx context.Context, project *types.Pr
238238
}
239239

240240
// Remove implements Service interface
241-
func (s *ServiceProxy) Remove(ctx context.Context, project string, options RemoveOptions) error {
241+
func (s *ServiceProxy) Remove(ctx context.Context, projectName string, options RemoveOptions) error {
242242
if s.RemoveFn == nil {
243243
return ErrNotImplemented
244244
}
245-
return s.RemoveFn(ctx, project, options)
245+
return s.RemoveFn(ctx, projectName, options)
246246
}
247247

248248
// Exec implements Service interface
249-
func (s *ServiceProxy) Exec(ctx context.Context, project string, options RunOptions) (int, error) {
249+
func (s *ServiceProxy) Exec(ctx context.Context, projectName string, options RunOptions) (int, error) {
250250
if s.ExecFn == nil {
251251
return 0, ErrNotImplemented
252252
}
253-
return s.ExecFn(ctx, project, options)
253+
return s.ExecFn(ctx, projectName, options)
254254
}
255255

256256
// Copy implements Service interface
257-
func (s *ServiceProxy) Copy(ctx context.Context, project string, options CopyOptions) error {
257+
func (s *ServiceProxy) Copy(ctx context.Context, projectName string, options CopyOptions) error {
258258
if s.CopyFn == nil {
259259
return ErrNotImplemented
260260
}
261-
return s.CopyFn(ctx, project, options)
261+
return s.CopyFn(ctx, projectName, options)
262262
}
263263

264264
// Pause implements Service interface
265-
func (s *ServiceProxy) Pause(ctx context.Context, project string, options PauseOptions) error {
265+
func (s *ServiceProxy) Pause(ctx context.Context, projectName string, options PauseOptions) error {
266266
if s.PauseFn == nil {
267267
return ErrNotImplemented
268268
}
269-
return s.PauseFn(ctx, project, options)
269+
return s.PauseFn(ctx, projectName, options)
270270
}
271271

272272
// UnPause implements Service interface
273-
func (s *ServiceProxy) UnPause(ctx context.Context, project string, options PauseOptions) error {
273+
func (s *ServiceProxy) UnPause(ctx context.Context, projectName string, options PauseOptions) error {
274274
if s.UnPauseFn == nil {
275275
return ErrNotImplemented
276276
}
277-
return s.UnPauseFn(ctx, project, options)
277+
return s.UnPauseFn(ctx, projectName, options)
278278
}
279279

280280
// Top implements Service interface
@@ -286,19 +286,19 @@ func (s *ServiceProxy) Top(ctx context.Context, project string, services []strin
286286
}
287287

288288
// Events implements Service interface
289-
func (s *ServiceProxy) Events(ctx context.Context, project string, options EventsOptions) error {
289+
func (s *ServiceProxy) Events(ctx context.Context, projectName string, options EventsOptions) error {
290290
if s.EventsFn == nil {
291291
return ErrNotImplemented
292292
}
293-
return s.EventsFn(ctx, project, options)
293+
return s.EventsFn(ctx, projectName, options)
294294
}
295295

296296
// Port implements Service interface
297-
func (s *ServiceProxy) Port(ctx context.Context, project string, service string, port int, options PortOptions) (string, int, error) {
297+
func (s *ServiceProxy) Port(ctx context.Context, projectName string, service string, port int, options PortOptions) (string, int, error) {
298298
if s.PortFn == nil {
299299
return "", 0, ErrNotImplemented
300300
}
301-
return s.PortFn(ctx, project, service, port, options)
301+
return s.PortFn(ctx, projectName, service, port, options)
302302
}
303303

304304
// Images implements Service interface

pkg/compose/cp.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ const (
4242
acrossServices = fromService | toService
4343
)
4444

45-
func (s *composeService) Copy(ctx context.Context, project string, opts api.CopyOptions) error {
46-
srcService, srcPath := splitCpArg(opts.Source)
47-
destService, dstPath := splitCpArg(opts.Destination)
45+
func (s *composeService) Copy(ctx context.Context, projectName string, options api.CopyOptions) error {
46+
projectName = strings.ToLower(projectName)
47+
srcService, srcPath := splitCpArg(options.Source)
48+
destService, dstPath := splitCpArg(options.Destination)
4849

4950
var direction copyDirection
5051
var serviceName string
@@ -53,7 +54,7 @@ func (s *composeService) Copy(ctx context.Context, project string, opts api.Copy
5354
serviceName = srcService
5455

5556
// copying from multiple containers of a services doesn't make sense.
56-
if opts.All {
57+
if options.All {
5758
return errors.New("cannot use the --all flag when copying from a service")
5859
}
5960
}
@@ -62,7 +63,7 @@ func (s *composeService) Copy(ctx context.Context, project string, opts api.Copy
6263
serviceName = destService
6364
}
6465

65-
containers, err := s.getContainers(ctx, project, oneOffExclude, true, serviceName)
66+
containers, err := s.getContainers(ctx, projectName, oneOffExclude, true, serviceName)
6667
if err != nil {
6768
return err
6869
}
@@ -71,8 +72,8 @@ func (s *composeService) Copy(ctx context.Context, project string, opts api.Copy
7172
return fmt.Errorf("no container found for service %q", serviceName)
7273
}
7374

74-
if !opts.All {
75-
containers = containers.filter(indexed(opts.Index))
75+
if !options.All {
76+
containers = containers.filter(indexed(options.Index))
7677
}
7778

7879
g := errgroup.Group{}
@@ -81,9 +82,9 @@ func (s *composeService) Copy(ctx context.Context, project string, opts api.Copy
8182
g.Go(func() error {
8283
switch direction {
8384
case fromService:
84-
return s.copyFromContainer(ctx, containerID, srcPath, dstPath, opts)
85+
return s.copyFromContainer(ctx, containerID, srcPath, dstPath, options)
8586
case toService:
86-
return s.copyToContainer(ctx, containerID, srcPath, dstPath, opts)
87+
return s.copyToContainer(ctx, containerID, srcPath, dstPath, options)
8788
case acrossServices:
8889
return errors.New("copying between services is not supported")
8990
default:

pkg/compose/events.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ import (
2929
"github.com/docker/compose/v2/pkg/utils"
3030
)
3131

32-
func (s *composeService) Events(ctx context.Context, project string, options api.EventsOptions) error {
32+
func (s *composeService) Events(ctx context.Context, projectName string, options api.EventsOptions) error {
33+
projectName = strings.ToLower(projectName)
3334
events, errors := s.apiClient().Events(ctx, moby.EventsOptions{
34-
Filters: filters.NewArgs(projectFilter(project)),
35+
Filters: filters.NewArgs(projectFilter(projectName)),
3536
})
3637
for {
3738
select {

pkg/compose/exec.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package compose
1919
import (
2020
"context"
2121
"fmt"
22+
"strings"
2223

2324
"github.com/docker/cli/cli"
2425
"github.com/docker/cli/cli/command/container"
@@ -27,22 +28,23 @@ import (
2728
"github.com/docker/docker/api/types/filters"
2829
)
2930

30-
func (s *composeService) Exec(ctx context.Context, project string, opts api.RunOptions) (int, error) {
31-
target, err := s.getExecTarget(ctx, project, opts)
31+
func (s *composeService) Exec(ctx context.Context, projectName string, options api.RunOptions) (int, error) {
32+
projectName = strings.ToLower(projectName)
33+
target, err := s.getExecTarget(ctx, projectName, options)
3234
if err != nil {
3335
return 0, err
3436
}
3537

3638
exec := container.NewExecOptions()
37-
exec.Interactive = opts.Interactive
38-
exec.TTY = opts.Tty
39-
exec.Detach = opts.Detach
40-
exec.User = opts.User
41-
exec.Privileged = opts.Privileged
42-
exec.Workdir = opts.WorkingDir
39+
exec.Interactive = options.Interactive
40+
exec.TTY = options.Tty
41+
exec.Detach = options.Detach
42+
exec.User = options.User
43+
exec.Privileged = options.Privileged
44+
exec.Workdir = options.WorkingDir
4345
exec.Container = target.ID
44-
exec.Command = opts.Command
45-
for _, v := range opts.Environment {
46+
exec.Command = options.Command
47+
for _, v := range options.Environment {
4648
err := exec.Env.Set(v)
4749
if err != nil {
4850
return 0, err

pkg/compose/images.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
)
3333

3434
func (s *composeService) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) {
35+
projectName = strings.ToLower(projectName)
3536
allContainers, err := s.apiClient().ContainerList(ctx, moby.ContainerListOptions{
3637
All: true,
3738
Filters: filters.NewArgs(projectFilter(projectName)),

pkg/compose/kill.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package compose
1919
import (
2020
"context"
2121
"fmt"
22+
"strings"
2223

2324
moby "github.com/docker/docker/api/types"
2425
"golang.org/x/sync/errgroup"
@@ -27,19 +28,19 @@ import (
2728
"github.com/docker/compose/v2/pkg/progress"
2829
)
2930

30-
func (s *composeService) Kill(ctx context.Context, project string, options api.KillOptions) error {
31+
func (s *composeService) Kill(ctx context.Context, projectName string, options api.KillOptions) error {
3132
return progress.Run(ctx, func(ctx context.Context) error {
32-
return s.kill(ctx, project, options)
33+
return s.kill(ctx, strings.ToLower(projectName), options)
3334
})
3435
}
3536

36-
func (s *composeService) kill(ctx context.Context, project string, options api.KillOptions) error {
37+
func (s *composeService) kill(ctx context.Context, projectName string, options api.KillOptions) error {
3738
w := progress.ContextWriter(ctx)
3839

3940
services := options.Services
4041

4142
var containers Containers
42-
containers, err := s.getContainers(ctx, project, oneOffInclude, false, services...)
43+
containers, err := s.getContainers(ctx, projectName, oneOffInclude, false, services...)
4344
if err != nil {
4445
return err
4546
}

pkg/compose/logs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package compose
1919
import (
2020
"context"
2121
"io"
22+
"strings"
2223

2324
"github.com/docker/compose/v2/pkg/api"
2425
"github.com/docker/compose/v2/pkg/utils"
@@ -28,6 +29,7 @@ import (
2829
)
2930

3031
func (s *composeService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error {
32+
projectName = strings.ToLower(projectName)
3133
containers, err := s.getContainers(ctx, projectName, oneOffExclude, true, options.Services...)
3234
if err != nil {
3335
return err

pkg/compose/pause.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package compose
1818

1919
import (
2020
"context"
21+
"strings"
2122

2223
moby "github.com/docker/docker/api/types"
2324
"golang.org/x/sync/errgroup"
@@ -26,9 +27,9 @@ import (
2627
"github.com/docker/compose/v2/pkg/progress"
2728
)
2829

29-
func (s *composeService) Pause(ctx context.Context, project string, options api.PauseOptions) error {
30+
func (s *composeService) Pause(ctx context.Context, projectName string, options api.PauseOptions) error {
3031
return progress.Run(ctx, func(ctx context.Context) error {
31-
return s.pause(ctx, project, options)
32+
return s.pause(ctx, strings.ToLower(projectName), options)
3233
})
3334
}
3435

@@ -54,14 +55,14 @@ func (s *composeService) pause(ctx context.Context, project string, options api.
5455
return eg.Wait()
5556
}
5657

57-
func (s *composeService) UnPause(ctx context.Context, project string, options api.PauseOptions) error {
58+
func (s *composeService) UnPause(ctx context.Context, projectName string, options api.PauseOptions) error {
5859
return progress.Run(ctx, func(ctx context.Context) error {
59-
return s.unPause(ctx, project, options)
60+
return s.unPause(ctx, strings.ToLower(projectName), options)
6061
})
6162
}
6263

63-
func (s *composeService) unPause(ctx context.Context, project string, options api.PauseOptions) error {
64-
containers, err := s.getContainers(ctx, project, oneOffExclude, false, options.Services...)
64+
func (s *composeService) unPause(ctx context.Context, projectName string, options api.PauseOptions) error {
65+
containers, err := s.getContainers(ctx, projectName, oneOffExclude, false, options.Services...)
6566
if err != nil {
6667
return err
6768
}

pkg/compose/port.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ package compose
1919
import (
2020
"context"
2121
"fmt"
22+
"strings"
2223

2324
"github.com/docker/compose/v2/pkg/api"
2425

2526
moby "github.com/docker/docker/api/types"
2627
"github.com/docker/docker/api/types/filters"
2728
)
2829

29-
func (s *composeService) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) {
30+
func (s *composeService) Port(ctx context.Context, projectName string, service string, port int, options api.PortOptions) (string, int, error) {
31+
projectName = strings.ToLower(projectName)
3032
list, err := s.apiClient().ContainerList(ctx, moby.ContainerListOptions{
3133
Filters: filters.NewArgs(
32-
projectFilter(project),
34+
projectFilter(projectName),
3335
serviceFilter(service),
3436
containerNumberFilter(options.Index),
3537
),

0 commit comments

Comments
 (0)