compose.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // +build kube
  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 kube
  15. import (
  16. "context"
  17. "github.com/compose-spec/compose-go/types"
  18. "github.com/docker/compose-cli/api/compose"
  19. "github.com/docker/compose-cli/api/context/store"
  20. "github.com/docker/compose-cli/api/errdefs"
  21. "github.com/docker/compose-cli/kube/charts"
  22. )
  23. // NewComposeService create a kubernetes implementation of the compose.Service API
  24. func NewComposeService(ctx store.KubeContext) (compose.Service, error) {
  25. chartsAPI, err := charts.NewSDK(ctx)
  26. if err != nil {
  27. return nil, err
  28. }
  29. return &composeService{
  30. ctx: ctx,
  31. sdk: chartsAPI,
  32. }, nil
  33. }
  34. type composeService struct {
  35. ctx store.KubeContext
  36. sdk charts.SDK
  37. }
  38. // Up executes the equivalent to a `compose up`
  39. func (s *composeService) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error {
  40. return s.sdk.Install(project)
  41. }
  42. // Down executes the equivalent to a `compose down`
  43. func (s *composeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
  44. return s.sdk.Uninstall(projectName)
  45. }
  46. // List executes the equivalent to a `docker stack ls`
  47. func (s *composeService) List(ctx context.Context) ([]compose.Stack, error) {
  48. return s.sdk.List()
  49. }
  50. // Build executes the equivalent to a `compose build`
  51. func (s *composeService) Build(ctx context.Context, project *types.Project) error {
  52. return errdefs.ErrNotImplemented
  53. }
  54. // Push executes the equivalent ot a `compose push`
  55. func (s *composeService) Push(ctx context.Context, project *types.Project) error {
  56. return errdefs.ErrNotImplemented
  57. }
  58. // Pull executes the equivalent of a `compose pull`
  59. func (s *composeService) Pull(ctx context.Context, project *types.Project) error {
  60. return errdefs.ErrNotImplemented
  61. }
  62. // Create executes the equivalent to a `compose create`
  63. func (s *composeService) Create(ctx context.Context, project *types.Project, opts compose.CreateOptions) error {
  64. return errdefs.ErrNotImplemented
  65. }
  66. // Start executes the equivalent to a `compose start`
  67. func (s *composeService) Start(ctx context.Context, project *types.Project, consumer compose.LogConsumer) error {
  68. return errdefs.ErrNotImplemented
  69. }
  70. // Stop executes the equivalent to a `compose stop`
  71. func (s *composeService) Stop(ctx context.Context, project *types.Project) error {
  72. return errdefs.ErrNotImplemented
  73. }
  74. // Logs executes the equivalent to a `compose logs`
  75. func (s *composeService) Logs(ctx context.Context, projectName string, consumer compose.LogConsumer, options compose.LogOptions) error {
  76. return errdefs.ErrNotImplemented
  77. }
  78. // Ps executes the equivalent to a `compose ps`
  79. func (s *composeService) Ps(ctx context.Context, projectName string) ([]compose.ContainerSummary, error) {
  80. return nil, errdefs.ErrNotImplemented
  81. }
  82. // Convert translate compose model into backend's native format
  83. func (s *composeService) Convert(ctx context.Context, project *types.Project, options compose.ConvertOptions) ([]byte, error) {
  84. return nil, errdefs.ErrNotImplemented
  85. }
  86. // RunOneOffContainer creates a service oneoff container and starts its dependencies
  87. func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) error {
  88. return errdefs.ErrNotImplemented
  89. }