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