Skip to content

Commit

Permalink
Remove ansi codes from compose up/down output (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano authored Mar 16, 2023
1 parent 1e96d54 commit f9639d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
env:
SETUP_GVM_VERSION: 'v0.5.0' # https://github.com/andrewkroh/gvm/issues/44#issuecomment-1013231151
DOCKER_COMPOSE_VERSION: "1.25.5" # "v2.15.1"
ELASTIC_PACKAGE_COMPOSE_DISABLE_ANSI: "true"
KIND_VERSION: 'v0.17.0'
K8S_VERSION: 'v1.26.0'

Expand Down
17 changes: 17 additions & 0 deletions internal/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"gopkg.in/yaml.v3"

"github.com/elastic/elastic-package/internal/docker"
"github.com/elastic/elastic-package/internal/environment"
"github.com/elastic/elastic-package/internal/logger"
"github.com/elastic/elastic-package/internal/signal"
)
Expand All @@ -30,12 +31,15 @@ const (
waitForHealthyInterval = 1 * time.Second
)

var DisableANSIComposeEnv = environment.WithElasticPackagePrefix("COMPOSE_DISABLE_ANSI")

// Project represents a Docker Compose project.
type Project struct {
name string
composeFilePaths []string

dockerComposeV1 bool
disableANSI bool
}

// Config represents a Docker Compose configuration file.
Expand Down Expand Up @@ -179,13 +183,22 @@ func NewProject(name string, paths ...string) (*Project, error) {
logger.Debugf("Determined Docker Compose version: %v, the tool will use Compose V1", ver)
c.dockerComposeV1 = true
}

v, ok := os.LookupEnv(DisableANSIComposeEnv)
if !c.dockerComposeV1 && ok && strings.ToLower(v) != "false" {
c.disableANSI = true
}

return &c, nil
}

// Up brings up a Docker Compose project.
func (p *Project) Up(opts CommandOptions) error {
args := p.baseArgs()
args = append(args, "up")
if p.disableANSI {
args = append(args, "--quiet-pull")
}
args = append(args, opts.ExtraArgs...)
args = append(args, opts.Services...)

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

if p.disableANSI {
args = append(args, "--ansi", "never")
}

args = append(args, "-p", p.name)
return args
}
Expand Down

0 comments on commit f9639d0

Please sign in to comment.