backend.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. "os"
  16. cliconfig "github.com/docker/cli/cli/config"
  17. "github.com/docker/docker/client"
  18. "github.com/docker/compose-cli/api/backend"
  19. "github.com/docker/compose-cli/api/cloud"
  20. "github.com/docker/compose-cli/api/containers"
  21. "github.com/docker/compose-cli/api/context/store"
  22. "github.com/docker/compose-cli/api/resources"
  23. "github.com/docker/compose-cli/api/secrets"
  24. "github.com/docker/compose-cli/api/volumes"
  25. "github.com/docker/compose-cli/pkg/api"
  26. "github.com/docker/compose-cli/pkg/compose"
  27. )
  28. const backendType = store.EcsLocalSimulationContextType
  29. func init() {
  30. backend.Register(backendType, backendType, service, getCloudService)
  31. }
  32. type ecsLocalSimulation struct {
  33. moby *client.Client
  34. compose api.Service
  35. }
  36. func service() (backend.Service, error) {
  37. apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
  38. if err != nil {
  39. return nil, err
  40. }
  41. return &ecsLocalSimulation{
  42. moby: apiClient,
  43. compose: compose.NewComposeService(apiClient, cliconfig.LoadDefaultConfigFile(os.Stderr)),
  44. }, nil
  45. }
  46. func getCloudService() (cloud.Service, error) {
  47. return ecsLocalSimulation{}, nil
  48. }
  49. func (e ecsLocalSimulation) ContainerService() containers.Service {
  50. return nil
  51. }
  52. func (e ecsLocalSimulation) VolumeService() volumes.Service {
  53. return nil
  54. }
  55. func (e ecsLocalSimulation) SecretsService() secrets.Service {
  56. return nil
  57. }
  58. func (e ecsLocalSimulation) ComposeService() api.Service {
  59. return e
  60. }
  61. func (e ecsLocalSimulation) ResourceService() resources.Service {
  62. return nil
  63. }