Skip to content

Commit 89dfb91

Browse files
Merge branch 'v2' into 8768-avoid-pulling-same-image-multiple-times
2 parents d62c9fe + 52eeda9 commit 89dfb91

32 files changed

+1319
-542
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ jobs:
2828
- name: Run golangci-lint
2929
env:
3030
BUILD_TAGS: e2e
31-
run: |
32-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/bin/ v1.39.0
33-
make -f builder.Makefile lint
31+
uses: golangci/golangci-lint-action@v2
32+
with:
33+
args: --timeout=180s
3434

3535
# only on main branch, costs too much for the gain on every PR
3636
validate-cross-build:

cmd/compose/compose.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,6 @@ func (o *projectOptions) WithServices(fn ProjectServicesFunc) func(cmd *cobra.Co
120120
return err
121121
}
122122

123-
if o.EnvFile != "" {
124-
var services types.Services
125-
for _, s := range project.Services {
126-
ef := o.EnvFile
127-
if ef != "" {
128-
if !filepath.IsAbs(ef) {
129-
ef = filepath.Join(project.WorkingDir, o.EnvFile)
130-
}
131-
if s.Labels == nil {
132-
s.Labels = make(map[string]string)
133-
}
134-
s.Labels[api.EnvironmentFileLabel] = ef
135-
services = append(services, s)
136-
}
137-
}
138-
project.Services = services
139-
}
140-
141123
return fn(ctx, project, args)
142124
})
143125
}
@@ -180,6 +162,25 @@ func (o *projectOptions) toProject(services []string, po ...cli.ProjectOptionsFn
180162
compose.Separator = "_"
181163
}
182164

165+
ef := o.EnvFile
166+
if ef != "" && !filepath.IsAbs(ef) {
167+
ef = filepath.Join(project.WorkingDir, o.EnvFile)
168+
}
169+
for i, s := range project.Services {
170+
s.CustomLabels = map[string]string{
171+
api.ProjectLabel: project.Name,
172+
api.ServiceLabel: s.Name,
173+
api.VersionLabel: api.ComposeVersion,
174+
api.WorkingDirLabel: project.WorkingDir,
175+
api.ConfigFilesLabel: strings.Join(project.ComposeFiles, ","),
176+
api.OneoffLabel: "False", // default, will be overridden by `run` command
177+
}
178+
if ef != "" {
179+
s.CustomLabels[api.EnvironmentFileLabel] = ef
180+
}
181+
project.Services[i] = s
182+
}
183+
183184
if len(services) > 0 {
184185
s, err := project.GetServices(services...)
185186
if err != nil {

cmd/compose/down.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ package compose
1919
import (
2020
"context"
2121
"fmt"
22+
"os"
23+
"strings"
2224
"time"
2325

2426
"github.com/compose-spec/compose-go/types"
27+
"github.com/sirupsen/logrus"
2528
"github.com/spf13/cobra"
29+
"github.com/spf13/pflag"
2630

2731
"github.com/docker/compose/v2/pkg/api"
2832
)
@@ -58,10 +62,19 @@ func downCommand(p *projectOptions, backend api.Service) *cobra.Command {
5862
ValidArgsFunction: noCompletion(),
5963
}
6064
flags := downCmd.Flags()
61-
flags.BoolVar(&opts.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file.")
65+
removeOrphans := strings.ToLower(os.Getenv("COMPOSE_REMOVE_ORPHANS ")) == "true"
66+
flags.BoolVar(&opts.removeOrphans, "remove-orphans", removeOrphans, "Remove containers for services not defined in the Compose file.")
6267
flags.IntVarP(&opts.timeout, "timeout", "t", 10, "Specify a shutdown timeout in seconds")
6368
flags.BoolVarP(&opts.volumes, "volumes", "v", false, " Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers.")
6469
flags.StringVar(&opts.images, "rmi", "", `Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")`)
70+
flags.SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName {
71+
switch name {
72+
case "volume":
73+
name = "volumes"
74+
logrus.Warn("--volume is deprecated, please use --volumes")
75+
}
76+
return pflag.NormalizedName(name)
77+
})
6578
return downCmd
6679
}
6780

cmd/compose/list.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,24 @@ func runList(ctx context.Context, backend api.Service, opts lsOptions) error {
9292
view := viewFromStackList(stackList)
9393
return formatter.Print(view, opts.Format, os.Stdout, func(w io.Writer) {
9494
for _, stack := range view {
95-
_, _ = fmt.Fprintf(w, "%s\t%s\n", stack.Name, stack.Status)
95+
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\n", stack.Name, stack.Status, stack.ConfigFiles)
9696
}
97-
}, "NAME", "STATUS")
97+
}, "NAME", "STATUS", "CONFIG FILES")
9898
}
9999

100100
type stackView struct {
101-
Name string
102-
Status string
101+
Name string
102+
Status string
103+
ConfigFiles string
103104
}
104105

105106
func viewFromStackList(stackList []api.Stack) []stackView {
106107
retList := make([]stackView, len(stackList))
107108
for i, s := range stackList {
108109
retList[i] = stackView{
109-
Name: s.Name,
110-
Status: strings.TrimSpace(fmt.Sprintf("%s %s", s.Status, s.Reason)),
110+
Name: s.Name,
111+
Status: strings.TrimSpace(fmt.Sprintf("%s %s", s.Status, s.Reason)),
112+
ConfigFiles: s.ConfigFiles,
111113
}
112114
}
113115
return retList

cmd/compose/remove.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func runRemove(ctx context.Context, backend api.Service, opts removeOptions, ser
6565
}
6666

6767
if opts.stop {
68-
err := backend.Stop(ctx, project, api.StopOptions{
68+
err := backend.Stop(ctx, project.Name, api.StopOptions{
6969
Services: services,
7070
})
7171
if err != nil {

cmd/compose/restart.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ func restartCommand(p *projectOptions, backend api.Service) *cobra.Command {
4949
}
5050

5151
func runRestart(ctx context.Context, backend api.Service, opts restartOptions, services []string) error {
52-
project, err := opts.toProject(services)
52+
projectName, err := opts.toProjectName()
5353
if err != nil {
5454
return err
5555
}
5656

5757
timeout := time.Duration(opts.timeout) * time.Second
58-
return backend.Restart(ctx, project, api.RestartOptions{
58+
return backend.Restart(ctx, projectName, api.RestartOptions{
5959
Timeout: &timeout,
6060
Services: services,
6161
})

cmd/compose/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,5 +240,5 @@ func startDependencies(ctx context.Context, backend api.Service, project types.P
240240
if err := backend.Create(ctx, &project, api.CreateOptions{}); err != nil {
241241
return err
242242
}
243-
return backend.Start(ctx, &project, api.StartOptions{})
243+
return backend.Start(ctx, project.Name, api.StartOptions{})
244244
}

cmd/compose/start.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ func startCommand(p *projectOptions, backend api.Service) *cobra.Command {
4343
}
4444

4545
func runStart(ctx context.Context, backend api.Service, opts startOptions, services []string) error {
46-
project, err := opts.toProject(services)
46+
projectName, err := opts.toProjectName()
4747
if err != nil {
4848
return err
4949
}
5050

51-
return backend.Start(ctx, project, api.StartOptions{})
51+
return backend.Start(ctx, projectName, api.StartOptions{
52+
AttachTo: services,
53+
})
5254
}

cmd/compose/stop.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func stopCommand(p *projectOptions, backend api.Service) *cobra.Command {
5353
}
5454

5555
func runStop(ctx context.Context, backend api.Service, opts stopOptions, services []string) error {
56-
project, err := opts.toProject(services)
56+
projectName, err := opts.toProjectName()
5757
if err != nil {
5858
return err
5959
}
@@ -63,7 +63,7 @@ func runStop(ctx context.Context, backend api.Service, opts stopOptions, service
6363
timeoutValue := time.Duration(opts.timeout) * time.Second
6464
timeout = &timeoutValue
6565
}
66-
return backend.Stop(ctx, project, api.StopOptions{
66+
return backend.Stop(ctx, projectName, api.StopOptions{
6767
Timeout: timeout,
6868
Services: services,
6969
})

docs/yaml/main/generate.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@ func generateCliYaml(opts *options) error {
3232
disableFlagsInUseLine(cmd)
3333

3434
cmd.DisableAutoGenTag = true
35-
return clidocstool.GenYamlTree(cmd, opts.target)
35+
tool, err := clidocstool.New(clidocstool.Options{
36+
Root: cmd,
37+
SourceDir: opts.source,
38+
TargetDir: opts.target,
39+
Plugin: true,
40+
})
41+
if err != nil {
42+
return err
43+
}
44+
return tool.GenYamlTree(cmd)
3645
}
3746

3847
func disableFlagsInUseLine(cmd *cobra.Command) {

0 commit comments

Comments
 (0)