project

package
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2017 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

package project contains a stripped down version of libcompose types from commit 3ca15215f36154fbf64f15bfa305bfb0cebb6ca7

Index

Constants

View Source
const (
	NoEvent = EventType(iota)

	EventContainerCreated = EventType(iota)
	EventContainerStarted = EventType(iota)

	EventServiceAdd          = EventType(iota)
	EventServiceUpStart      = EventType(iota)
	EventServiceUpIgnored    = EventType(iota)
	EventServiceUp           = EventType(iota)
	EventServiceCreateStart  = EventType(iota)
	EventServiceCreate       = EventType(iota)
	EventServiceDeleteStart  = EventType(iota)
	EventServiceDelete       = EventType(iota)
	EventServiceDownStart    = EventType(iota)
	EventServiceDown         = EventType(iota)
	EventServiceRestartStart = EventType(iota)
	EventServiceRestart      = EventType(iota)
	EventServicePullStart    = EventType(iota)
	EventServicePull         = EventType(iota)
	EventServiceKillStart    = EventType(iota)
	EventServiceKill         = EventType(iota)
	EventServiceStartStart   = EventType(iota)
	EventServiceStart        = EventType(iota)
	EventServiceBuildStart   = EventType(iota)
	EventServiceBuild        = EventType(iota)
	EventServicePauseStart   = EventType(iota)
	EventServicePause        = EventType(iota)
	EventServiceUnpauseStart = EventType(iota)
	EventServiceUnpause      = EventType(iota)

	EventProjectDownStart     = EventType(iota)
	EventProjectDownDone      = EventType(iota)
	EventProjectCreateStart   = EventType(iota)
	EventProjectCreateDone    = EventType(iota)
	EventProjectUpStart       = EventType(iota)
	EventProjectUpDone        = EventType(iota)
	EventProjectDeleteStart   = EventType(iota)
	EventProjectDeleteDone    = EventType(iota)
	EventProjectRestartStart  = EventType(iota)
	EventProjectRestartDone   = EventType(iota)
	EventProjectReload        = EventType(iota)
	EventProjectReloadTrigger = EventType(iota)
	EventProjectKillStart     = EventType(iota)
	EventProjectKillDone      = EventType(iota)
	EventProjectStartStart    = EventType(iota)
	EventProjectStartDone     = EventType(iota)
	EventProjectBuildStart    = EventType(iota)
	EventProjectBuildDone     = EventType(iota)
	EventProjectPauseStart    = EventType(iota)
	EventProjectPauseDone     = EventType(iota)
	EventProjectUnpauseStart  = EventType(iota)
	EventProjectUnpauseDone   = EventType(iota)
)

Definitions of libcompose events

View Source
const RelTypeIpcNamespace = ServiceRelationshipType("ipc")

RelTypeIpcNamespace means the service share the same ipc namespace.

View Source
const RelTypeLink = ServiceRelationshipType("")

RelTypeLink means the services are linked (docker links).

View Source
const RelTypeNetNamespace = ServiceRelationshipType("netns")

RelTypeNetNamespace means the services share the same network namespace.

View Source
const RelTypeVolumesFrom = ServiceRelationshipType("volumesFrom")

RelTypeVolumesFrom means the services share some volumes.

Variables

View Source
var (
	StateExecuted = ServiceState("executed")
	StateUnknown  = ServiceState("unknown")
)

State definitions

View Source
var (
	ErrRestart     = errors.New("Restart execution")
	ErrUnsupported = errors.New("UnsupportedOperation")
)

Error definitions

View Source
var (
	// ValidRemotes list the of valid prefixes that can be sent to Docker as a build remote location
	// This is public for consumers of libcompose to use
	ValidRemotes = []string{
		"git://",
		"git@github.com:",
		"github.com",
		"http:",
		"https:",
	}
)

Functions

func AddEnvironmentLookUp

func AddEnvironmentLookUp(context *Context) error

AddEnvironmentLookUp adds mechanism for extracting environment variables, from operating system or .env file

func Convert

func Convert(src, target interface{}) error

Convert converts a struct (src) to another one (target) using yaml marshalling/unmarshalling. If the structure are not compatible, this will throw an error as the unmarshalling will fail.

func GetContainerFromIpcLikeConfig

func GetContainerFromIpcLikeConfig(p *Project, conf string) string

GetContainerFromIpcLikeConfig returns name of the service that shares the IPC namespace with the specified service.

func GetServiceHash

func GetServiceHash(name string, config *ServiceConfig) string

GetServiceHash computes and returns a hash that will identify a service. This hash will be then used to detect if the service definition/configuration have changed and needs to be recreated.

func NameAlias

func NameAlias(name string) (string, string)

NameAlias returns the name and alias based on the specified string. If the name contains a colon (like name:alias) it will split it, otherwise it will return the specified name as name and alias.

func ParseEnvFile

func ParseEnvFile(filename string) ([]string, error)

ParseEnvFile reads a file with environment variables enumerated by lines

“Environment variable names used by the utilities in the Shell and Utilities volume of IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore) from the characters defined in Portable Character Set and do not begin with a digit. *But*, other characters may be permitted by an implementation; applications shall tolerate the presence of such names.” -- http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html

As of #16585, it's up to application inside docker to validate or not environment variables, that's why we just strip leading whitespace and nothing more.

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

Command represents a docker command, can be a string or an array of strings. FIXME why not use Stringorslice (type Command struct { Stringorslice }

func NewCommand

func NewCommand(parts ...string) Command

NewCommand create a Command based on the specified parts (as strings).

func (Command) MarshalYAML

func (s Command) MarshalYAML() (value interface{}, err error)

MarshalYAML implements the Marshaller interface.

func (*Command) Slice

func (s *Command) Slice() []string

Slice gets the parts of the Command as a Slice of string.

func (*Command) ToString

func (s *Command) ToString() string

ToString returns the parts of the command as a string (joined by spaces).

func (*Command) UnmarshalYAML

func (s *Command) UnmarshalYAML(unmarshal func(value interface{}) error) error

UnmarshalYAML implements the Unmarshaller interface.

type ComposableEnvLookup

type ComposableEnvLookup struct {
	Lookups []EnvironmentLookup
}

ComposableEnvLookup is a structure that implements the EnvironmentLookup interface. It holds an ordered list of EnvironmentLookup to call to look for the environment value.

func (*ComposableEnvLookup) Lookup

func (l *ComposableEnvLookup) Lookup(key, serviceName string, config *ServiceConfig) []string

Lookup creates a string slice of string containing a "docker-friendly" environment string in the form of 'key=value'. It loop through the lookups and returns the latest value if more than one lookup return a result.

type Container

type Container interface {
	ID() (string, error)
	Name() string
	Port(port string) (string, error)
	IsRunning() (bool, error)
}

Container defines what a libcompose container provides.

type Context

type Context struct {
	Timeout       uint
	Log           bool
	Volume        bool
	ForceRecreate bool
	NoRecreate    bool
	NoCache       bool
	NoBuild       bool
	Signal        string
	ComposeFiles  []string
	ComposeBytes  [][]byte
	ProjectName   string

	ServiceFactory      ServiceFactory
	EnvironmentLookup   EnvironmentLookup
	ResourceLookup      ResourceLookup
	IgnoreMissingConfig bool
	Project             *Project
	// contains filtered or unexported fields
}

Context holds context meta information about a libcompose project, like the project name, the compose file, etc.

type EmptyService

type EmptyService struct {
}

EmptyService is a struct that implements Service but does nothing.

func (*EmptyService) Build

func (e *EmptyService) Build() error

Build implements Service.Build but does nothing.

func (*EmptyService) Containers

func (e *EmptyService) Containers() ([]Container, error)

Containers implements Service.Containers but does nothing.

func (*EmptyService) Create

func (e *EmptyService) Create() error

Create implements Service.Create but does nothing.

func (*EmptyService) Delete

func (e *EmptyService) Delete() error

Delete implements Service.Delete but does nothing.

func (*EmptyService) Down

func (e *EmptyService) Down() error

Down implements Service.Down but does nothing.

func (*EmptyService) Info

func (e *EmptyService) Info(qFlag bool) (InfoSet, error)

Info implements Service.Info but does nothing.

func (*EmptyService) Kill

func (e *EmptyService) Kill() error

Kill implements Service.Kill but does nothing.

func (*EmptyService) Log

func (e *EmptyService) Log() error

Log implements Service.Log but does nothing.

func (*EmptyService) Pause

func (e *EmptyService) Pause() error

Pause implements Service.Pause but does nothing.

func (*EmptyService) Pull

func (e *EmptyService) Pull() error

Pull implements Service.Pull but does nothing.

func (*EmptyService) Restart

func (e *EmptyService) Restart() error

Restart implements Service.Restart but does nothing.

func (*EmptyService) Scale

func (e *EmptyService) Scale(count int) error

Scale implements Service.Scale but does nothing.

func (*EmptyService) Start

func (e *EmptyService) Start() error

Start implements Service.Start but does nothing.

func (*EmptyService) Unpause

func (e *EmptyService) Unpause() error

Unpause implements Service.Pause but does nothing.

func (*EmptyService) Up

func (e *EmptyService) Up() error

Up implements Service.Up but does nothing.

type EnvfileLookup

type EnvfileLookup struct {
	Path string
}

EnvfileLookup is a structure that implements the EnvironmentLookup interface. It holds the path of the file where to lookup environment values.

func (*EnvfileLookup) Lookup

func (l *EnvfileLookup) Lookup(key, serviceName string, config *ServiceConfig) []string

Lookup creates a string slice of string containing a "docker-friendly" environment string in the form of 'key=value'. It gets environment values using a '.env' file in the specified path.

type EnvironmentLookup

type EnvironmentLookup interface {
	Lookup(key, serviceName string, config *ServiceConfig) []string
}

EnvironmentLookup defines methods to provides environment variable loading.

type Event

type Event struct {
	EventType   EventType
	ServiceName string
	Data        map[string]string
}

Event holds project-wide event informations.

type EventType

type EventType int

EventType defines a type of libcompose event.

func (EventType) String

func (e EventType) String() string

type FileResourceLookup

type FileResourceLookup struct {
}

FileResourceLookup is a "bare" structure that implements the project.ResourceLookup interface

func (*FileResourceLookup) Lookup

func (f *FileResourceLookup) Lookup(file, relativeTo string) ([]byte, string, error)

Lookup returns the content and the actual filename of the file that is "built" using the specified file and relativeTo string. file and relativeTo are supposed to be file path. If file starts with a slash ('/'), it tries to load it, otherwise it will build a filename using the folder part of relativeTo joined with file.

func (*FileResourceLookup) ResolvePath

func (f *FileResourceLookup) ResolvePath(path, relativeTo string) string

ResolvePath returns the path to be used for the given path volume. This function already takes care of relative paths.

type Info

type Info []InfoPart

Info holds a list of InfoPart.

type InfoPart

type InfoPart struct {
	Key, Value string
}

InfoPart holds key/value strings.

type InfoSet

type InfoSet []Info

InfoSet holds a list of Info.

func (InfoSet) String

func (infos InfoSet) String(titleFlag bool) string

type MaporColonSlice

type MaporColonSlice struct {
	// contains filtered or unexported fields
}

MaporColonSlice represents a slice of strings that gets unmarshal from a YAML map into 'key:value' string.

func NewMaporColonSlice

func NewMaporColonSlice(parts []string) MaporColonSlice

NewMaporColonSlice creates a new MaporColonSlice based on the specified parts.

func (MaporColonSlice) MarshalYAML

func (s MaporColonSlice) MarshalYAML() (value interface{}, err error)

MarshalYAML implements the Marshaller interface.

func (*MaporColonSlice) Slice

func (s *MaporColonSlice) Slice() []string

Slice gets the parts of the MaporColonSlice as a Slice of string.

func (*MaporColonSlice) UnmarshalYAML

func (s *MaporColonSlice) UnmarshalYAML(unmarshal func(value interface{}) error) error

UnmarshalYAML implements the Unmarshaller interface.

type MaporEqualSlice

type MaporEqualSlice struct {
	// contains filtered or unexported fields
}

MaporEqualSlice represents a slice of strings that gets unmarshal from a YAML map into 'key=value' string.

func NewMaporEqualSlice

func NewMaporEqualSlice(parts []string) MaporEqualSlice

NewMaporEqualSlice creates a new MaporEqualSlice based on the specified parts.

func (MaporEqualSlice) MarshalYAML

func (s MaporEqualSlice) MarshalYAML() (value interface{}, err error)

MarshalYAML implements the Marshaller interface.

func (*MaporEqualSlice) Slice

func (s *MaporEqualSlice) Slice() []string

Slice gets the parts of the MaporEqualSlice as a Slice of string.

func (*MaporEqualSlice) UnmarshalYAML

func (s *MaporEqualSlice) UnmarshalYAML(unmarshal func(value interface{}) error) error

UnmarshalYAML implements the Unmarshaller interface.

type MaporSpaceSlice

type MaporSpaceSlice struct {
	// contains filtered or unexported fields
}

MaporSpaceSlice represents a slice of strings that gets unmarshal from a YAML map into 'key value' string.

func NewMaporSpaceSlice

func NewMaporSpaceSlice(parts []string) MaporSpaceSlice

NewMaporSpaceSlice creates a new MaporSpaceSlice based on the specified parts.

func (MaporSpaceSlice) MarshalYAML

func (s MaporSpaceSlice) MarshalYAML() (tag string, value interface{}, err error)

MarshalYAML implements the Marshaller interface.

func (*MaporSpaceSlice) Slice

func (s *MaporSpaceSlice) Slice() []string

Slice gets the parts of the MaporSpaceSlice as a Slice of string.

func (*MaporSpaceSlice) UnmarshalYAML

func (s *MaporSpaceSlice) UnmarshalYAML(unmarshal func(value interface{}) error) error

UnmarshalYAML implements the Unmarshaller interface.

type OsEnvLookup

type OsEnvLookup struct {
}

OsEnvLookup is a "bare" structure that implements the EnvironmentLookup interface

func (*OsEnvLookup) Lookup

func (o *OsEnvLookup) Lookup(key, serviceName string, config *ServiceConfig) []string

Lookup creates a string slice of string containing a "docker-friendly" environment string in the form of 'key=value'. It gets environment values using os.Getenv. If the os environment variable does not exists, the slice is empty. serviceName and config are not used at all in this implementation.

type Project

type Project struct {
	Name           string
	Configs        map[string]*ServiceConfig
	Files          []string
	ReloadCallback func() error
	// contains filtered or unexported fields
}

Project holds libcompose project information.

func NewProject

func NewProject(context *Context) *Project

NewProject create a new project with the specified context.

func (*Project) AddConfig

func (p *Project) AddConfig(name string, config *ServiceConfig) error

AddConfig adds the specified service config for the specified name.

func (*Project) CreateService

func (p *Project) CreateService(name string) (Service, error)

CreateService creates a service with the specified name based. It there is no config in the project for this service, it will return an error.

func (*Project) Load

func (p *Project) Load(bytes []byte) error

Load loads the specified byte array (the composefile content) and adds the service configuration to the project. FIXME is it needed ?

func (*Project) Parse

func (p *Project) Parse() error

Parse populates project information based on its context. It sets up the name, the composefile and the composebytes (the composefile content).

type ResourceLookup

type ResourceLookup interface {
	Lookup(file, relativeTo string) ([]byte, string, error)
	ResolvePath(path, inFile string) string
}

ResourceLookup defines methods to provides file loading.

type Service

type Service interface {
	Info(qFlag bool) (InfoSet, error)
	Name() string
	Build() error
	Create() error
	Up() error
	Start() error
	Down() error
	Delete() error
	Restart() error
	Log() error
	Pull() error
	Kill() error
	Config() *ServiceConfig
	DependentServices() []ServiceRelationship
	Containers() ([]Container, error)
	Scale(count int) error
	Pause() error
	Unpause() error
}

Service defines what a libcompose service provides.

type ServiceConfig

type ServiceConfig struct {
	Build         string            `yaml:"build,omitempty"`
	CapAdd        []string          `yaml:"cap_add,omitempty"`
	CapDrop       []string          `yaml:"cap_drop,omitempty"`
	CgroupParent  string            `yaml:"cgroup_parent,omitempty"`
	CPUQuota      int64             `yaml:"cpu_quota,omitempty"`
	CPUSet        string            `yaml:"cpuset,omitempty"`
	CPUShares     int64             `yaml:"cpu_shares,omitempty"`
	Command       Command           `yaml:"command,flow,omitempty"`
	ContainerName string            `yaml:"container_name,omitempty"`
	Devices       []string          `yaml:"devices,omitempty"`
	DNS           Stringorslice     `yaml:"dns,omitempty"`
	DNSSearch     Stringorslice     `yaml:"dns_search,omitempty"`
	Dockerfile    string            `yaml:"dockerfile,omitempty"`
	DomainName    string            `yaml:"domainname,omitempty"`
	Entrypoint    Command           `yaml:"entrypoint,flow,omitempty"`
	EnvFile       Stringorslice     `yaml:"env_file,omitempty"`
	Environment   MaporEqualSlice   `yaml:"environment,omitempty"`
	Hostname      string            `yaml:"hostname,omitempty"`
	Image         string            `yaml:"image,omitempty"`
	Labels        SliceorMap        `yaml:"labels,omitempty"`
	Links         MaporColonSlice   `yaml:"links,omitempty"`
	LogDriver     string            `yaml:"log_driver,omitempty"`
	MacAddress    string            `yaml:"mac_address,omitempty"`
	MemLimit      int64             `yaml:"mem_limit,omitempty"`
	MemSwapLimit  int64             `yaml:"memswap_limit,omitempty"`
	Name          string            `yaml:"name,omitempty"`
	Net           string            `yaml:"net,omitempty"`
	Pid           string            `yaml:"pid,omitempty"`
	Uts           string            `yaml:"uts,omitempty"`
	Ipc           string            `yaml:"ipc,omitempty"`
	Ports         []string          `yaml:"ports,omitempty"`
	Privileged    bool              `yaml:"privileged,omitempty"`
	Restart       string            `yaml:"restart,omitempty"`
	ReadOnly      bool              `yaml:"read_only,omitempty"`
	StdinOpen     bool              `yaml:"stdin_open,omitempty"`
	SecurityOpt   []string          `yaml:"security_opt,omitempty"`
	Tty           bool              `yaml:"tty,omitempty"`
	User          string            `yaml:"user,omitempty"`
	VolumeDriver  string            `yaml:"volume_driver,omitempty"`
	Volumes       []string          `yaml:"volumes,omitempty"`
	VolumesFrom   []string          `yaml:"volumes_from,omitempty"`
	WorkingDir    string            `yaml:"working_dir,omitempty"`
	Expose        []string          `yaml:"expose,omitempty"`
	ExternalLinks []string          `yaml:"external_links,omitempty"`
	LogOpt        map[string]string `yaml:"log_opt,omitempty"`
	ExtraHosts    []string          `yaml:"extra_hosts,omitempty"`
	Ulimits       Ulimits           `yaml:"ulimits,omitempty"`
}

ServiceConfig holds libcompose service configuration

type ServiceFactory

type ServiceFactory interface {
	Create(project *Project, name string, serviceConfig *ServiceConfig) (Service, error)
}

ServiceFactory is an interface factory to create Service object for the specified project, with the specified name and service configuration.

type ServiceRelationship

type ServiceRelationship struct {
	Target, Alias string
	Type          ServiceRelationshipType
	Optional      bool
}

ServiceRelationship holds the relationship information between two services.

func DefaultDependentServices

func DefaultDependentServices(p *Project, s Service) []ServiceRelationship

DefaultDependentServices return the dependent services (as an array of ServiceRelationship) for the specified project and service. It looks for : links, volumesFrom, net and ipc configuration.

func NewServiceRelationship

func NewServiceRelationship(nameAlias string, relType ServiceRelationshipType) ServiceRelationship

NewServiceRelationship creates a new Relationship based on the specified alias and relationship type.

type ServiceRelationshipType

type ServiceRelationshipType string

ServiceRelationshipType defines the type of service relationship.

type ServiceState

type ServiceState string

ServiceState holds the state of a service.

type SliceorMap

type SliceorMap struct {
	// contains filtered or unexported fields
}

SliceorMap represents a slice or a map of strings.

func NewSliceorMap

func NewSliceorMap(parts map[string]string) SliceorMap

NewSliceorMap creates a new SliceorMap based on the specified parts (as map of string).

func (*SliceorMap) MapParts

func (s *SliceorMap) MapParts() map[string]string

MapParts get the parts of the SliceorMap as a Map of string.

func (SliceorMap) MarshalYAML

func (s SliceorMap) MarshalYAML() (value interface{}, err error)

MarshalYAML implements the Marshaller interface.

func (*SliceorMap) UnmarshalYAML

func (s *SliceorMap) UnmarshalYAML(unmarshal func(value interface{}) error) error

UnmarshalYAML implements the Unmarshaller interface.

type Stringorslice

type Stringorslice struct {
	// contains filtered or unexported fields
}

Stringorslice represents a string or an array of strings. TODO use docker/docker/pkg/stringutils.StrSlice once 1.9.x is released.

func NewStringorslice

func NewStringorslice(parts ...string) Stringorslice

NewStringorslice creates an Stringorslice based on the specified parts (as strings).

func (*Stringorslice) Len

func (s *Stringorslice) Len() int

Len returns the number of parts of the Stringorslice.

func (Stringorslice) MarshalYAML

func (s Stringorslice) MarshalYAML() (value interface{}, err error)

MarshalYAML implements the Marshaller interface.

func (*Stringorslice) Slice

func (s *Stringorslice) Slice() []string

Slice gets the parts of the StrSlice as a Slice of string.

func (*Stringorslice) UnmarshalYAML

func (s *Stringorslice) UnmarshalYAML(unmarshal func(value interface{}) error) error

UnmarshalYAML implements the Unmarshaller interface.

type Ulimit

type Ulimit struct {
	Name string
	// contains filtered or unexported fields
}

Ulimit represent ulimit inforation.

func (Ulimit) MarshalYAML

func (u Ulimit) MarshalYAML() (value interface{}, err error)

MarshalYAML implements the Marshaller interface.

type Ulimits

type Ulimits struct {
	Elements []Ulimit
}

Ulimits represent a list of Ulimit. It is, however, represented in yaml as keys (and thus map in Go)

func (Ulimits) MarshalYAML

func (u Ulimits) MarshalYAML() (value interface{}, err error)

MarshalYAML implements the Marshaller interface.

func (*Ulimits) UnmarshalYAML

func (u *Ulimits) UnmarshalYAML(unmarshal func(value interface{}) error) error

UnmarshalYAML implements the Unmarshaller interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL