Skip to content

Commit

Permalink
fix(compose): introduce custom types to fix ambiguity in CreateOption…
Browse files Browse the repository at this point in the history
…s and StartOptions
  • Loading branch information
prskr committed Oct 18, 2022
1 parent 53c75cd commit 8757773
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
15 changes: 13 additions & 2 deletions compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"runtime"
"strings"

"github.com/compose-spec/compose-go/types"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/flags"
"github.com/docker/compose/v2/pkg/api"
Expand All @@ -33,8 +34,18 @@ type ComposeStackOption interface {
}

type stackUpOptions struct {
api.CreateOptions
api.StartOptions
// Services defines the services user interacts with
Services []string
// Remove legacy containers for services that are not defined in the project
RemoveOrphans bool
// Wait won't return until containers reached the running|healthy state
Wait bool
// Recreate define the strategy to apply on existing containers
Recreate string
// RecreateDependencies define the strategy to apply on dependencies services
RecreateDependencies string
// Project is the compose project used to define this app. Might be nil if user ran command just with project name
Project *types.Project
}

type StackUpOption interface {
Expand Down
24 changes: 14 additions & 10 deletions compose_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,10 @@ func (d *dockerCompose) Up(ctx context.Context, opts ...StackUpOption) (err erro
}

upOptions := stackUpOptions{
CreateOptions: api.CreateOptions{
Services: d.project.ServiceNames(),
Recreate: api.RecreateDiverged,
RecreateDependencies: api.RecreateDiverged,
},
StartOptions: api.StartOptions{
Project: d.project,
},
Services: d.project.ServiceNames(),
Recreate: api.RecreateDiverged,
RecreateDependencies: api.RecreateDiverged,
Project: d.project,
}

for i := range opts {
Expand All @@ -203,8 +199,16 @@ func (d *dockerCompose) Up(ctx context.Context, opts ...StackUpOption) (err erro
}

err = d.composeService.Up(ctx, d.project, api.UpOptions{
Create: upOptions.CreateOptions,
Start: upOptions.StartOptions,
Create: api.CreateOptions{
Services: upOptions.Services,
Recreate: upOptions.Recreate,
RecreateDependencies: upOptions.RecreateDependencies,
RemoveOrphans: upOptions.RemoveOrphans,
},
Start: api.StartOptions{
Project: upOptions.Project,
Wait: upOptions.Wait,
},
})

if err != nil {
Expand Down

0 comments on commit 8757773

Please sign in to comment.