api.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 compose
  14. import (
  15. "context"
  16. "github.com/compose-spec/compose-go/types"
  17. )
  18. // Service manages a compose project
  19. type Service interface {
  20. // Build executes the equivalent to a `compose build`
  21. Build(ctx context.Context, project *types.Project) error
  22. // Push executes the equivalent ot a `compose push`
  23. Push(ctx context.Context, project *types.Project) error
  24. // Pull executes the equivalent of a `compose pull`
  25. Pull(ctx context.Context, project *types.Project) error
  26. // Create executes the equivalent to a `compose create`
  27. Create(ctx context.Context, project *types.Project) error
  28. // Start executes the equivalent to a `compose start`
  29. Start(ctx context.Context, project *types.Project, consumer LogConsumer) error
  30. // Up executes the equivalent to a `compose up`
  31. Up(ctx context.Context, project *types.Project, detach bool) error
  32. // Down executes the equivalent to a `compose down`
  33. Down(ctx context.Context, projectName string) error
  34. // Logs executes the equivalent to a `compose logs`
  35. Logs(ctx context.Context, projectName string, consumer LogConsumer, options LogOptions) error
  36. // Ps executes the equivalent to a `compose ps`
  37. Ps(ctx context.Context, projectName string) ([]ContainerSummary, error)
  38. // List executes the equivalent to a `docker stack ls`
  39. List(ctx context.Context, projectName string) ([]Stack, error)
  40. // Convert translate compose model into backend's native format
  41. Convert(ctx context.Context, project *types.Project, format string) ([]byte, error)
  42. }
  43. // PortPublisher hold status about published port
  44. type PortPublisher struct {
  45. URL string
  46. TargetPort int
  47. PublishedPort int
  48. Protocol string
  49. }
  50. // ContainerSummary hold high-level description of a container
  51. type ContainerSummary struct {
  52. ID string
  53. Name string
  54. Project string
  55. Service string
  56. State string
  57. Publishers []PortPublisher
  58. }
  59. // ServiceStatus hold status about a service
  60. type ServiceStatus struct {
  61. ID string
  62. Name string
  63. Replicas int
  64. Desired int
  65. Ports []string
  66. Publishers []PortPublisher
  67. }
  68. // LogOptions defines optional parameters for the `Log` API
  69. type LogOptions struct {
  70. Services []string
  71. }
  72. const (
  73. // STARTING indicates that stack is being deployed
  74. STARTING string = "Starting"
  75. // RUNNING indicates that stack is deployed and services are running
  76. RUNNING string = "Running"
  77. // UPDATING indicates that some stack resources are being recreated
  78. UPDATING string = "Updating"
  79. // REMOVING indicates that stack is being deleted
  80. REMOVING string = "Removing"
  81. // UNKNOWN indicates unknown stack state
  82. UNKNOWN string = "Unknown"
  83. // FAILED indicates that stack deployment failed
  84. FAILED string = "Failed"
  85. )
  86. // Stack holds the name and state of a compose application/stack
  87. type Stack struct {
  88. ID string
  89. Name string
  90. Status string
  91. Reason string
  92. }
  93. // LogConsumer is a callback to process log messages from services
  94. type LogConsumer interface {
  95. Log(service, container, message string)
  96. }