Explorar o código

Add support for COMPOSE_PROGRESS env variable

COMPOSE_PROGRESS variable supports 5 values:
- "auto" - detect console capabilities
- "tty" - use terminal capability for advanced rendering
- "plain" - dump raw events to output
- "quiet" - don't display events
- "json" - outputs a machine-readable JSON stream

Signed-off-by: Anvar Umuraliev <[email protected]>
Anvar Umuraliev hai 7 meses
pai
achega
f8dae06df8
Modificáronse 2 ficheiros con 16 adicións e 0 borrados
  1. 12 0
      pkg/e2e/compose_run_test.go
  2. 4 0
      pkg/progress/writer.go

+ 12 - 0
pkg/e2e/compose_run_test.go

@@ -170,6 +170,18 @@ func TestLocalComposeRun(t *testing.T) {
 		assert.Assert(t, strings.Contains(res.Combined(), "Pulled"), res.Combined())
 	})
 
+	t.Run("COMPOSE_PROGRESS quiet", func(t *testing.T) {
+		res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/quiet-pull.yaml", "down", "--remove-orphans", "--rmi", "all")
+		res.Assert(t, icmd.Success)
+
+		cmd := c.NewDockerComposeCmd(t, "-f", "./fixtures/run-test/quiet-pull.yaml", "run", "backend")
+		res = icmd.RunCmd(cmd, func(c *icmd.Cmd) {
+			c.Env = append(c.Env, "COMPOSE_PROGRESS=quiet")
+		})
+		assert.Assert(t, !strings.Contains(res.Combined(), "Pull complete"), res.Combined())
+		assert.Assert(t, !strings.Contains(res.Combined(), "Pulled"), res.Combined())
+	})
+
 	t.Run("--pull", func(t *testing.T) {
 		res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/pull.yaml", "down", "--remove-orphans", "--rmi", "all")
 		res.Assert(t, icmd.Success)

+ 4 - 0
pkg/progress/writer.go

@@ -19,6 +19,7 @@ package progress
 import (
 	"context"
 	"io"
+	"os"
 	"sync"
 
 	"github.com/docker/cli/cli/streams"
@@ -121,6 +122,9 @@ func NewWriter(ctx context.Context, out *streams.Out, progressTitle string) (Wri
 	if !ok {
 		dryRun = false
 	}
+	if v, ok := os.LookupEnv("COMPOSE_PROGRESS"); ok && Mode == ModeAuto {
+		Mode = v
+	}
 	if Mode == ModeQuiet {
 		return quiet{}, nil
 	}