runtime

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddServiceToRuntime

func AddServiceToRuntime(c Runtime, r recipe.Service) error

AddServiceToRuntime helps to create new service in runtime based on a recipe.

func ApplyRecipeToRuntime

func ApplyRecipeToRuntime(c Runtime, r recipe.Recipe) error

ApplyRecipeToRuntime can add all services from recipe and modifies existing ones based on rules.

func ApplyRecipes

func ApplyRecipes(st recipe.Stack, rt Runtime, selector []string, instanceOverride int) error

ApplyRecipes can apply full recipes and other services (partial recipes) based on the selectors.

func InitFromRecipe

func InitFromRecipe(service Service, recipe recipe.Service) error

InitFromRecipe can fill standard fields of the service (flags, configs, ...) based on the recipe.

func Match

func Match(service Service, matcher recipe.Matcher) bool

Match checks if matcher selects the given service.

func ModifyFromRecipe

func ModifyFromRecipe(service Service, mod recipe.Modification) error

ModifyFromRecipe applies the modification defined by a recipe to a service.

func ModifyService

func ModifyService(stack recipe.Stack, rt Runtime, selectors []string, f func(service Service) error) error

ModifyService applies a function to all services based on selector.

func PortConvention

func PortConvention(instance ServiceInstance, portType string) (int, error)

PortConvention defines port numbers for any services.

func RemoveFlag

func RemoveFlag(command []string, s string) []string

RemoveFlag remove flags based on prefix.

func Render

func Render(r Runtime, serviceInstance ServiceInstance, original string) (string, error)

Render can resolve all the go templates in a string.

func SetFlag

func SetFlag(command []string, s string) []string

SetFlag adds OR modify existing flag set.

Types

type HostResolver

type HostResolver interface {
	GetHost(serviceInstance ServiceInstance, hostType string) string
}

HostResolver helps to find the right hostname (or ip) for a specific service.

type ManageableNetwork added in v1.2.1

type ManageableNetwork interface {
	AddNetwork(string) error
	RemoveNetwork(string) error
}

ManageableNetwork is the interface to configure docker networks.

type MockRuntime

type MockRuntime struct {
	Services []Service
}

MockRuntime is a runtime `implementation` for testing.

func NewMockRuntime

func NewMockRuntime() *MockRuntime

NewMockRuntime creates a runtime for testing.

func (*MockRuntime) AddService

func (m *MockRuntime) AddService(service recipe.Service) (Service, error)

AddService implements runtime.Runtime.

func (*MockRuntime) Get

func (m *MockRuntime) Get(serviceInstance ServiceInstance, name string) string

Get implements runtime.Runtime.

func (*MockRuntime) GetHost

func (m *MockRuntime) GetHost(serviceInstance ServiceInstance, hostType string) string

GetHost implements runtime.Runtime.

func (*MockRuntime) GetPort

func (m *MockRuntime) GetPort(serviceInstance ServiceInstance, portType string) PortMap

GetPort implements runtime.Runtime.

func (*MockRuntime) GetServices

func (m *MockRuntime) GetServices() []Service

GetServices implements runtime.Runtime.

func (*MockRuntime) Reload

func (m *MockRuntime) Reload(stack recipe.Stack) error

Reload implements runtime.Runtime.

func (*MockRuntime) Write

func (m *MockRuntime) Write() error

Write implements runtime.Runtime.

type MockService

type MockService struct {
	Identifier  ServiceInstance
	Image       string
	Persisted   []string
	Config      map[string]string
	Environment map[string]string
	Flag        []string
	Ports       map[int]int
	Label       []string
}

MockService is a service implementation for MockRuntime.

func NewMockService

func NewMockService(name string) *MockService

NewMockService can create a new mock service.

func (*MockService) AddConfig

func (m *MockService) AddConfig(key string, value string) error

AddConfig implements runtime.Service.

func (*MockService) AddEnvironment

func (m *MockService) AddEnvironment(key string, value string) error

AddEnvironment implements runtime.Service.

func (*MockService) AddFlag

func (m *MockService) AddFlag(flag string) error

AddFlag implements runtime.Service.

func (*MockService) AddPortForward

func (m *MockService) AddPortForward(portMap PortMap) error

AddPortForward implements runtime.Service.

func (*MockService) ChangeImage

func (m *MockService) ChangeImage(f func(string) string) error

ChangeImage implements runtime.Service.

func (*MockService) GetENV

func (m *MockService) GetENV() map[string]*string

GetENV implements runtime.Service.

func (*MockService) GetVolumes

func (m *MockService) GetVolumes() []VolumeMount

GetVolumes implements runtime.Service.

func (*MockService) ID

func (m *MockService) ID() ServiceInstance

ID implements runtime.Service.

func (*MockService) Labels

func (m *MockService) Labels() []string

Labels implements runtime.Service.

func (*MockService) Persist

func (m *MockService) Persist(dir string) error

Persist implements runtime.Service.

func (*MockService) RemoveFlag

func (m *MockService) RemoveFlag(flag string) error

RemoveFlag implements runtime.Service.

func (*MockService) RemovePortForward added in v1.2.0

func (m *MockService) RemovePortForward(portMap PortMap) error

RemovePortForward implements runtime.Service.

func (*MockService) UseFile

func (m *MockService) UseFile(path string, name string, data string) error

UseFile implements runtime.Service.

func (*MockService) UseFolder

func (m *MockService) UseFolder(path string, name string) error

UseFolder implements runtime.Service.

type PortMap

type PortMap struct {
	Internal int
	External int
	Protocol string
}

PortMap defines the internal and external ports to use when port forwarding.

type PortResolver

type PortResolver interface {
	GetPort(serviceInstance ServiceInstance, portType string) PortMap
}

PortResolver helps to find the right port number for a specific service.

type Runtime

type Runtime interface {
	HostResolver
	PortResolver
	VariableGetter

	// AddService creates and adds new service instance based on the recipe.
	AddService(recipe.Service) (Service, error)
	Write() error
	GetServices() []Service
	Reload(stack recipe.Stack) error
}

Runtime provides methods to read/write/modify any existing runtime definition (like compose/nomad/...)

type Service

type Service interface {

	// ID returns with the unique identifier (including index in case of multiple instances are added from a service)
	ID() ServiceInstance
	GetENV() map[string]*string
	GetVolumes() []VolumeMount

	// ChangeImage applies transformation to the container image
	ChangeImage(func(string) string) error

	// AddConfig adds / changes existing configuration. Use it instead of AddEnvironment to be more generic.
	AddConfig(key string, value string) error
	AddFlag(flag string) error
	RemoveFlag(flag string) error

	// AddEnvironment registers new environment variable to be used. For normal configs, use AddConfig to be more general.
	AddEnvironment(key string, value string) error

	AddPortForward(PortMap) error
	RemovePortForward(PortMap) error

	Persist(dir string) error
	Labels() []string

	UseFile(path string, name string, data string) error
	UseFolder(path string, name string) error
}

Service is the interface to modify any service.

type ServiceInstance

type ServiceInstance struct {
	Name     string
	Instance int
}

ServiceInstance is a unique identifier of a service instance.

func NewServiceInstance

func NewServiceInstance(name string, i int) ServiceInstance

NewServiceInstance creates the ID from name and instance identifier (number).

func ServiceInstanceFromIndexedName

func ServiceInstanceFromIndexedName(service string) ServiceInstance

ServiceInstanceFromIndexedName creates ID from string like 'storagenode0'.

func ServiceInstanceFromStr

func ServiceInstanceFromStr(service string) ServiceInstance

ServiceInstanceFromStr parses ServiceInstance from 'storagenode/2' like string expression.

func (ServiceInstance) String

func (i ServiceInstance) String() string

type VariableGetter

type VariableGetter interface {
	Get(serviceInstance ServiceInstance, name string) string
}

VariableGetter returns with any custom template variable.

type VolumeMount

type VolumeMount struct {
	MountType string
	Source    string
	Target    string
}

VolumeMount defines the type source and target fields when mounting a volume to the container.

Jump to

Keyboard shortcuts

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