backend.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // +build local
  2. /*
  3. Copyright 2020 Docker Compose CLI authors
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package local
  15. import (
  16. "context"
  17. "github.com/docker/docker/client"
  18. "github.com/docker/compose-cli/api/compose"
  19. "github.com/docker/compose-cli/api/containers"
  20. "github.com/docker/compose-cli/api/resources"
  21. "github.com/docker/compose-cli/api/secrets"
  22. "github.com/docker/compose-cli/api/volumes"
  23. "github.com/docker/compose-cli/backend"
  24. "github.com/docker/compose-cli/context/cloud"
  25. )
  26. type local struct {
  27. *containerService
  28. *volumeService
  29. }
  30. func init() {
  31. backend.Register("local", "local", service, cloud.NotImplementedCloudService)
  32. }
  33. func service(ctx context.Context) (backend.Service, error) {
  34. apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
  35. if err != nil {
  36. return nil, err
  37. }
  38. return &local{
  39. containerService: &containerService{apiClient},
  40. volumeService: &volumeService{apiClient},
  41. }, nil
  42. }
  43. func (s *local) ContainerService() containers.Service {
  44. return s.containerService
  45. }
  46. func (s *local) ComposeService() compose.Service {
  47. return s
  48. }
  49. func (s *local) SecretsService() secrets.Service {
  50. return nil
  51. }
  52. func (s *local) VolumeService() volumes.Service {
  53. return s.volumeService
  54. }
  55. func (s *local) ResourceService() resources.Service {
  56. return nil
  57. }