api.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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, options UpOptions) error
  32. // Down executes the equivalent to a `compose down`
  33. Down(ctx context.Context, projectName string, options DownOptions) 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, options ConvertOptions) ([]byte, error)
  42. }
  43. // UpOptions group options of the Up API
  44. type UpOptions struct {
  45. // Detach will create services and return immediately
  46. Detach bool
  47. }
  48. // DownOptions group options of the Down API
  49. type DownOptions struct {
  50. // RemoveOrphans will cleanup containers that are not declared on the compose model but own the same labels
  51. RemoveOrphans bool
  52. }
  53. // ConvertOptions group options of the Convert API
  54. type ConvertOptions struct {
  55. // Format define the output format used to dump converted application model (json|yaml)
  56. Format string
  57. }
  58. // PortPublisher hold status about published port
  59. type PortPublisher struct {
  60. URL string
  61. TargetPort int
  62. PublishedPort int
  63. Protocol string
  64. }
  65. // ContainerSummary hold high-level description of a container
  66. type ContainerSummary struct {
  67. ID string
  68. Name string
  69. Project string
  70. Service string
  71. State string
  72. Publishers []PortPublisher
  73. }
  74. // ServiceStatus hold status about a service
  75. type ServiceStatus struct {
  76. ID string
  77. Name string
  78. Replicas int
  79. Desired int
  80. Ports []string
  81. Publishers []PortPublisher
  82. }
  83. // LogOptions defines optional parameters for the `Log` API
  84. type LogOptions struct {
  85. Services []string
  86. }
  87. const (
  88. // STARTING indicates that stack is being deployed
  89. STARTING string = "Starting"
  90. // RUNNING indicates that stack is deployed and services are running
  91. RUNNING string = "Running"
  92. // UPDATING indicates that some stack resources are being recreated
  93. UPDATING string = "Updating"
  94. // REMOVING indicates that stack is being deleted
  95. REMOVING string = "Removing"
  96. // UNKNOWN indicates unknown stack state
  97. UNKNOWN string = "Unknown"
  98. // FAILED indicates that stack deployment failed
  99. FAILED string = "Failed"
  100. )
  101. // Stack holds the name and state of a compose application/stack
  102. type Stack struct {
  103. ID string
  104. Name string
  105. Status string
  106. Reason string
  107. }
  108. // LogConsumer is a callback to process log messages from services
  109. type LogConsumer interface {
  110. Log(service, container, message string)
  111. }