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