Skip to content
Merged
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
38 changes: 24 additions & 14 deletions internal/stack/serverless.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ const (
defaultProjectType = "observability"
)

var (
allowedProjectTypes = []string{
"security",
"observability",
}
)
var allowedProjectTypes = []string{
"security",
"observability",
}

type serverlessProvider struct {
profile *profile.Profile
Expand Down Expand Up @@ -329,23 +327,31 @@ func (sp *serverlessProvider) startLocalServices(options Options, config Config)
return fmt.Errorf("could not initialize local services compose project")
}

err = project.Build(compose.CommandOptions{})
opts := compose.CommandOptions{
ExtraArgs: []string{},
}

err = project.Build(opts)
if err != nil {
return fmt.Errorf("failed to build images for local services: %w", err)
}

err = project.Up(compose.CommandOptions{ExtraArgs: []string{"-d"}})
if err != nil {
if options.DaemonMode {
opts.ExtraArgs = append(opts.ExtraArgs, "-d")
}

if err := project.Up(opts); err != nil {
// At least starting on 8.6.0, fleet-server may be reconfigured or
// restarted after being healthy. If elastic-agent tries to enroll at
// this moment, it fails inmediately, stopping and making `docker-compose up`
// to fail too.
// As a workaround, try to give another chance to docker-compose if only
// elastic-agent failed.
fmt.Println("Elastic Agent failed to start, trying again.")
err = project.Up(compose.CommandOptions{ExtraArgs: []string{"-d"}})
if err != nil {
return fmt.Errorf("failed to start local agent: %w", err)
if onlyElasticAgentFailed(options) {
fmt.Println("Elastic Agent failed to start, trying again.")
if err := project.Up(opts); err != nil {
return fmt.Errorf("failed to start local services: %w", err)
}
}
}

Expand Down Expand Up @@ -390,7 +396,11 @@ func (sp *serverlessProvider) destroyLocalServices() error {
return fmt.Errorf("could not initialize local services compose project")
}

err = project.Down(compose.CommandOptions{})
opts := compose.CommandOptions{
// Remove associated volumes.
ExtraArgs: []string{"--volumes", "--remove-orphans"},
}
err = project.Down(opts)
if err != nil {
return fmt.Errorf("failed to destroy local services: %w", err)
}
Expand Down