Skip to content

Commit 693b9ef

Browse files
ndeloofglours
authored andcommitted
fix support for BUILDKIT_PROGRESS
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 046879a commit 693b9ef

File tree

6 files changed

+22
-33
lines changed

6 files changed

+22
-33
lines changed

cmd/compose/build.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/docker/cli/cli/command"
2828
cliopts "github.com/docker/cli/opts"
2929
ui "github.com/docker/compose/v2/pkg/progress"
30-
buildkit "github.com/moby/buildkit/util/progress/progressui"
3130
"github.com/spf13/cobra"
3231

3332
"github.com/docker/compose/v2/pkg/api"
@@ -137,7 +136,7 @@ func buildCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service)
137136
flags.Bool("no-rm", false, "Do not remove intermediate containers after a successful build. DEPRECATED")
138137
flags.MarkHidden("no-rm") //nolint:errcheck
139138
flags.VarP(&opts.memory, "memory", "m", "Set memory limit for the build container. Not supported by BuildKit.")
140-
flags.StringVar(&p.Progress, "progress", string(buildkit.AutoMode), fmt.Sprintf(`Set type of ui output (%s)`, strings.Join(printerModes, ", ")))
139+
flags.StringVar(&p.Progress, "progress", "", fmt.Sprintf(`Set type of ui output (%s)`, strings.Join(printerModes, ", ")))
141140
flags.MarkHidden("progress") //nolint:errcheck
142141
flags.BoolVar(&opts.print, "print", false, "Print equivalent bake file")
143142
flags.BoolVar(&opts.check, "check", false, "Check build configuration")

cmd/compose/compose.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import (
4747
ui "github.com/docker/compose/v2/pkg/progress"
4848
"github.com/docker/compose/v2/pkg/remote"
4949
"github.com/docker/compose/v2/pkg/utils"
50-
buildkit "github.com/moby/buildkit/util/progress/progressui"
5150
"github.com/morikuni/aec"
5251
"github.com/sirupsen/logrus"
5352
"github.com/spf13/cobra"
@@ -230,7 +229,7 @@ func (o *ProjectOptions) addProjectFlags(f *pflag.FlagSet) {
230229
f.StringVar(&o.ProjectDir, "project-directory", "", "Specify an alternate working directory\n(default: the path of the, first specified, Compose file)")
231230
f.StringVar(&o.WorkDir, "workdir", "", "DEPRECATED! USE --project-directory INSTEAD.\nSpecify an alternate working directory\n(default: the path of the, first specified, Compose file)")
232231
f.BoolVar(&o.Compatibility, "compatibility", false, "Run compose in backward compatibility mode")
233-
f.StringVar(&o.Progress, "progress", defaultStringVar(ComposeProgress, string(buildkit.AutoMode)), fmt.Sprintf(`Set type of progress output (%s)`, strings.Join(printerModes, ", ")))
232+
f.StringVar(&o.Progress, "progress", os.Getenv(ComposeProgress), fmt.Sprintf(`Set type of progress output (%s)`, strings.Join(printerModes, ", ")))
234233
f.BoolVar(&o.All, "all-resources", false, "Include all resources, even those not used by services")
235234
_ = f.MarkHidden("workdir")
236235
}
@@ -242,14 +241,6 @@ func defaultStringArrayVar(env string) []string {
242241
})
243242
}
244243

245-
// get default value for a command line flag from the env variable, if the env variable is not set, it returns the provided default value 'def'
246-
func defaultStringVar(env, def string) string {
247-
if v, ok := os.LookupEnv(env); ok {
248-
return v
249-
}
250-
return def
251-
}
252-
253244
func (o *ProjectOptions) projectOrName(ctx context.Context, dockerCli command.Cli, services ...string) (*types.Project, string, error) {
254245
name := o.ProjectName
255246
var project *types.Project
@@ -516,8 +507,7 @@ func RootCommand(dockerCli command.Cli, backend Backend) *cobra.Command { //noli
516507
}
517508

518509
switch opts.Progress {
519-
case ui.ModeAuto:
520-
ui.Mode = ui.ModeAuto
510+
case "", ui.ModeAuto:
521511
if ansi == "never" {
522512
ui.Mode = ui.ModePlain
523513
}

docs/reference/compose.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Define and run multi-container applications with Docker
5959
| `-f`, `--file` | `stringArray` | | Compose configuration files |
6060
| `--parallel` | `int` | `-1` | Control max parallelism, -1 for unlimited |
6161
| `--profile` | `stringArray` | | Specify a profile to enable |
62-
| `--progress` | `string` | `auto` | Set type of progress output (auto, tty, plain, json, quiet) |
62+
| `--progress` | `string` | | Set type of progress output (auto, tty, plain, json, quiet) |
6363
| `--project-directory` | `string` | | Specify an alternate working directory<br>(default: the path of the, first specified, Compose file) |
6464
| `-p`, `--project-name` | `string` | | Project name |
6565

docs/reference/docker_compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ options:
169169
swarm: false
170170
- option: progress
171171
value_type: string
172-
default_value: auto
173172
description: Set type of progress output (auto, tty, plain, json, quiet)
174173
deprecated: false
175174
hidden: false

docs/reference/docker_compose_build.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ options:
118118
swarm: false
119119
- option: progress
120120
value_type: string
121-
default_value: auto
122121
description: Set type of ui output (auto, tty, plain, json, quiet)
123122
deprecated: false
124123
hidden: true

pkg/progress/writer.go

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

1919
import (
2020
"context"
21+
"fmt"
2122
"io"
2223
"sync"
2324

@@ -121,29 +122,30 @@ func NewWriter(ctx context.Context, out *streams.Out, progressTitle string) (Wri
121122
if !ok {
122123
dryRun = false
123124
}
124-
if Mode == ModeQuiet {
125+
switch Mode {
126+
case ModeQuiet:
125127
return quiet{}, nil
126-
}
127-
128-
tty := Mode == ModeTTY
129-
if Mode == ModeAuto && isTerminal {
130-
tty = true
131-
}
132-
if tty {
133-
return newTTYWriter(out, dryRun, progressTitle)
134-
}
135-
if Mode == ModeJSON {
128+
case ModeJSON:
136129
return &jsonWriter{
137130
out: out,
138131
done: make(chan bool),
139132
dryRun: dryRun,
140133
}, nil
134+
case ModeTTY:
135+
return newTTYWriter(out, dryRun, progressTitle)
136+
case ModeAuto, "":
137+
if isTerminal {
138+
return newTTYWriter(out, dryRun, progressTitle)
139+
}
140+
fallthrough
141+
case ModePlain:
142+
return &plainWriter{
143+
out: out,
144+
done: make(chan bool),
145+
dryRun: dryRun,
146+
}, nil
141147
}
142-
return &plainWriter{
143-
out: out,
144-
done: make(chan bool),
145-
dryRun: dryRun,
146-
}, nil
148+
return nil, fmt.Errorf("unknown progress mode: %s", Mode)
147149
}
148150

149151
func newTTYWriter(out io.Writer, dryRun bool, progressTitle string) (Writer, error) {

0 commit comments

Comments
 (0)