service.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package project
  2. import (
  3. "errors"
  4. "golang.org/x/net/context"
  5. "github.com/docker/libcompose/config"
  6. "github.com/docker/libcompose/project/options"
  7. )
  8. // Service defines what a libcompose service provides.
  9. type Service interface {
  10. Build(ctx context.Context, buildOptions options.Build) error
  11. Create(ctx context.Context, options options.Create) error
  12. Delete(ctx context.Context, options options.Delete) error
  13. Info(ctx context.Context, qFlag bool) (InfoSet, error)
  14. Log(ctx context.Context, follow bool) error
  15. Kill(ctx context.Context, signal string) error
  16. Pause(ctx context.Context) error
  17. Pull(ctx context.Context) error
  18. Restart(ctx context.Context, timeout int) error
  19. Run(ctx context.Context, commandParts []string) (int, error)
  20. Scale(ctx context.Context, count int, timeout int) error
  21. Start(ctx context.Context) error
  22. Stop(ctx context.Context, timeout int) error
  23. Unpause(ctx context.Context) error
  24. Up(ctx context.Context, options options.Up) error
  25. RemoveImage(ctx context.Context, imageType options.ImageType) error
  26. Containers(ctx context.Context) ([]Container, error)
  27. DependentServices() []ServiceRelationship
  28. Config() *config.ServiceConfig
  29. Name() string
  30. }
  31. // ServiceState holds the state of a service.
  32. type ServiceState string
  33. // State definitions
  34. var (
  35. StateExecuted = ServiceState("executed")
  36. StateUnknown = ServiceState("unknown")
  37. )
  38. // Error definitions
  39. var (
  40. ErrRestart = errors.New("Restart execution")
  41. ErrUnsupported = errors.New("UnsupportedOperation")
  42. )
  43. // ServiceFactory is an interface factory to create Service object for the specified
  44. // project, with the specified name and service configuration.
  45. type ServiceFactory interface {
  46. Create(project *Project, name string, serviceConfig *config.ServiceConfig) (Service, error)
  47. }
  48. // ServiceRelationshipType defines the type of service relationship.
  49. type ServiceRelationshipType string
  50. // RelTypeLink means the services are linked (docker links).
  51. const RelTypeLink = ServiceRelationshipType("")
  52. // RelTypeNetNamespace means the services share the same network namespace.
  53. const RelTypeNetNamespace = ServiceRelationshipType("netns")
  54. // RelTypeIpcNamespace means the service share the same ipc namespace.
  55. const RelTypeIpcNamespace = ServiceRelationshipType("ipc")
  56. // RelTypeVolumesFrom means the services share some volumes.
  57. const RelTypeVolumesFrom = ServiceRelationshipType("volumesFrom")
  58. // RelTypeDependsOn means the dependency was explicitly set using 'depends_on'.
  59. const RelTypeDependsOn = ServiceRelationshipType("dependsOn")
  60. // ServiceRelationship holds the relationship information between two services.
  61. type ServiceRelationship struct {
  62. Target, Alias string
  63. Type ServiceRelationshipType
  64. Optional bool
  65. }
  66. // NewServiceRelationship creates a new Relationship based on the specified alias
  67. // and relationship type.
  68. func NewServiceRelationship(nameAlias string, relType ServiceRelationshipType) ServiceRelationship {
  69. name, alias := NameAlias(nameAlias)
  70. return ServiceRelationship{
  71. Target: name,
  72. Alias: alias,
  73. Type: relType,
  74. }
  75. }