mirror of
https://github.com/docker/compose.git
synced 2026-11-20 06:59:53 +00:00
fix(build): TTY progress on Windows — hand the real stdout to buildkit
The bake progress display goes through containerd/console, which on Windows only accepts the exact os.Stdin/Stdout/Stderr values (pointer identity in newMaster) and rejects everything else with "creating a console from a file is not supported on windows". The _console wrapper introduced to satisfy buildkit's console.File type-assert therefore could never pass that check: TTY progress silently fell back to plain in auto mode, and --progress=tty / --ansi always failed hard with "failed to get console". When the CLI stream was constructed from a real file — the interactive case, where it wraps os.Stdout — hand that genuine *os.File to NewDisplay so the identity check passes. File-less streams keep the wrapper, which works on Unix where only the descriptor matters. Fixes #14086 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
8bd79da4bc
commit
9a70c817fa
2 changed files with 41 additions and 3 deletions
|
|
@ -494,11 +494,23 @@ func (s *composeService) getBuildxPlugin() (*manager.Plugin, error) {
|
|||
return buildx, nil
|
||||
}
|
||||
|
||||
// makeConsole wraps the provided writer to match [containerd.File] interface if it is of type *streams.Out.
|
||||
// buildkit's NewDisplay doesn't actually require a [io.Reader], it only uses the [containerd.Console] type to
|
||||
// benefits from ANSI capabilities, but only does writes.
|
||||
// makeConsole adapts the provided writer for buildkit's NewDisplay, which
|
||||
// requires a [console.File] to enable the TTY rendering (it only ever writes,
|
||||
// but goes through [console.ConsoleFromFile] for the ANSI capabilities).
|
||||
//
|
||||
// When the stream was constructed from a real file — the interactive case,
|
||||
// where it wraps os.Stdout — the genuine [*os.File] is handed over: on
|
||||
// Windows, containerd/console only accepts the exact os.Stdin/Stdout/Stderr
|
||||
// values (identity check in newMaster), so any wrapper fails with "creating a
|
||||
// console from a file is not supported on windows" and the TTY progress can
|
||||
// never engage (#14086). For file-less streams the [console.File] wrapper is
|
||||
// kept: the TTY rendering then works on Unix, where only the descriptor
|
||||
// matters, and falls back to plain elsewhere.
|
||||
func makeConsole(out io.Writer) io.Writer {
|
||||
if s, ok := out.(*streams.Out); ok {
|
||||
if f, ok := s.File(); ok {
|
||||
return f
|
||||
}
|
||||
return &_console{s}
|
||||
}
|
||||
return out
|
||||
|
|
|
|||
|
|
@ -17,9 +17,13 @@
|
|||
package compose
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/types"
|
||||
"github.com/docker/cli/cli/streams"
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
|
|
@ -46,3 +50,25 @@ func TestBakeTargetNames(t *testing.T) {
|
|||
"a_b.c": "a_b_c_",
|
||||
})
|
||||
}
|
||||
|
||||
// makeConsole must hand the genuine *os.File over when the stream wraps one:
|
||||
// on Windows, containerd/console rejects anything but the exact
|
||||
// os.Stdin/Stdout/Stderr values, so a wrapper would disable the TTY progress
|
||||
// rendering entirely (#14086).
|
||||
func TestMakeConsole(t *testing.T) {
|
||||
t.Run("stream wrapping a real file yields the file itself", func(t *testing.T) {
|
||||
out := makeConsole(streams.NewOut(os.Stdout))
|
||||
assert.Equal(t, out, os.Stdout)
|
||||
})
|
||||
|
||||
t.Run("file-less stream keeps the console.File wrapper", func(t *testing.T) {
|
||||
out := makeConsole(streams.NewOut(&bytes.Buffer{}))
|
||||
_, ok := out.(*_console)
|
||||
assert.Check(t, ok, "expected a *_console, got %T", out)
|
||||
})
|
||||
|
||||
t.Run("plain writer is left untouched", func(t *testing.T) {
|
||||
buf := &bytes.Buffer{}
|
||||
assert.Equal(t, makeConsole(buf), io.Writer(buf))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue