2020-12-08 11:53:36 +01:00
|
|
|
/*
|
|
|
|
Copyright 2020 Docker Compose CLI authors
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package compose
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-03-12 09:47:41 -04:00
|
|
|
"errors"
|
2020-12-08 11:53:36 +01:00
|
|
|
"fmt"
|
2023-05-11 18:45:00 +02:00
|
|
|
"os"
|
2023-03-01 17:34:33 +01:00
|
|
|
"strconv"
|
2023-01-13 14:26:28 +01:00
|
|
|
"strings"
|
2023-05-14 14:32:23 +02:00
|
|
|
"sync"
|
2023-01-13 14:26:28 +01:00
|
|
|
|
2023-11-08 10:19:24 +01:00
|
|
|
"github.com/compose-spec/compose-go/v2/types"
|
2022-02-23 11:28:56 +01:00
|
|
|
"github.com/docker/cli/cli/command"
|
2021-03-22 14:12:57 +01:00
|
|
|
"github.com/docker/cli/cli/config/configfile"
|
2023-01-12 23:31:14 +01:00
|
|
|
"github.com/docker/cli/cli/flags"
|
2022-02-23 11:28:56 +01:00
|
|
|
"github.com/docker/cli/cli/streams"
|
2025-02-12 09:34:07 +01:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2022-03-14 15:14:03 +01:00
|
|
|
"github.com/docker/docker/api/types/filters"
|
2025-02-12 09:34:07 +01:00
|
|
|
"github.com/docker/docker/api/types/network"
|
2023-05-14 14:32:23 +02:00
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2025-02-12 09:34:07 +01:00
|
|
|
"github.com/docker/docker/api/types/volume"
|
2020-12-08 11:53:36 +01:00
|
|
|
"github.com/docker/docker/client"
|
2025-02-12 09:34:07 +01:00
|
|
|
"github.com/jonboulle/clockwork"
|
|
|
|
|
|
|
|
"github.com/docker/compose/v2/internal/desktop"
|
|
|
|
"github.com/docker/compose/v2/internal/experimental"
|
|
|
|
"github.com/docker/compose/v2/pkg/api"
|
2020-12-08 11:53:36 +01:00
|
|
|
)
|
|
|
|
|
2023-05-11 18:45:00 +02:00
|
|
|
var stdioToStdout bool
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
out, ok := os.LookupEnv("COMPOSE_STATUS_STDOUT")
|
|
|
|
if ok {
|
|
|
|
stdioToStdout, _ = strconv.ParseBool(out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 11:53:36 +01:00
|
|
|
// NewComposeService create a local implementation of the compose.Service API
|
2022-02-23 11:28:56 +01:00
|
|
|
func NewComposeService(dockerCli command.Cli) api.Service {
|
2021-02-15 09:13:41 +01:00
|
|
|
return &composeService{
|
2022-11-30 12:08:26 +01:00
|
|
|
dockerCli: dockerCli,
|
watch: batch & de-duplicate file events (#10865)
Adjust the debouncing logic so that it applies to all inbound file
events, regardless of whether they match a sync or rebuild rule.
When the batch is flushed out, if any event for the service is a
rebuild event, then the service is rebuilt and all sync events for
the batch are ignored. If _all_ events in the batch are sync events,
then a sync is triggered, passing the entire batch at once. This
provides a substantial performance win for the new `tar`-based
implementation, as it can efficiently transfer the changes in bulk.
Additionally, this helps with jitter, e.g. it's not uncommon for
there to be double-writes in quick succession to a file, so even if
there's not many files being modified at once, it can still prevent
some unnecessary transfers.
Signed-off-by: Milas Bowman <milas.bowman@docker.com>
2023-08-03 14:53:02 -04:00
|
|
|
clock: clockwork.NewRealClock(),
|
2022-11-30 12:08:26 +01:00
|
|
|
maxConcurrency: -1,
|
2023-01-11 16:38:57 +01:00
|
|
|
dryRun: false,
|
2021-02-15 09:13:41 +01:00
|
|
|
}
|
2020-12-08 11:53:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type composeService struct {
|
2024-03-20 07:44:27 -06:00
|
|
|
dockerCli command.Cli
|
|
|
|
desktopCli *desktop.Client
|
|
|
|
experiments *experimental.State
|
2024-03-12 09:47:41 -04:00
|
|
|
|
watch: batch & de-duplicate file events (#10865)
Adjust the debouncing logic so that it applies to all inbound file
events, regardless of whether they match a sync or rebuild rule.
When the batch is flushed out, if any event for the service is a
rebuild event, then the service is rebuilt and all sync events for
the batch are ignored. If _all_ events in the batch are sync events,
then a sync is triggered, passing the entire batch at once. This
provides a substantial performance win for the new `tar`-based
implementation, as it can efficiently transfer the changes in bulk.
Additionally, this helps with jitter, e.g. it's not uncommon for
there to be double-writes in quick succession to a file, so even if
there's not many files being modified at once, it can still prevent
some unnecessary transfers.
Signed-off-by: Milas Bowman <milas.bowman@docker.com>
2023-08-03 14:53:02 -04:00
|
|
|
clock clockwork.Clock
|
2022-11-30 12:08:26 +01:00
|
|
|
maxConcurrency int
|
2023-01-11 16:38:57 +01:00
|
|
|
dryRun bool
|
2022-02-23 11:28:56 +01:00
|
|
|
}
|
|
|
|
|
2024-03-12 09:47:41 -04:00
|
|
|
// Close releases any connections/resources held by the underlying clients.
|
|
|
|
//
|
|
|
|
// In practice, this service has the same lifetime as the process, so everything
|
|
|
|
// will get cleaned up at about the same time regardless even if not invoked.
|
|
|
|
func (s *composeService) Close() error {
|
|
|
|
var errs []error
|
|
|
|
if s.dockerCli != nil {
|
|
|
|
errs = append(errs, s.dockerCli.Client().Close())
|
|
|
|
}
|
2024-03-08 14:07:51 +00:00
|
|
|
if s.isDesktopIntegrationActive() {
|
2024-03-12 09:47:41 -04:00
|
|
|
errs = append(errs, s.desktopCli.Close())
|
|
|
|
}
|
|
|
|
return errors.Join(errs...)
|
|
|
|
}
|
|
|
|
|
2022-02-23 11:28:56 +01:00
|
|
|
func (s *composeService) apiClient() client.APIClient {
|
|
|
|
return s.dockerCli.Client()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *composeService) configFile() *configfile.ConfigFile {
|
|
|
|
return s.dockerCli.ConfigFile()
|
|
|
|
}
|
|
|
|
|
2022-11-30 12:08:26 +01:00
|
|
|
func (s *composeService) MaxConcurrency(i int) {
|
|
|
|
s.maxConcurrency = i
|
|
|
|
}
|
|
|
|
|
2023-01-27 16:43:48 +01:00
|
|
|
func (s *composeService) DryRunMode(ctx context.Context, dryRun bool) (context.Context, error) {
|
2023-02-03 12:51:52 +01:00
|
|
|
s.dryRun = dryRun
|
2023-01-12 23:31:14 +01:00
|
|
|
if dryRun {
|
|
|
|
cli, err := command.NewDockerCli()
|
|
|
|
if err != nil {
|
2023-01-27 16:43:48 +01:00
|
|
|
return ctx, err
|
2023-01-12 23:31:14 +01:00
|
|
|
}
|
2023-07-04 15:38:57 +02:00
|
|
|
|
|
|
|
options := flags.NewClientOptions()
|
|
|
|
options.Context = s.dockerCli.CurrentContext()
|
|
|
|
err = cli.Initialize(options, command.WithInitializeClient(func(cli *command.DockerCli) (client.APIClient, error) {
|
|
|
|
return api.NewDryRunClient(s.apiClient(), s.dockerCli)
|
2023-01-12 23:31:14 +01:00
|
|
|
}))
|
2023-01-13 14:26:28 +01:00
|
|
|
if err != nil {
|
2023-01-27 16:43:48 +01:00
|
|
|
return ctx, err
|
2023-01-13 14:26:28 +01:00
|
|
|
}
|
2023-01-12 23:31:14 +01:00
|
|
|
s.dockerCli = cli
|
|
|
|
}
|
2023-01-27 16:43:48 +01:00
|
|
|
return context.WithValue(ctx, api.DryRunKey{}, dryRun), nil
|
2023-01-11 16:38:57 +01:00
|
|
|
}
|
|
|
|
|
2022-02-23 11:28:56 +01:00
|
|
|
func (s *composeService) stdout() *streams.Out {
|
|
|
|
return s.dockerCli.Out()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *composeService) stdin() *streams.In {
|
|
|
|
return s.dockerCli.In()
|
|
|
|
}
|
|
|
|
|
2024-06-24 12:52:15 +02:00
|
|
|
func (s *composeService) stderr() *streams.Out {
|
2022-02-23 11:28:56 +01:00
|
|
|
return s.dockerCli.Err()
|
2020-12-08 11:53:36 +01:00
|
|
|
}
|
|
|
|
|
2024-06-24 12:52:15 +02:00
|
|
|
func (s *composeService) stdinfo() *streams.Out {
|
2023-05-11 18:45:00 +02:00
|
|
|
if stdioToStdout {
|
|
|
|
return s.dockerCli.Out()
|
|
|
|
}
|
|
|
|
return s.dockerCli.Err()
|
|
|
|
}
|
|
|
|
|
2025-02-12 09:34:07 +01:00
|
|
|
func getCanonicalContainerName(c container.Summary) string {
|
2022-03-03 14:19:01 +01:00
|
|
|
if len(c.Names) == 0 {
|
|
|
|
// corner case, sometime happens on removal. return short ID as a safeguard value
|
|
|
|
return c.ID[:12]
|
|
|
|
}
|
2020-12-08 11:53:36 +01:00
|
|
|
// Names return container canonical name /foo + link aliases /linked_by/foo
|
|
|
|
for _, name := range c.Names {
|
|
|
|
if strings.LastIndex(name, "/") == 0 {
|
|
|
|
return name[1:]
|
|
|
|
}
|
|
|
|
}
|
2024-01-30 13:27:27 +00:00
|
|
|
|
|
|
|
return strings.TrimPrefix(c.Names[0], "/")
|
2020-12-08 11:53:36 +01:00
|
|
|
}
|
|
|
|
|
2025-02-12 09:34:07 +01:00
|
|
|
func getContainerNameWithoutProject(c container.Summary) string {
|
2021-06-14 16:26:14 +02:00
|
|
|
project := c.Labels[api.ProjectLabel]
|
2023-11-15 14:41:35 +01:00
|
|
|
defaultName := getDefaultContainerName(project, c.Labels[api.ServiceLabel], c.Labels[api.ContainerNumberLabel])
|
|
|
|
name := getCanonicalContainerName(c)
|
|
|
|
if name != defaultName {
|
|
|
|
// service declares a custom container_name
|
|
|
|
return name
|
2021-02-08 11:04:46 +01:00
|
|
|
}
|
2023-11-15 14:41:35 +01:00
|
|
|
return name[len(project)+1:]
|
2021-02-08 11:04:46 +01:00
|
|
|
}
|
|
|
|
|
2022-02-05 10:27:52 +03:30
|
|
|
// projectFromName builds a types.Project based on actual resources with compose labels set
|
2022-02-24 23:46:07 +03:30
|
|
|
func (s *composeService) projectFromName(containers Containers, projectName string, services ...string) (*types.Project, error) {
|
2022-02-05 10:27:52 +03:30
|
|
|
project := &types.Project{
|
2023-11-08 10:19:24 +01:00
|
|
|
Name: projectName,
|
|
|
|
Services: types.Services{},
|
2022-02-05 10:27:52 +03:30
|
|
|
}
|
|
|
|
if len(containers) == 0 {
|
2023-09-26 00:57:12 +02:00
|
|
|
return project, fmt.Errorf("no container found for project %q: %w", projectName, api.ErrNotFound)
|
2022-02-05 10:27:52 +03:30
|
|
|
}
|
2023-11-27 10:14:31 +01:00
|
|
|
set := types.Services{}
|
2022-02-05 10:27:52 +03:30
|
|
|
for _, c := range containers {
|
2024-10-18 13:20:06 +02:00
|
|
|
serviceLabel, ok := c.Labels[api.ServiceLabel]
|
|
|
|
if !ok {
|
|
|
|
serviceLabel = getCanonicalContainerName(c)
|
|
|
|
}
|
2023-11-08 10:19:24 +01:00
|
|
|
service, ok := set[serviceLabel]
|
2022-02-25 06:26:05 +03:30
|
|
|
if !ok {
|
2023-11-08 10:19:24 +01:00
|
|
|
service = types.ServiceConfig{
|
2022-02-25 06:26:05 +03:30
|
|
|
Name: serviceLabel,
|
build: label built images for reliable cleanup on `down`
When running `compose down`, the `--rmi` flag can be passed,
which currently supports two values:
* `local`: remove any _implicitly-named_ images that Compose
built
* `all` : remove any named images (locally-built or fetched
from a remote repo)
Removing images in the `local` case can be problematic, as it's
historically been done via a fair amount of inference over the
Compose model. Additionally, when using the "project-model"
(by passing `--project-name` instead of using a Compose file),
we're even more limited: if no containers for the project are
running, there's nothing to derive state from to perform the
inference on.
As a first pass, we started labeling _containers_ with the name
of the locally-built image associated with it (if any) in #9715.
Unfortunately, this still suffers from the aforementioned problems
around using actual state (i.e. the containers might no longer
exist) and meant that when operating in file mode (the default),
things did not behave as expected: the label is not available
in the project since it only exists at runtime.
Now, with these changes, Compose will label any images it builds
with project metadata. Upon cleanup during `down`, the engine
image API is queried for related images and matched up with the
services for the project. As a fallback for images built with
prior versions of Compose, the previous approach is still taken.
See also:
* https://github.com/docker/compose/issues/9655
* https://github.com/docker/compose/pull/9715
Signed-off-by: Milas Bowman <milas.bowman@docker.com>
2022-09-07 16:24:47 -04:00
|
|
|
Image: c.Image,
|
2022-02-25 06:26:05 +03:30
|
|
|
Labels: c.Labels,
|
|
|
|
}
|
2022-02-05 10:27:52 +03:30
|
|
|
}
|
2023-11-08 10:19:24 +01:00
|
|
|
service.Scale = increment(service.Scale)
|
2023-11-27 11:02:19 +01:00
|
|
|
set[serviceLabel] = service
|
2022-02-24 22:39:38 +03:30
|
|
|
}
|
2023-11-27 10:14:31 +01:00
|
|
|
for name, service := range set {
|
2022-02-24 22:39:38 +03:30
|
|
|
dependencies := service.Labels[api.DependenciesLabel]
|
fix linting issues with golangci-lint 1.60.2
pkg/watch/watcher_darwin.go:96:16: Error return value of `d.stream.Start` is not checked (errcheck)
d.stream.Start()
^
pkg/prompt/prompt.go:97:12: Error return value of `fmt.Fprint` is not checked (errcheck)
fmt.Fprint(u.stdout, message)
^
pkg/prompt/prompt.go:99:12: Error return value of `fmt.Scanln` is not checked (errcheck)
fmt.Scanln(&answer)
^
cmd/formatter/logs.go:118:15: Error return value of `fmt.Fprintf` is not checked (errcheck)
fmt.Fprintf(w, "%s%s%s\n", p.prefix, timestamp, line)
^
cmd/formatter/logs.go:120:15: Error return value of `fmt.Fprintf` is not checked (errcheck)
fmt.Fprintf(w, "%s%s\n", p.prefix, line)
^
pkg/progress/json.go:67:15: Error return value of `fmt.Fprintln` is not checked (errcheck)
fmt.Fprintln(p.out, string(marshal))
^
pkg/progress/json.go:87:15: Error return value of `fmt.Fprintln` is not checked (errcheck)
fmt.Fprintln(p.out, string(marshal))
^
pkg/progress/plain.go:47:14: Error return value of `fmt.Fprintln` is not checked (errcheck)
fmt.Fprintln(p.out, prefix, e.ID, e.Text, e.StatusText)
^
pkg/progress/tty.go:162:12: Error return value of `fmt.Fprint` is not checked (errcheck)
fmt.Fprint(w.out, b.Column(0).ANSI)
^
pkg/progress/tty.go:165:12: Error return value of `fmt.Fprint` is not checked (errcheck)
fmt.Fprint(w.out, aec.Hide)
^
pkg/compose/attach.go:53:13: Error return value of `fmt.Fprintf` is not checked (errcheck)
fmt.Fprintf(s.stdout(), "Attaching to %s\n", strings.Join(names, ", "))
^
pkg/compose/compose.go:194:6: emptyStringTest: replace `len(dependencies) > 0` with `dependencies != ""` (gocritic)
if len(dependencies) > 0 {
^
pkg/compose/convergence.go:461:2: builtinShadow: shadowing of predeclared identifier: max (gocritic)
max := 0
^
pkg/compose/run.go:127:5: emptyStringTest: replace `len(opts.User) > 0` with `opts.User != ""` (gocritic)
if len(opts.User) > 0 {
^
pkg/compose/run.go:139:5: emptyStringTest: replace `len(opts.WorkingDir) > 0` with `opts.WorkingDir != ""` (gocritic)
if len(opts.WorkingDir) > 0 {
^
pkg/compose/viz.go:91:8: emptyStringTest: replace `len(portConfig.HostIP) > 0` with `portConfig.HostIP != ""` (gocritic)
if len(portConfig.HostIP) > 0 {
^
cmd/compatibility/convert.go:66:6: emptyStringTest: replace `len(arg) > 0` with `arg != ""` (gocritic)
if len(arg) > 0 && arg[0] != '-' {
^
pkg/e2e/watch_test.go:208:25: printf: non-constant format string in call to gotest.tools/v3/poll.Continue (govet)
return poll.Continue(res.Combined())
^
pkg/e2e/watch_test.go:290:25: printf: non-constant format string in call to gotest.tools/v3/poll.Continue (govet)
return poll.Continue(r.Combined())
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-11 12:52:55 +02:00
|
|
|
if dependencies != "" {
|
2022-02-05 10:27:52 +03:30
|
|
|
service.DependsOn = types.DependsOnConfig{}
|
2022-02-23 21:34:34 +03:30
|
|
|
for _, dc := range strings.Split(dependencies, ",") {
|
|
|
|
dcArr := strings.Split(dc, ":")
|
|
|
|
condition := ServiceConditionRunningOrHealthy
|
2023-03-01 17:34:33 +01:00
|
|
|
// Let's restart the dependency by default if we don't have the info stored in the label
|
|
|
|
restart := true
|
2023-07-10 18:27:59 +02:00
|
|
|
required := true
|
2022-02-23 21:34:34 +03:30
|
|
|
dependency := dcArr[0]
|
|
|
|
|
|
|
|
// backward compatibility
|
|
|
|
if len(dcArr) > 1 {
|
|
|
|
condition = dcArr[1]
|
2023-03-01 17:34:33 +01:00
|
|
|
if len(dcArr) > 2 {
|
|
|
|
restart, _ = strconv.ParseBool(dcArr[2])
|
|
|
|
}
|
2022-02-23 21:34:34 +03:30
|
|
|
}
|
2023-07-10 18:27:59 +02:00
|
|
|
service.DependsOn[dependency] = types.ServiceDependency{Condition: condition, Restart: restart, Required: required}
|
2022-02-05 10:27:52 +03:30
|
|
|
}
|
2023-11-27 10:14:31 +01:00
|
|
|
set[name] = service
|
2022-02-05 10:27:52 +03:30
|
|
|
}
|
|
|
|
}
|
2023-11-27 10:14:31 +01:00
|
|
|
project.Services = set
|
|
|
|
|
2022-02-24 23:46:07 +03:30
|
|
|
SERVICES:
|
|
|
|
for _, qs := range services {
|
|
|
|
for _, es := range project.Services {
|
|
|
|
if es.Name == qs {
|
|
|
|
continue SERVICES
|
|
|
|
}
|
|
|
|
}
|
2023-09-26 00:57:12 +02:00
|
|
|
return project, fmt.Errorf("no such service: %q: %w", qs, api.ErrNotFound)
|
2022-02-24 23:46:07 +03:30
|
|
|
}
|
2023-12-29 11:45:45 +01:00
|
|
|
project, err := project.WithSelectedServices(services)
|
2022-02-27 03:40:46 +03:30
|
|
|
if err != nil {
|
|
|
|
return project, err
|
|
|
|
}
|
2022-02-05 10:27:52 +03:30
|
|
|
|
2022-02-24 23:46:07 +03:30
|
|
|
return project, nil
|
2022-02-05 10:27:52 +03:30
|
|
|
}
|
2022-03-09 08:25:01 +01:00
|
|
|
|
2023-11-08 10:19:24 +01:00
|
|
|
func increment(scale *int) *int {
|
|
|
|
i := 1
|
|
|
|
if scale != nil {
|
|
|
|
i = *scale + 1
|
|
|
|
}
|
|
|
|
return &i
|
|
|
|
}
|
|
|
|
|
2022-03-14 15:14:03 +01:00
|
|
|
func (s *composeService) actualVolumes(ctx context.Context, projectName string) (types.Volumes, error) {
|
2023-06-06 16:55:54 -04:00
|
|
|
opts := volume.ListOptions{
|
|
|
|
Filters: filters.NewArgs(projectFilter(projectName)),
|
|
|
|
}
|
|
|
|
volumes, err := s.apiClient().VolumeList(ctx, opts)
|
2022-03-14 15:14:03 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := types.Volumes{}
|
|
|
|
for _, vol := range volumes.Volumes {
|
|
|
|
actual[vol.Labels[api.VolumeLabel]] = types.VolumeConfig{
|
|
|
|
Name: vol.Name,
|
|
|
|
Driver: vol.Driver,
|
|
|
|
Labels: vol.Labels,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return actual, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *composeService) actualNetworks(ctx context.Context, projectName string) (types.Networks, error) {
|
2024-06-07 17:57:54 +02:00
|
|
|
networks, err := s.apiClient().NetworkList(ctx, network.ListOptions{
|
2022-03-14 15:14:03 +01:00
|
|
|
Filters: filters.NewArgs(projectFilter(projectName)),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := types.Networks{}
|
|
|
|
for _, net := range networks {
|
|
|
|
actual[net.Labels[api.NetworkLabel]] = types.NetworkConfig{
|
|
|
|
Name: net.Name,
|
|
|
|
Driver: net.Driver,
|
|
|
|
Labels: net.Labels,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return actual, nil
|
|
|
|
}
|
2023-05-14 14:32:23 +02:00
|
|
|
|
|
|
|
var swarmEnabled = struct {
|
|
|
|
once sync.Once
|
|
|
|
val bool
|
|
|
|
err error
|
|
|
|
}{}
|
|
|
|
|
|
|
|
func (s *composeService) isSWarmEnabled(ctx context.Context) (bool, error) {
|
|
|
|
swarmEnabled.once.Do(func() {
|
|
|
|
info, err := s.apiClient().Info(ctx)
|
|
|
|
if err != nil {
|
|
|
|
swarmEnabled.err = err
|
|
|
|
}
|
2023-05-22 08:26:22 +02:00
|
|
|
switch info.Swarm.LocalNodeState {
|
|
|
|
case swarm.LocalNodeStateInactive, swarm.LocalNodeStateLocked:
|
|
|
|
swarmEnabled.val = false
|
|
|
|
default:
|
|
|
|
swarmEnabled.val = true
|
2023-05-14 14:32:23 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
return swarmEnabled.val, swarmEnabled.err
|
2023-11-20 11:45:16 +01:00
|
|
|
}
|
|
|
|
|
2024-01-30 17:41:19 +00:00
|
|
|
type runtimeVersionCache struct {
|
2023-11-20 11:45:16 +01:00
|
|
|
once sync.Once
|
|
|
|
val string
|
|
|
|
err error
|
2024-01-30 17:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var runtimeVersion runtimeVersionCache
|
2023-11-20 11:45:16 +01:00
|
|
|
|
|
|
|
func (s *composeService) RuntimeVersion(ctx context.Context) (string, error) {
|
|
|
|
runtimeVersion.once.Do(func() {
|
|
|
|
version, err := s.dockerCli.Client().ServerVersion(ctx)
|
|
|
|
if err != nil {
|
|
|
|
runtimeVersion.err = err
|
|
|
|
}
|
|
|
|
runtimeVersion.val = version.APIVersion
|
|
|
|
})
|
|
|
|
return runtimeVersion.val, runtimeVersion.err
|
2023-05-14 14:32:23 +02:00
|
|
|
}
|
2024-03-08 14:07:51 +00:00
|
|
|
|
|
|
|
func (s *composeService) isDesktopIntegrationActive() bool {
|
|
|
|
return s.desktopCli != nil
|
|
|
|
}
|