desktop.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. Copyright 2024 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package compose
  14. import (
  15. "context"
  16. "strings"
  17. )
  18. // engineLabelDesktopAddress is used to detect that Compose is running with a
  19. // Docker Desktop context. When this label is present, the value is an endpoint
  20. // address for an in-memory socket (AF_UNIX or named pipe).
  21. const engineLabelDesktopAddress = "com.docker.desktop.address"
  22. func (s *composeService) isDesktopIntegrationActive(ctx context.Context) (bool, error) {
  23. info, err := s.apiClient().Info(ctx)
  24. if err != nil {
  25. return false, err
  26. }
  27. for _, l := range info.Labels {
  28. k, _, ok := strings.Cut(l, "=")
  29. if ok && k == engineLabelDesktopAddress {
  30. return true, nil
  31. }
  32. }
  33. return false, nil
  34. }