api.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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) error
  36. // Ps executes the equivalent to a `compose ps`
  37. Ps(ctx context.Context, projectName string) ([]ServiceStatus, 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. // ServiceStatus hold status about a service
  51. type ServiceStatus struct {
  52. ID string
  53. Name string
  54. Replicas int
  55. Desired int
  56. Ports []string
  57. Publishers []PortPublisher
  58. }
  59. const (
  60. // STARTING indicates that stack is being deployed
  61. STARTING string = "Starting"
  62. // RUNNING indicates that stack is deployed and services are running
  63. RUNNING string = "Running"
  64. // UPDATING indicates that some stack resources are being recreated
  65. UPDATING string = "Updating"
  66. // REMOVING indicates that stack is being deleted
  67. REMOVING string = "Removing"
  68. // UNKNOWN indicates unknown stack state
  69. UNKNOWN string = "Unknown"
  70. // FAILED indicates that stack deployment failed
  71. FAILED string = "Failed"
  72. )
  73. // Stack holds the name and state of a compose application/stack
  74. type Stack struct {
  75. ID string
  76. Name string
  77. Status string
  78. Reason string
  79. }
  80. // LogConsumer is a callback to process log messages from services
  81. type LogConsumer interface {
  82. Log(service, container, message string)
  83. }