Skip to content

Commit f9639d0

Browse files
authored
Remove ansi codes from compose up/down output (#1182)
1 parent 1e96d54 commit f9639d0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

.buildkite/pipeline.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
env:
22
SETUP_GVM_VERSION: 'v0.5.0' # https://github.com/andrewkroh/gvm/issues/44#issuecomment-1013231151
33
DOCKER_COMPOSE_VERSION: "1.25.5" # "v2.15.1"
4+
ELASTIC_PACKAGE_COMPOSE_DISABLE_ANSI: "true"
45
KIND_VERSION: 'v0.17.0'
56
K8S_VERSION: 'v1.26.0'
67

internal/compose/compose.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"gopkg.in/yaml.v3"
2020

2121
"github.com/elastic/elastic-package/internal/docker"
22+
"github.com/elastic/elastic-package/internal/environment"
2223
"github.com/elastic/elastic-package/internal/logger"
2324
"github.com/elastic/elastic-package/internal/signal"
2425
)
@@ -30,12 +31,15 @@ const (
3031
waitForHealthyInterval = 1 * time.Second
3132
)
3233

34+
var DisableANSIComposeEnv = environment.WithElasticPackagePrefix("COMPOSE_DISABLE_ANSI")
35+
3336
// Project represents a Docker Compose project.
3437
type Project struct {
3538
name string
3639
composeFilePaths []string
3740

3841
dockerComposeV1 bool
42+
disableANSI bool
3943
}
4044

4145
// Config represents a Docker Compose configuration file.
@@ -179,13 +183,22 @@ func NewProject(name string, paths ...string) (*Project, error) {
179183
logger.Debugf("Determined Docker Compose version: %v, the tool will use Compose V1", ver)
180184
c.dockerComposeV1 = true
181185
}
186+
187+
v, ok := os.LookupEnv(DisableANSIComposeEnv)
188+
if !c.dockerComposeV1 && ok && strings.ToLower(v) != "false" {
189+
c.disableANSI = true
190+
}
191+
182192
return &c, nil
183193
}
184194

185195
// Up brings up a Docker Compose project.
186196
func (p *Project) Up(opts CommandOptions) error {
187197
args := p.baseArgs()
188198
args = append(args, "up")
199+
if p.disableANSI {
200+
args = append(args, "--quiet-pull")
201+
}
189202
args = append(args, opts.ExtraArgs...)
190203
args = append(args, opts.Services...)
191204

@@ -364,6 +377,10 @@ func (p *Project) baseArgs() []string {
364377
args = append(args, "-f", path)
365378
}
366379

380+
if p.disableANSI {
381+
args = append(args, "--ansi", "never")
382+
}
383+
367384
args = append(args, "-p", p.name)
368385
return args
369386
}

0 commit comments

Comments
 (0)