compose.go 3.7 KB

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