backend.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Copyright 2020 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 local
  14. import (
  15. "context"
  16. "github.com/docker/docker/client"
  17. "github.com/docker/compose-cli/api/compose"
  18. "github.com/docker/compose-cli/api/containers"
  19. "github.com/docker/compose-cli/api/resources"
  20. "github.com/docker/compose-cli/api/secrets"
  21. "github.com/docker/compose-cli/api/volumes"
  22. "github.com/docker/compose-cli/backend"
  23. "github.com/docker/compose-cli/context/cloud"
  24. local_compose "github.com/docker/compose-cli/local/compose"
  25. )
  26. type local struct {
  27. containerService *containerService
  28. volumeService *volumeService
  29. composeService compose.Service
  30. }
  31. func init() {
  32. backend.Register("local", "local", service, cloud.NotImplementedCloudService)
  33. }
  34. func service(ctx context.Context) (backend.Service, error) {
  35. apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
  36. if err != nil {
  37. return nil, err
  38. }
  39. return &local{
  40. containerService: &containerService{apiClient},
  41. volumeService: &volumeService{apiClient},
  42. composeService: local_compose.NewComposeService(apiClient),
  43. }, nil
  44. }
  45. func (s *local) ContainerService() containers.Service {
  46. return s.containerService
  47. }
  48. func (s *local) ComposeService() compose.Service {
  49. return s.composeService
  50. }
  51. func (s *local) SecretsService() secrets.Service {
  52. return nil
  53. }
  54. func (s *local) VolumeService() volumes.Service {
  55. return s.volumeService
  56. }
  57. func (s *local) ResourceService() resources.Service {
  58. return nil
  59. }