api.go 2.6 KB

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