adopt compose-go/v2

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2023-11-08 10:19:24 +01:00 committed by Nicolas De loof
parent 85a1aec123
commit cda04f288e
62 changed files with 187 additions and 144 deletions

View File

@ -22,9 +22,9 @@ import (
"os" "os"
"strings" "strings"
"github.com/compose-spec/compose-go/cli" "github.com/compose-spec/compose-go/v2/cli"
"github.com/compose-spec/compose-go/loader" "github.com/compose-spec/compose-go/v2/loader"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
cliopts "github.com/docker/cli/opts" cliopts "github.com/docker/cli/opts"
ui "github.com/docker/compose/v2/pkg/progress" ui "github.com/docker/compose/v2/pkg/progress"
@ -50,7 +50,14 @@ func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions,
var SSHKeys []types.SSHKey var SSHKeys []types.SSHKey
var err error var err error
if opts.ssh != "" { if opts.ssh != "" {
SSHKeys, err = loader.ParseShortSSHSyntax(opts.ssh) id, path, found := strings.Cut(opts.ssh, "=")
if !found && id != "default" {
return api.BuildOptions{}, fmt.Errorf("invalid ssh key %q", opts.ssh)
}
SSHKeys = append(SSHKeys, types.SSHKey{
ID: id,
Path: path,
})
if err != nil { if err != nil {
return api.BuildOptions{}, err return api.BuildOptions{}, err
} }

View File

@ -27,10 +27,10 @@ import (
"strings" "strings"
"syscall" "syscall"
"github.com/compose-spec/compose-go/cli" "github.com/compose-spec/compose-go/v2/cli"
"github.com/compose-spec/compose-go/dotenv" "github.com/compose-spec/compose-go/v2/dotenv"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
composegoutils "github.com/compose-spec/compose-go/utils" composegoutils "github.com/compose-spec/compose-go/v2/utils"
"github.com/docker/buildx/util/logutil" "github.com/docker/buildx/util/logutil"
dockercli "github.com/docker/cli/cli" dockercli "github.com/docker/cli/cli"
"github.com/docker/cli/cli-plugins/manager" "github.com/docker/cli/cli-plugins/manager"

View File

@ -19,7 +19,7 @@ package compose
import ( import (
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )

View File

@ -24,8 +24,8 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/compose-spec/compose-go/cli" "github.com/compose-spec/compose-go/v2/cli"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"

View File

@ -24,7 +24,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -164,7 +164,15 @@ func (opts createOptions) Apply(project *types.Project) error {
return err return err
} }
for _, scale := range opts.scale { err := applyScaleOpts(project, opts.scale)
if err != nil {
return err
}
return nil
}
func applyScaleOpts(project *types.Project, opts []string) error {
for _, scale := range opts {
split := strings.Split(scale, "=") split := strings.Split(scale, "=")
if len(split) != 2 { if len(split) != 2 {
return fmt.Errorf("invalid --scale option %q. Should be SERVICE=NUM", scale) return fmt.Errorf("invalid --scale option %q. Should be SERVICE=NUM", scale)
@ -174,7 +182,7 @@ func (opts createOptions) Apply(project *types.Project) error {
if err != nil { if err != nil {
return err return err
} }
err = setServiceScale(project, name, uint64(replicas)) err = setServiceScale(project, name, replicas)
if err != nil { if err != nil {
return err return err
} }

View File

@ -21,7 +21,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/mocks" "github.com/docker/compose/v2/pkg/mocks"

View File

@ -19,7 +19,7 @@ package compose
import ( import (
"context" "context"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"

View File

@ -19,7 +19,7 @@ package compose
import ( import (
"fmt" "fmt"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/pkg/utils" "github.com/docker/compose/v2/pkg/utils"
) )

View File

@ -19,7 +19,7 @@ package compose
import ( import (
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )

View File

@ -21,7 +21,7 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/morikuni/aec" "github.com/morikuni/aec"
"github.com/spf13/cobra" "github.com/spf13/cobra"

View File

@ -19,7 +19,7 @@ package compose
import ( import (
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )

View File

@ -19,7 +19,7 @@ package compose
import ( import (
"context" "context"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"

View File

@ -21,12 +21,12 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/compose-spec/compose-go/v2/format"
xprogress "github.com/moby/buildkit/util/progress/progressui" xprogress "github.com/moby/buildkit/util/progress/progressui"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
cgo "github.com/compose-spec/compose-go/cli" cgo "github.com/compose-spec/compose-go/v2/cli"
"github.com/compose-spec/compose-go/loader" "github.com/compose-spec/compose-go/v2/types"
"github.com/compose-spec/compose-go/types"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/opts" "github.com/docker/cli/opts"
"github.com/mattn/go-shellwords" "github.com/mattn/go-shellwords"
@ -98,7 +98,7 @@ func (options runOptions) apply(project *types.Project) error {
} }
for _, v := range options.volumes { for _, v := range options.volumes {
volume, err := loader.ParseVolume(v) volume, err := format.ParseVolume(v)
if err != nil { if err != nil {
return err return err
} }

View File

@ -24,7 +24,7 @@ import (
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"golang.org/x/exp/maps" "golang.org/x/exp/maps"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
@ -77,11 +77,11 @@ func runScale(ctx context.Context, dockerCli command.Cli, backend api.Service, o
if service.Name != key { if service.Name != key {
continue continue
} }
if service.Deploy == nil { value := value
service.Deploy = &types.DeployConfig{} service.Scale = &value
if service.Deploy != nil {
service.Deploy.Replicas = &value
} }
scale := uint64(value)
service.Deploy.Replicas = &scale
project.Services[i] = service project.Services[i] = service
break break
} }

View File

@ -25,7 +25,7 @@ import (
xprogress "github.com/moby/buildkit/util/progress/progressui" xprogress "github.com/moby/buildkit/util/progress/progressui"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/compose/v2/cmd/formatter" "github.com/docker/compose/v2/cmd/formatter"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -259,7 +259,7 @@ func runUp(
}) })
} }
func setServiceScale(project *types.Project, name string, replicas uint64) error { func setServiceScale(project *types.Project, name string, replicas int) error {
for i, s := range project.Services { for i, s := range project.Services {
if s.Name != name { if s.Name != name {
continue continue
@ -269,10 +269,10 @@ func setServiceScale(project *types.Project, name string, replicas uint64) error
if err != nil { if err != nil {
return err return err
} }
if service.Deploy == nil { service.Scale = &replicas
service.Deploy = &types.DeployConfig{} if service.Deploy != nil {
service.Deploy.Replicas = &replicas
} }
service.Deploy.Replicas = &replicas
project.Services[i] = service project.Services[i] = service
return nil return nil
} }

View File

@ -19,7 +19,7 @@ package compose
import ( import (
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
@ -31,13 +31,21 @@ func TestApplyScaleOpt(t *testing.T) {
}, },
{ {
Name: "bar", Name: "bar",
Deploy: &types.DeployConfig{
Mode: "test",
},
}, },
}, },
} }
opt := createOptions{scale: []string{"foo=2"}} err := applyScaleOpts(&p, []string{"foo=2", "bar=3"})
err := opt.Apply(&p)
assert.NilError(t, err) assert.NilError(t, err)
foo, err := p.GetService("foo") foo, err := p.GetService("foo")
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, *foo.Deploy.Replicas, uint64(2)) assert.Equal(t, *foo.Scale, 2)
bar, err := p.GetService("bar")
assert.NilError(t, err)
assert.Equal(t, *bar.Scale, 3)
assert.Equal(t, *bar.Deploy.Replicas, 3)
} }

View File

@ -20,7 +20,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/compose/v2/internal/locker" "github.com/docker/compose/v2/internal/locker"

2
go.mod
View File

@ -6,7 +6,7 @@ require (
github.com/AlecAivazis/survey/v2 v2.3.7 github.com/AlecAivazis/survey/v2 v2.3.7
github.com/Microsoft/go-winio v0.6.1 github.com/Microsoft/go-winio v0.6.1
github.com/buger/goterm v1.0.4 github.com/buger/goterm v1.0.4
github.com/compose-spec/compose-go v1.20.2 github.com/compose-spec/compose-go/v2 v2.0.0-20231121074112-593b77722992
github.com/containerd/console v1.0.3 github.com/containerd/console v1.0.3
github.com/containerd/containerd v1.7.7 github.com/containerd/containerd v1.7.7
github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew v1.1.1

4
go.sum
View File

@ -132,8 +132,8 @@ github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+g
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE= github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4= github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
github.com/compose-spec/compose-go v1.20.2 h1:u/yfZHn4EaHGdidrZycWpxXgFffjYULlTbRfJ51ykjQ= github.com/compose-spec/compose-go/v2 v2.0.0-20231121074112-593b77722992 h1:0BM7GPtSRK7djjvG3h67aJYH8eRikBgxkrEG7wNtgaU=
github.com/compose-spec/compose-go v1.20.2/go.mod h1:+MdqXV4RA7wdFsahh/Kb8U0pAJqkg7mr4PM9tFKU8RM= github.com/compose-spec/compose-go/v2 v2.0.0-20231121074112-593b77722992/go.mod h1:uAthZuC/GWStR8mxGMRaQyaOeSqA4V+MZIiAIfuBoIU=
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw= github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=

View File

@ -22,7 +22,7 @@ import (
"io/fs" "io/fs"
"os" "os"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -63,8 +63,8 @@ func (d *DockerCopy) Sync(ctx context.Context, service types.ServiceConfig, path
func (d *DockerCopy) sync(ctx context.Context, service types.ServiceConfig, pathMapping PathMapping) error { func (d *DockerCopy) sync(ctx context.Context, service types.ServiceConfig, pathMapping PathMapping) error {
scale := 1 scale := 1
if service.Deploy != nil && service.Deploy.Replicas != nil { if service.Scale != nil {
scale = int(*service.Deploy.Replicas) scale = *service.Scale
} }
if fi, statErr := os.Stat(pathMapping.HostPath); statErr == nil { if fi, statErr := os.Stat(pathMapping.HostPath); statErr == nil {

View File

@ -17,7 +17,7 @@ package sync
import ( import (
"context" "context"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
) )
// PathMapping contains the Compose service and modified host system path. // PathMapping contains the Compose service and modified host system path.

View File

@ -32,7 +32,7 @@ import (
"github.com/hashicorp/go-multierror" "github.com/hashicorp/go-multierror"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
) )

View File

@ -22,7 +22,7 @@ import (
"github.com/docker/compose/v2/pkg/utils" "github.com/docker/compose/v2/pkg/utils"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"

View File

@ -22,7 +22,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/pkg/utils" "github.com/docker/compose/v2/pkg/utils"
) )

View File

@ -19,7 +19,7 @@ package api
import ( import (
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )

View File

@ -19,7 +19,7 @@ package api
import ( import (
"context" "context"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
) )
var _ Service = &ServiceProxy{} var _ Service = &ServiceProxy{}

View File

@ -23,7 +23,7 @@ import (
"io" "io"
"strings" "strings"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/streams" "github.com/docker/cli/cli/streams"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
containerType "github.com/docker/docker/api/types/container" containerType "github.com/docker/docker/api/types/container"

View File

@ -26,7 +26,7 @@ import (
"github.com/moby/buildkit/util/progress/progressui" "github.com/moby/buildkit/util/progress/progressui"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
"github.com/docker/buildx/build" "github.com/docker/buildx/build"
"github.com/docker/buildx/builder" "github.com/docker/buildx/builder"

View File

@ -31,7 +31,7 @@ import (
"github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/registry"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command/image/build" "github.com/docker/cli/cli/command/image/build"
dockertypes "github.com/docker/docker/api/types" dockertypes "github.com/docker/docker/api/types"

View File

@ -29,7 +29,7 @@ import (
"github.com/docker/docker/api/types/volume" "github.com/docker/docker/api/types/volume"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/cli/config/configfile"
@ -177,23 +177,25 @@ func (s *composeService) Config(ctx context.Context, project *types.Project, opt
// projectFromName builds a types.Project based on actual resources with compose labels set // projectFromName builds a types.Project based on actual resources with compose labels set
func (s *composeService) projectFromName(containers Containers, projectName string, services ...string) (*types.Project, error) { func (s *composeService) projectFromName(containers Containers, projectName string, services ...string) (*types.Project, error) {
project := &types.Project{ project := &types.Project{
Name: projectName, Name: projectName,
Services: types.Services{},
} }
if len(containers) == 0 { if len(containers) == 0 {
return project, fmt.Errorf("no container found for project %q: %w", projectName, api.ErrNotFound) return project, fmt.Errorf("no container found for project %q: %w", projectName, api.ErrNotFound)
} }
set := map[string]*types.ServiceConfig{} set := map[string]types.ServiceConfig{}
for _, c := range containers { for _, c := range containers {
serviceLabel := c.Labels[api.ServiceLabel] serviceLabel := c.Labels[api.ServiceLabel]
_, ok := set[serviceLabel] service, ok := set[serviceLabel]
if !ok { if !ok {
set[serviceLabel] = &types.ServiceConfig{ service = types.ServiceConfig{
Name: serviceLabel, Name: serviceLabel,
Image: c.Image, Image: c.Image,
Labels: c.Labels, Labels: c.Labels,
} }
set[serviceLabel] = service
} }
set[serviceLabel].Scale++ service.Scale = increment(service.Scale)
} }
for _, service := range set { for _, service := range set {
dependencies := service.Labels[api.DependenciesLabel] dependencies := service.Labels[api.DependenciesLabel]
@ -217,7 +219,7 @@ func (s *composeService) projectFromName(containers Containers, projectName stri
service.DependsOn[dependency] = types.ServiceDependency{Condition: condition, Restart: restart, Required: required} service.DependsOn[dependency] = types.ServiceDependency{Condition: condition, Restart: restart, Required: required}
} }
} }
project.Services = append(project.Services, *service) project.Services = append(project.Services, service)
} }
SERVICES: SERVICES:
for _, qs := range services { for _, qs := range services {
@ -236,6 +238,14 @@ SERVICES:
return project, nil return project, nil
} }
func increment(scale *int) *int {
i := 1
if scale != nil {
i = *scale + 1
}
return &i
}
func (s *composeService) actualVolumes(ctx context.Context, projectName string) (types.Volumes, error) { func (s *composeService) actualVolumes(ctx context.Context, projectName string) (types.Volumes, error) {
opts := volume.ListOptions{ opts := volume.ListOptions{
Filters: filters.NewArgs(projectFilter(projectName)), Filters: filters.NewArgs(projectFilter(projectName)),

View File

@ -22,7 +22,7 @@ import (
"sort" "sort"
"strconv" "strconv"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/utils" "github.com/docker/compose/v2/pkg/utils"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"

View File

@ -29,7 +29,7 @@ import (
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
"github.com/docker/compose/v2/internal/tracing" "github.com/docker/compose/v2/internal/tracing"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
@ -428,7 +428,7 @@ func shouldWaitForDependency(serviceName string, dependencyConfig types.ServiceD
} }
} }
return false, err return false, err
} else if service.Scale == 0 { } else if service.Scale != nil && *service.Scale == 0 {
// don't wait for the dependency which configured to have 0 containers running // don't wait for the dependency which configured to have 0 containers running
return false, nil return false, nil
} }
@ -457,8 +457,11 @@ func nextContainerNumber(containers []moby.Container) int {
func getScale(config types.ServiceConfig) (int, error) { func getScale(config types.ServiceConfig) (int, error) {
scale := 1 scale := 1
if config.Deploy != nil && config.Deploy.Replicas != nil { if config.Scale != nil {
scale = int(*config.Deploy.Replicas) scale = *config.Scale
} else if config.Deploy != nil && config.Deploy.Replicas != nil {
// this should not be required as compose-go enforce consistency between scale anr replicas
scale = *config.Deploy.Replicas
} }
if scale > 1 && config.ContainerName != "" { if scale > 1 && config.ContainerName != "" {
return 0, fmt.Errorf(doubledContainerNameWarning, return 0, fmt.Errorf(doubledContainerNameWarning,

View File

@ -22,7 +22,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
containerType "github.com/docker/docker/api/types/container" containerType "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
@ -37,31 +37,33 @@ func TestContainerName(t *testing.T) {
s := types.ServiceConfig{ s := types.ServiceConfig{
Name: "testservicename", Name: "testservicename",
ContainerName: "testcontainername", ContainerName: "testcontainername",
Scale: 1, Scale: intPtr(1),
Deploy: &types.DeployConfig{}, Deploy: &types.DeployConfig{},
} }
ret, err := getScale(s) ret, err := getScale(s)
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, ret, s.Scale) assert.Equal(t, ret, *s.Scale)
var zero uint64 // = 0 s.Scale = intPtr(0)
s.Deploy.Replicas = &zero
ret, err = getScale(s) ret, err = getScale(s)
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, ret, int(*s.Deploy.Replicas)) assert.Equal(t, ret, *s.Scale)
var two uint64 = 2 s.Scale = intPtr(2)
s.Deploy.Replicas = &two
_, err = getScale(s) _, err = getScale(s)
assert.Error(t, err, fmt.Sprintf(doubledContainerNameWarning, s.Name, s.ContainerName)) assert.Error(t, err, fmt.Sprintf(doubledContainerNameWarning, s.Name, s.ContainerName))
} }
func intPtr(i int) *int {
return &i
}
func TestServiceLinks(t *testing.T) { func TestServiceLinks(t *testing.T) {
const dbContainerName = "/" + testProject + "-db-1" const dbContainerName = "/" + testProject + "-db-1"
const webContainerName = "/" + testProject + "-web-1" const webContainerName = "/" + testProject + "-web-1"
s := types.ServiceConfig{ s := types.ServiceConfig{
Name: "web", Name: "web",
Scale: 1, Scale: intPtr(1),
} }
containerListOptions := containerType.ListOptions{ containerListOptions := containerType.ListOptions{
@ -223,8 +225,8 @@ func TestWaitDependencies(t *testing.T) {
cli.EXPECT().Client().Return(apiClient).AnyTimes() cli.EXPECT().Client().Return(apiClient).AnyTimes()
t.Run("should skip dependencies with scale 0", func(t *testing.T) { t.Run("should skip dependencies with scale 0", func(t *testing.T) {
dbService := types.ServiceConfig{Name: "db", Scale: 0} dbService := types.ServiceConfig{Name: "db", Scale: intPtr(0)}
redisService := types.ServiceConfig{Name: "redis", Scale: 0} redisService := types.ServiceConfig{Name: "redis", Scale: intPtr(0)}
project := types.Project{Name: strings.ToLower(testProject), Services: types.Services{dbService, redisService}} project := types.Project{Name: strings.ToLower(testProject), Services: types.Services{dbService, redisService}}
dependencies := types.DependsOnConfig{ dependencies := types.DependsOnConfig{
"db": {Condition: ServiceConditionRunningOrHealthy}, "db": {Condition: ServiceConditionRunningOrHealthy},
@ -233,8 +235,8 @@ func TestWaitDependencies(t *testing.T) {
assert.NilError(t, tested.waitDependencies(context.Background(), &project, "", dependencies, nil)) assert.NilError(t, tested.waitDependencies(context.Background(), &project, "", dependencies, nil))
}) })
t.Run("should skip dependencies with condition service_started", func(t *testing.T) { t.Run("should skip dependencies with condition service_started", func(t *testing.T) {
dbService := types.ServiceConfig{Name: "db", Scale: 1} dbService := types.ServiceConfig{Name: "db", Scale: intPtr(1)}
redisService := types.ServiceConfig{Name: "redis", Scale: 1} redisService := types.ServiceConfig{Name: "redis", Scale: intPtr(1)}
project := types.Project{Name: strings.ToLower(testProject), Services: types.Services{dbService, redisService}} project := types.Project{Name: strings.ToLower(testProject), Services: types.Services{dbService, redisService}}
dependencies := types.DependsOnConfig{ dependencies := types.DependsOnConfig{
"db": {Condition: types.ServiceConditionStarted, Required: true}, "db": {Condition: types.ServiceConditionStarted, Required: true},

View File

@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"time" "time"
compose "github.com/compose-spec/compose-go/types" compose "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
) )

View File

@ -41,7 +41,7 @@ import (
"github.com/docker/go-units" "github.com/docker/go-units"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/progress" "github.com/docker/compose/v2/pkg/progress"
@ -810,7 +810,7 @@ func buildContainerConfigMounts(p types.Project, s types.ServiceConfig) ([]mount
} }
definedConfig := p.Configs[config.Source] definedConfig := p.Configs[config.Source]
if definedConfig.External.External { if definedConfig.External {
return nil, fmt.Errorf("unsupported external config %s", definedConfig.Name) return nil, fmt.Errorf("unsupported external config %s", definedConfig.Name)
} }
@ -860,7 +860,7 @@ func buildContainerSecretMounts(p types.Project, s types.ServiceConfig) ([]mount
} }
definedSecret := p.Secrets[secret.Source] definedSecret := p.Secrets[secret.Source]
if definedSecret.External.External { if definedSecret.External {
return nil, fmt.Errorf("unsupported external secret %s", definedSecret.Name) return nil, fmt.Errorf("unsupported external secret %s", definedSecret.Name)
} }
@ -1019,7 +1019,7 @@ func buildTmpfsOptions(tmpfs *types.ServiceVolumeTmpfs) *mount.TmpfsOptions {
} }
func (s *composeService) ensureNetwork(ctx context.Context, n *types.NetworkConfig) error { func (s *composeService) ensureNetwork(ctx context.Context, n *types.NetworkConfig) error {
if n.External.External { if n.External {
return s.resolveExternalNetwork(ctx, n) return s.resolveExternalNetwork(ctx, n)
} }
@ -1206,14 +1206,14 @@ func (s *composeService) ensureVolume(ctx context.Context, volume types.VolumeCo
if !errdefs.IsNotFound(err) { if !errdefs.IsNotFound(err) {
return err return err
} }
if volume.External.External { if volume.External {
return fmt.Errorf("external volume %q not found", volume.Name) return fmt.Errorf("external volume %q not found", volume.Name)
} }
err := s.createVolume(ctx, volume) err := s.createVolume(ctx, volume)
return err return err
} }
if volume.External.External { if volume.External {
return nil return nil
} }

View File

@ -26,7 +26,7 @@ import (
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
composetypes "github.com/compose-spec/compose-go/types" composetypes "github.com/compose-spec/compose-go/v2/types"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
mountTypes "github.com/docker/docker/api/types/mount" mountTypes "github.com/docker/docker/api/types/mount"

View File

@ -22,7 +22,7 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"

View File

@ -23,7 +23,7 @@ import (
"sync" "sync"
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/pkg/utils" "github.com/docker/compose/v2/pkg/utils"
testify "github.com/stretchr/testify/assert" testify "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"

View File

@ -24,7 +24,7 @@ import (
"github.com/docker/compose/v2/pkg/utils" "github.com/docker/compose/v2/pkg/utils"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
containerType "github.com/docker/docker/api/types/container" containerType "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
@ -136,7 +136,7 @@ func checkSelectedServices(options api.DownOptions, project *types.Project) ([]s
func (s *composeService) ensureVolumesDown(ctx context.Context, project *types.Project, w progress.Writer) []downOp { func (s *composeService) ensureVolumesDown(ctx context.Context, project *types.Project, w progress.Writer) []downOp {
var ops []downOp var ops []downOp
for _, vol := range project.Volumes { for _, vol := range project.Volumes {
if vol.External.External { if vol.External {
continue continue
} }
volumeName := vol.Name volumeName := vol.Name
@ -171,7 +171,7 @@ func (s *composeService) ensureImagesDown(ctx context.Context, project *types.Pr
func (s *composeService) ensureNetworksDown(ctx context.Context, project *types.Project, w progress.Writer) []downOp { func (s *composeService) ensureNetworksDown(ctx context.Context, project *types.Project, w progress.Writer) []downOp {
var ops []downOp var ops []downOp
for key, n := range project.Networks { for key, n := range project.Networks {
if n.External.External { if n.External {
continue continue
} }
// loop capture variable for op closure // loop capture variable for op closure

View File

@ -23,7 +23,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/streams" "github.com/docker/cli/cli/streams"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
containerType "github.com/docker/docker/api/types/container" containerType "github.com/docker/docker/api/types/container"

View File

@ -20,7 +20,7 @@ import (
"errors" "errors"
"io/fs" "io/fs"
"github.com/compose-spec/compose-go/errdefs" "github.com/compose-spec/compose-go/v2/errdefs"
) )
// Error error to categorize failures and extract metrics info // Error error to categorize failures and extract metrics info

View File

@ -19,7 +19,7 @@ package compose
import ( import (
"encoding/json" "encoding/json"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
) )
@ -28,12 +28,11 @@ func ServiceHash(o types.ServiceConfig) (string, error) {
// remove the Build config when generating the service hash // remove the Build config when generating the service hash
o.Build = nil o.Build = nil
o.PullPolicy = "" o.PullPolicy = ""
if o.Deploy == nil { o.Scale = nil
o.Deploy = &types.DeployConfig{} if o.Deploy != nil {
o.Deploy.Replicas = nil
} }
o.Scale = 1
var one uint64 = 1
o.Deploy.Replicas = &one
bytes, err := json.Marshal(o) bytes, err := json.Marshal(o)
if err != nil { if err != nil {
return "", err return "", err

View File

@ -19,7 +19,7 @@ package compose
import ( import (
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
@ -31,9 +31,9 @@ func TestServiceHash(t *testing.T) {
assert.Equal(t, hash1, hash2) assert.Equal(t, hash1, hash2)
} }
func serviceConfig(replicas uint64) types.ServiceConfig { func serviceConfig(replicas int) types.ServiceConfig {
return types.ServiceConfig{ return types.ServiceConfig{
Scale: int(replicas), Scale: &replicas,
Deploy: &types.DeployConfig{ Deploy: &types.DeployConfig{
Replicas: &replicas, Replicas: &replicas,
}, },

View File

@ -22,7 +22,7 @@ import (
"sort" "sort"
"sync" "sync"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/distribution/reference" "github.com/distribution/reference"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"

View File

@ -23,7 +23,7 @@ import (
"sync" "sync"
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
containerType "github.com/docker/docker/api/types/container" containerType "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"

View File

@ -20,7 +20,7 @@ import (
"context" "context"
"os" "os"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/docker/buildx/util/imagetools" "github.com/docker/buildx/util/imagetools"
"github.com/docker/compose/v2/internal/ocipush" "github.com/docker/compose/v2/internal/ocipush"
@ -122,12 +122,13 @@ func (s *composeService) generateImageDigestsOverride(ctx context.Context, proje
if err != nil { if err != nil {
return nil, err return nil, err
} }
override := types.Project{} override := types.Project{
for _, service := range project.Services { Services: types.Services{},
override.Services = append(override.Services, types.ServiceConfig{ }
Name: service.Name, for name, service := range project.Services {
override.Services[name] = types.ServiceConfig{
Image: service.Image, Image: service.Image,
}) }
} }
return override.MarshalYAML() return override.MarshalYAML()
} }

View File

@ -25,7 +25,7 @@ import (
"io" "io"
"strings" "strings"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/docker/buildx/driver" "github.com/docker/buildx/driver"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"

View File

@ -25,7 +25,7 @@ import (
"io" "io"
"strings" "strings"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/docker/buildx/driver" "github.com/docker/buildx/driver"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"

View File

@ -20,7 +20,7 @@ import (
"context" "context"
"strings" "strings"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/progress" "github.com/docker/compose/v2/pkg/progress"
"github.com/docker/compose/v2/pkg/utils" "github.com/docker/compose/v2/pkg/utils"

View File

@ -23,7 +23,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
cmd "github.com/docker/cli/cli/command/container" cmd "github.com/docker/cli/cli/command/container"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
@ -73,7 +73,8 @@ func (s *composeService) prepareRun(ctx context.Context, project *types.Project,
if service.ContainerName == "" { if service.ContainerName == "" {
service.ContainerName = fmt.Sprintf("%[1]s%[4]s%[2]s%[4]srun%[4]s%[3]s", project.Name, service.Name, stringid.TruncateID(slug), api.Separator) service.ContainerName = fmt.Sprintf("%[1]s%[4]s%[2]s%[4]srun%[4]s%[3]s", project.Name, service.Name, stringid.TruncateID(slug), api.Separator)
} }
service.Scale = 1 one := 1
service.Scale = &one
service.Restart = "" service.Restart = ""
if service.Deploy != nil { if service.Deploy != nil {
service.Deploy.RestartPolicy = nil service.Deploy.RestartPolicy = nil

View File

@ -18,7 +18,7 @@ package compose
import ( import (
"context" "context"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/internal/tracing" "github.com/docker/compose/v2/internal/tracing"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/progress" "github.com/docker/compose/v2/pkg/progress"

View File

@ -24,7 +24,7 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
) )

View File

@ -30,7 +30,7 @@ import (
"github.com/docker/compose/v2/pkg/progress" "github.com/docker/compose/v2/pkg/progress"
"github.com/docker/compose/v2/pkg/utils" "github.com/docker/compose/v2/pkg/utils"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"

View File

@ -23,7 +23,7 @@ import (
"os/signal" "os/signal"
"syscall" "syscall"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/compose/v2/internal/tracing" "github.com/docker/compose/v2/internal/tracing"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"

View File

@ -21,7 +21,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
) )
@ -30,13 +30,13 @@ type vizGraph map[*types.ServiceConfig][]*types.ServiceConfig
func (s *composeService) Viz(_ context.Context, project *types.Project, opts api.VizOptions) (string, error) { func (s *composeService) Viz(_ context.Context, project *types.Project, opts api.VizOptions) (string, error) {
graph := make(vizGraph) graph := make(vizGraph)
for i, serviceConfig := range project.Services { for _, service := range project.Services {
serviceConfigPtr := &project.Services[i] service := service
graph[serviceConfigPtr] = make([]*types.ServiceConfig, 0, len(serviceConfig.DependsOn)) graph[&service] = make([]*types.ServiceConfig, 0, len(service.DependsOn))
for dependencyName := range serviceConfig.DependsOn { for dependencyName := range service.DependsOn {
// no error should be returned since dependencyName should exist // no error should be returned since dependencyName should exist
dependency, _ := project.GetService(dependencyName) dependency, _ := project.GetService(dependencyName)
graph[serviceConfigPtr] = append(graph[serviceConfigPtr], &dependency) graph[&service] = append(graph[&service], &dependency)
} }
} }

View File

@ -21,7 +21,7 @@ import (
"strconv" "strconv"
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"

View File

@ -27,7 +27,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/internal/sync" "github.com/docker/compose/v2/internal/sync"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/watch" "github.com/docker/compose/v2/pkg/watch"

View File

@ -20,7 +20,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/internal/sync" "github.com/docker/compose/v2/internal/sync"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/mocks" "github.com/docker/compose/v2/pkg/mocks"

View File

@ -40,18 +40,21 @@ func TestScaleBasicCases(t *testing.T) {
t.Log("scale up one service") t.Log("scale up one service")
res = c.RunDockerComposeCmd(t, "--project-directory", "fixtures/scale", "scale", "dbadmin=2") res = c.RunDockerComposeCmd(t, "--project-directory", "fixtures/scale", "scale", "dbadmin=2")
checkServiceContainer(t, res.Combined(), "scale-basic-tests-dbadmin", "Started", 2) out := res.Combined()
checkServiceContainer(t, out, "scale-basic-tests-dbadmin", "Started", 2)
t.Log("scale up 2 services") t.Log("scale up 2 services")
res = c.RunDockerComposeCmd(t, "--project-directory", "fixtures/scale", "scale", "front=3", "back=2") res = c.RunDockerComposeCmd(t, "--project-directory", "fixtures/scale", "scale", "front=3", "back=2")
checkServiceContainer(t, res.Combined(), "scale-basic-tests-front", "Running", 2) out = res.Combined()
checkServiceContainer(t, res.Combined(), "scale-basic-tests-front", "Started", 1) checkServiceContainer(t, out, "scale-basic-tests-front", "Running", 2)
checkServiceContainer(t, res.Combined(), "scale-basic-tests-back", "Running", 1) checkServiceContainer(t, out, "scale-basic-tests-front", "Started", 1)
checkServiceContainer(t, res.Combined(), "scale-basic-tests-back", "Started", 1) checkServiceContainer(t, out, "scale-basic-tests-back", "Running", 1)
checkServiceContainer(t, out, "scale-basic-tests-back", "Started", 1)
t.Log("scale down one service") t.Log("scale down one service")
res = c.RunDockerComposeCmd(t, "--project-directory", "fixtures/scale", "scale", "dbadmin=1") res = c.RunDockerComposeCmd(t, "--project-directory", "fixtures/scale", "scale", "dbadmin=1")
checkServiceContainer(t, res.Combined(), "scale-basic-tests-dbadmin", "Running", 1) out = res.Combined()
checkServiceContainer(t, out, "scale-basic-tests-dbadmin", "Running", 1)
t.Log("scale to 0 a service") t.Log("scale to 0 a service")
res = c.RunDockerComposeCmd(t, "--project-directory", "fixtures/scale", "scale", "dbadmin=0") res = c.RunDockerComposeCmd(t, "--project-directory", "fixtures/scale", "scale", "dbadmin=0")
@ -59,9 +62,10 @@ func TestScaleBasicCases(t *testing.T) {
t.Log("scale down 2 services") t.Log("scale down 2 services")
res = c.RunDockerComposeCmd(t, "--project-directory", "fixtures/scale", "scale", "front=2", "back=1") res = c.RunDockerComposeCmd(t, "--project-directory", "fixtures/scale", "scale", "front=2", "back=1")
checkServiceContainer(t, res.Combined(), "scale-basic-tests-front", "Running", 2) out = res.Combined()
assert.Check(t, !strings.Contains(res.Combined(), "Container scale-basic-tests-front-3 Running"), res.Combined()) checkServiceContainer(t, out, "scale-basic-tests-front", "Running", 2)
checkServiceContainer(t, res.Combined(), "scale-basic-tests-back", "Running", 1) assert.Check(t, !strings.Contains(out, "Container scale-basic-tests-front-3 Running"), res.Combined())
checkServiceContainer(t, out, "scale-basic-tests-back", "Running", 1)
} }
func TestScaleWithDepsCases(t *testing.T) { func TestScaleWithDepsCases(t *testing.T) {

View File

@ -8,7 +8,7 @@ import (
context "context" context "context"
reflect "reflect" reflect "reflect"
types "github.com/compose-spec/compose-go/types" types "github.com/compose-spec/compose-go/v2/types"
api "github.com/docker/compose/v2/pkg/api" api "github.com/docker/compose/v2/pkg/api"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
) )

View File

@ -25,9 +25,9 @@ import (
"regexp" "regexp"
"strconv" "strconv"
"github.com/compose-spec/compose-go/cli" "github.com/compose-spec/compose-go/v2/cli"
"github.com/compose-spec/compose-go/loader" "github.com/compose-spec/compose-go/v2/loader"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
"github.com/moby/buildkit/util/gitutil" "github.com/moby/buildkit/util/gitutil"
) )

View File

@ -25,7 +25,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/compose-spec/compose-go/loader" "github.com/compose-spec/compose-go/v2/loader"
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/docker/buildx/store/storeutil" "github.com/docker/buildx/store/storeutil"
"github.com/docker/buildx/util/imagetools" "github.com/docker/buildx/util/imagetools"