Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions cmd/compose/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"io"
"slices"
"sort"
"strings"

Expand All @@ -30,7 +31,6 @@ import (

"github.com/docker/compose/v2/cmd/formatter"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/utils"
)

type imageOptions struct {
Expand Down Expand Up @@ -76,7 +76,7 @@ func runImages(ctx context.Context, dockerCli command.Cli, backend api.Service,
if i := strings.IndexRune(img.ID, ':'); i >= 0 {
id = id[i+1:]
}
if !utils.StringContains(ids, id) {
if !slices.Contains(ids, id) {
ids = append(ids, id)
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/compose/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io"
"os"
"slices"
"sort"
"strings"
"text/tabwriter"
Expand All @@ -32,7 +33,6 @@ import (
"github.com/docker/compose/v2/internal/tracing"
ui "github.com/docker/compose/v2/pkg/progress"
"github.com/docker/compose/v2/pkg/prompt"
"github.com/docker/compose/v2/pkg/utils"
)

func applyPlatforms(project *types.Project, buildForSinglePlatform bool) error {
Expand All @@ -44,15 +44,15 @@ func applyPlatforms(project *types.Project, buildForSinglePlatform bool) error {

// default platform only applies if the service doesn't specify
if defaultPlatform != "" && service.Platform == "" {
if len(service.Build.Platforms) > 0 && !utils.StringContains(service.Build.Platforms, defaultPlatform) {
if len(service.Build.Platforms) > 0 && !slices.Contains(service.Build.Platforms, defaultPlatform) {
return fmt.Errorf("service %q build.platforms does not support value set by DOCKER_DEFAULT_PLATFORM: %s", name, defaultPlatform)
}
service.Platform = defaultPlatform
}

if service.Platform != "" {
if len(service.Build.Platforms) > 0 {
if !utils.StringContains(service.Build.Platforms, service.Platform) {
if !slices.Contains(service.Build.Platforms, service.Platform) {
return fmt.Errorf("service %q build configuration does not support platform: %s", name, service.Platform)
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/compose/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"context"
"errors"
"fmt"
"slices"
"sort"
"strings"

"github.com/docker/compose/v2/cmd/formatter"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/utils"

"github.com/docker/cli/cli/command"
cliformatter "github.com/docker/cli/cli/command/formatter"
Expand Down Expand Up @@ -101,7 +101,7 @@ func runPs(ctx context.Context, dockerCli command.Cli, backend api.Service, serv
names := project.ServiceNames()
if len(services) > 0 {
for _, service := range services {
if !utils.StringContains(names, service) {
if !slices.Contains(names, service) {
return fmt.Errorf("no such service: %s", service)
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ func runPs(ctx context.Context, dockerCli command.Cli, backend api.Service, serv
services := []string{}
for _, c := range containers {
s := c.Service
if !utils.StringContains(services, s) {
if !slices.Contains(services, s) {
services = append(services, s)
}
}
Expand Down
10 changes: 2 additions & 8 deletions internal/ocipush/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"net/http"
"path/filepath"
"slices"
"time"

pusherrors "github.com/containerd/containerd/v2/core/remotes/errors"
Expand Down Expand Up @@ -157,14 +158,7 @@ func isNonAuthClientError(statusCode int) bool {
// not a client error
return false
}
for _, v := range clientAuthStatusCodes {
if statusCode == v {
// client auth error
return false
}
}
// any other 4xx client error
return true
return !slices.Contains(clientAuthStatusCodes, statusCode)
}

func generateManifest(layers []v1.Descriptor, ociCompat api.OCIVersion) ([]Pushable, error) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package api
import (
"context"
"fmt"
"slices"
"strings"
"time"

"github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/opts"
"github.com/docker/compose/v2/pkg/utils"
)

// Service manages a compose project
Expand Down Expand Up @@ -175,13 +175,13 @@ func (o BuildOptions) Apply(project *types.Project) error {
continue
}
if platform != "" {
if len(service.Build.Platforms) > 0 && !utils.StringContains(service.Build.Platforms, platform) {
if len(service.Build.Platforms) > 0 && !slices.Contains(service.Build.Platforms, platform) {
return fmt.Errorf("service %q build.platforms does not support value set by DOCKER_DEFAULT_PLATFORM: %s", name, platform)
}
service.Platform = platform
}
if service.Platform != "" {
if len(service.Build.Platforms) > 0 && !utils.StringContains(service.Build.Platforms, service.Platform) {
if len(service.Build.Platforms) > 0 && !slices.Contains(service.Build.Platforms, service.Platform) {
return fmt.Errorf("service %q build configuration does not support platform: %s", name, service.Platform)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/compose/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package compose
import (
"context"
"fmt"
"slices"
"sort"
"strconv"

"github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/utils"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
)
Expand Down Expand Up @@ -124,7 +124,7 @@ func matches(c container.Summary, predicates ...containerPredicate) bool {
func isService(services ...string) containerPredicate {
return func(c container.Summary) bool {
service := c.Labels[api.ServiceLabel]
return utils.StringContains(services, service)
return slices.Contains(services, service)
}
}

Expand All @@ -145,7 +145,7 @@ func isOrphaned(project *types.Project) containerPredicate {
}
// Service that is not defined in the compose model
service := c.Labels[api.ServiceLabel]
return !utils.StringContains(services, service)
return !slices.Contains(services, service)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/compose/convergence.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (c *convergence) apply(ctx context.Context, project *types.Project, options

return tracing.SpanWrapFunc("service/apply", tracing.ServiceOptions(service), func(ctx context.Context) error {
strategy := options.RecreateDependencies
if utils.StringContains(options.Services, name) {
if slices.Contains(options.Services, name) {
strategy = options.Recreate
}
return c.ensureService(ctx, project, service, strategy, options.Inherit, options.Timeout)
Expand Down
7 changes: 4 additions & 3 deletions pkg/compose/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package compose
import (
"context"
"fmt"
"slices"
"strings"
"sync"

Expand Down Expand Up @@ -434,7 +435,7 @@ func (g *Graph) HasCycles() (bool, error) {
path := []string{
vertex.Key,
}
if !utils.StringContains(discovered, vertex.Key) && !utils.StringContains(finished, vertex.Key) {
if !slices.Contains(discovered, vertex.Key) && !slices.Contains(finished, vertex.Key) {
var err error
discovered, finished, err = g.visit(vertex.Key, path, discovered, finished)
if err != nil {
Expand All @@ -451,11 +452,11 @@ func (g *Graph) visit(key string, path []string, discovered []string, finished [

for _, v := range g.Vertices[key].Children {
path := append(path, v.Key)
if utils.StringContains(discovered, v.Key) {
if slices.Contains(discovered, v.Key) {
return nil, nil, fmt.Errorf("cycle found: %s", strings.Join(path, " -> "))
}

if !utils.StringContains(finished, v.Key) {
if !slices.Contains(finished, v.Key) {
if _, _, err := g.visit(v.Key, path, discovered, finished); err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/compose/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package compose

import (
"context"
"slices"
"strings"
"time"

"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters"

"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/utils"
)

func (s *composeService) Events(ctx context.Context, projectName string, options api.EventsOptions) error {
Expand All @@ -47,7 +47,7 @@ func (s *composeService) Events(ctx context.Context, projectName string, options
continue
}
service := event.Actor.Attributes[api.ServiceLabel]
if len(options.Services) > 0 && !utils.StringContains(options.Services, service) {
if len(options.Services) > 0 && !slices.Contains(options.Services, service) {
continue
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/compose/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package compose
import (
"context"
"fmt"
"slices"
"strings"
"sync"

Expand All @@ -29,7 +30,6 @@ import (
"golang.org/x/sync/errgroup"

"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/utils"
)

func (s *composeService) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) {
Expand All @@ -45,7 +45,7 @@ func (s *composeService) Images(ctx context.Context, projectName string, options
if len(options.Services) > 0 {
// filter service containers
for _, c := range allContainers {
if utils.StringContains(options.Services, c.Labels[api.ServiceLabel]) {
if slices.Contains(options.Services, c.Labels[api.ServiceLabel]) {
containers = append(containers, c)
}
}
Expand All @@ -55,7 +55,7 @@ func (s *composeService) Images(ctx context.Context, projectName string, options

images := []string{}
for _, c := range containers {
if !utils.StringContains(images, c.Image) {
if !slices.Contains(images, c.Image) {
images = append(images, c.Image)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/compose/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package compose
import (
"context"
"fmt"
"slices"
"sort"
"strings"

"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/utils"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -74,7 +74,7 @@ func combinedConfigFiles(containers []container.Summary) (string, error) {
}

for _, f := range strings.Split(files, ",") {
if !utils.StringContains(configFiles, f) {
if !slices.Contains(configFiles, f) {
configFiles = append(configFiles, f)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/compose/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package compose

import (
"context"
"slices"
"strings"

"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/progress"
"github.com/docker/compose/v2/pkg/utils"
)

func (s *composeService) Stop(ctx context.Context, projectName string, options api.StopOptions) error {
Expand Down Expand Up @@ -51,7 +51,7 @@ func (s *composeService) stop(ctx context.Context, projectName string, options a

w := progress.ContextWriter(ctx)
return InReverseDependencyOrder(ctx, project, func(c context.Context, service string) error {
if !utils.StringContains(options.Services, service) {
if !slices.Contains(options.Services, service) {
return nil
}
serv := project.Services[service]
Expand Down
4 changes: 2 additions & 2 deletions pkg/progress/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"context"
"fmt"
"io"
"slices"
"strings"
"sync"
"time"

"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/utils"

"github.com/buger/goterm"
"github.com/docker/go-units"
Expand Down Expand Up @@ -77,7 +77,7 @@ func (w *ttyWriter) Event(e Event) {
}

func (w *ttyWriter) event(e Event) {
if !utils.StringContains(w.eventIDs, e.ID) {
if !slices.Contains(w.eventIDs, e.ID) {
w.eventIDs = append(w.eventIDs, e.ID)
}
if _, ok := w.events[e.ID]; ok {
Expand Down
10 changes: 0 additions & 10 deletions pkg/utils/stringutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ import (
"strings"
)

// StringContains check if an array contains a specific value
func StringContains(array []string, needle string) bool {
for _, val := range array {
if val == needle {
return true
}
}
return false
}

// StringToBool converts a string to a boolean ignoring errors
func StringToBool(s string) bool {
s = strings.ToLower(strings.TrimSpace(s))
Expand Down