1
0

api.go 2.8 KB

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