Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/buger/goterm v1.0.4
github.com/compose-spec/compose-go/v2 v2.1.3
github.com/containerd/console v1.0.4
github.com/containerd/containerd v1.7.18
github.com/davecgh/go-spew v1.1.1
github.com/distribution/reference v0.6.0
Expand Down Expand Up @@ -81,6 +80,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/console v1.0.4 // indirect
github.com/containerd/continuity v0.4.3 // indirect
github.com/containerd/errdefs v0.1.0 // indirect
github.com/containerd/log v0.1.0 // indirect
Expand Down
5 changes: 2 additions & 3 deletions pkg/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"errors"
"fmt"
"io"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -129,11 +128,11 @@ func (s *composeService) stdin() *streams.In {
return s.dockerCli.In()
}

func (s *composeService) stderr() io.Writer {
func (s *composeService) stderr() *streams.Out {
return s.dockerCli.Err()
}

func (s *composeService) stdinfo() io.Writer {
func (s *composeService) stdinfo() *streams.Out {
if stdioToStdout {
return s.dockerCli.Out()
}
Expand Down
38 changes: 14 additions & 24 deletions pkg/progress/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import (
"io"
"sync"

"github.com/containerd/console"
"github.com/moby/term"
"github.com/sirupsen/logrus"
"github.com/docker/cli/cli/streams"
"golang.org/x/sync/errgroup"

"github.com/docker/compose/v2/pkg/api"
Expand Down Expand Up @@ -59,22 +57,22 @@ type progressFunc func(context.Context) error
type progressFuncWithStatus func(context.Context) (string, error)

// Run will run a writer and the progress function in parallel
func Run(ctx context.Context, pf progressFunc, out io.Writer) error {
func Run(ctx context.Context, pf progressFunc, out *streams.Out) error {
_, err := RunWithStatus(ctx, func(ctx context.Context) (string, error) {
return "", pf(ctx)
}, out, "Running")
return err
}

func RunWithTitle(ctx context.Context, pf progressFunc, out io.Writer, progressTitle string) error {
func RunWithTitle(ctx context.Context, pf progressFunc, out *streams.Out, progressTitle string) error {
_, err := RunWithStatus(ctx, func(ctx context.Context) (string, error) {
return "", pf(ctx)
}, out, progressTitle)
return err
}

// RunWithStatus will run a writer and the progress function in parallel and return a status
func RunWithStatus(ctx context.Context, pf progressFuncWithStatus, out io.Writer, progressTitle string) (string, error) {
func RunWithStatus(ctx context.Context, pf progressFuncWithStatus, out *streams.Out, progressTitle string) (string, error) {
eg, _ := errgroup.WithContext(ctx)
w, err := NewWriter(ctx, out, progressTitle)
var result string
Expand Down Expand Up @@ -115,25 +113,22 @@ const (
var Mode = ModeAuto

// NewWriter returns a new multi-progress writer
func NewWriter(ctx context.Context, out io.Writer, progressTitle string) (Writer, error) {
_, isTerminal := term.GetFdInfo(out)
func NewWriter(ctx context.Context, out *streams.Out, progressTitle string) (Writer, error) {
isTerminal := out.IsTerminal()
dryRun, ok := ctx.Value(api.DryRunKey{}).(bool)
if !ok {
dryRun = false
}
if Mode == ModeQuiet {
return quiet{}, nil
}
f, isConsole := out.(console.File) // see https://github.com/docker/compose/issues/10560
if Mode == ModeAuto && isTerminal && isConsole {
return newTTYWriter(f, dryRun, progressTitle)

tty := Mode == ModeTTY
if Mode == ModeAuto && isTerminal {
tty = true
}
if Mode == ModeTTY {
if !isConsole {
logrus.Warn("Terminal is not a POSIX console")
} else {
return newTTYWriter(f, dryRun, progressTitle)
}
if tty {
return newTTYWriter(out, dryRun, progressTitle)
}
return &plainWriter{
out: out,
Expand All @@ -142,14 +137,9 @@ func NewWriter(ctx context.Context, out io.Writer, progressTitle string) (Writer
}, nil
}

func newTTYWriter(out console.File, dryRun bool, progressTitle string) (Writer, error) {
con, err := console.ConsoleFromFile(out)
if err != nil {
return nil, err
}

func newTTYWriter(out io.Writer, dryRun bool, progressTitle string) (Writer, error) {
return &ttyWriter{
out: con,
out: out,
eventIDs: []string{},
events: map[string]Event{},
repeated: false,
Expand Down