Skip to content

Commit e1ce7cd

Browse files
committed
fix support for BUILDKIT_PROGRESS
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 60256a8 commit e1ce7cd

File tree

3 files changed

+21
-30
lines changed

3 files changed

+21
-30
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
}

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)