api.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. "io"
  17. "github.com/compose-spec/compose-go/types"
  18. )
  19. // Service manages a compose project
  20. type Service interface {
  21. // Build executes the equivalent to a `compose build`
  22. Build(ctx context.Context, project *types.Project) error
  23. // Push executes the equivalent ot a `compose push`
  24. Push(ctx context.Context, project *types.Project) error
  25. // Up executes the equivalent to a `compose up`
  26. Up(ctx context.Context, project *types.Project, detach bool) error
  27. // Down executes the equivalent to a `compose down`
  28. Down(ctx context.Context, projectName string) error
  29. // Logs executes the equivalent to a `compose logs`
  30. Logs(ctx context.Context, projectName string, w io.Writer) error
  31. // Ps executes the equivalent to a `compose ps`
  32. Ps(ctx context.Context, projectName string) ([]ServiceStatus, error)
  33. // List executes the equivalent to a `docker stack ls`
  34. List(ctx context.Context, projectName string) ([]Stack, error)
  35. // Convert translate compose model into backend's native format
  36. Convert(ctx context.Context, project *types.Project, format string) ([]byte, error)
  37. }
  38. // PortPublisher hold status about published port
  39. type PortPublisher struct {
  40. URL string
  41. TargetPort int
  42. PublishedPort int
  43. Protocol string
  44. }
  45. // ServiceStatus hold status about a service
  46. type ServiceStatus struct {
  47. ID string
  48. Name string
  49. Replicas int
  50. Desired int
  51. Ports []string
  52. Publishers []PortPublisher
  53. }
  54. const (
  55. // STARTING indicates that stack is being deployed
  56. STARTING string = "Starting"
  57. // RUNNING indicates that stack is deployed and services are running
  58. RUNNING string = "Running"
  59. // UPDATING indicates that some stack resources are being recreated
  60. UPDATING string = "Updating"
  61. // REMOVING indicates that stack is being deleted
  62. REMOVING string = "Removing"
  63. // UNKNOWN indicates unknown stack state
  64. UNKNOWN string = "Unknown"
  65. // FAILED indicates that stack deployment failed
  66. FAILED string = "Failed"
  67. )
  68. // Stack holds the name and state of a compose application/stack
  69. type Stack struct {
  70. ID string
  71. Name string
  72. Status string
  73. Reason string
  74. }