Skip to content

Commit 84b716f

Browse files
committed
Add COMPOSE_RUN_QUIET env variable for the run command
Signed-off-by: Anvar Umuraliev <an.umuraliev@gmail.com>
1 parent 60385e6 commit 84b716f

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

cmd/compose/run.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"os"
23+
"strconv"
2324
"strings"
2425

2526
"github.com/compose-spec/compose-go/v2/dotenv"
@@ -181,7 +182,13 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
181182
options.noTty = !options.tty
182183
}
183184
}
184-
if options.quiet {
185+
var quiet bool
186+
if quietEnv, ok := os.LookupEnv("COMPOSE_RUN_QUIET"); ok {
187+
quiet, _ = strconv.ParseBool(quietEnv)
188+
} else {
189+
quiet = options.quiet
190+
}
191+
if quiet {
185192
progress.Mode = progress.ModeQuiet
186193
devnull, err := os.Open(os.DevNull)
187194
if err != nil {

pkg/e2e/compose_run_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ func TestLocalComposeRun(t *testing.T) {
170170
assert.Assert(t, strings.Contains(res.Combined(), "Pulled"), res.Combined())
171171
})
172172

173+
t.Run("COMPOSE_RUN_QUIET", func(t *testing.T) {
174+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/quiet-pull.yaml", "down", "--remove-orphans", "--rmi", "all")
175+
res.Assert(t, icmd.Success)
176+
177+
cmd := c.NewDockerComposeCmd(t, "-f", "./fixtures/run-test/quiet-pull.yaml", "run", "backend")
178+
res = icmd.RunCmd(cmd, func(c *icmd.Cmd) {
179+
c.Env = append(c.Env, "COMPOSE_RUN_QUIET=True")
180+
})
181+
assert.Assert(t, !strings.Contains(res.Combined(), "Pull complete"), res.Combined())
182+
assert.Assert(t, !strings.Contains(res.Combined(), "Pulled"), res.Combined())
183+
})
184+
173185
t.Run("--pull", func(t *testing.T) {
174186
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/pull.yaml", "down", "--remove-orphans", "--rmi", "all")
175187
res.Assert(t, icmd.Success)

0 commit comments

Comments
 (0)