gufo.thor.services.base¶
BaseService definition.
Attributes:
Name | Type | Description |
---|---|---|
loader |
Loader[BaseService]
|
The service loader. |
BaseService
¶
Bases: ABC
Base class for the service declaration.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Service name |
is_noc |
bool
|
True, if the service is belongs to NOC |
dependencies |
Optional[Tuple[BaseService, ...]]
|
Optional list of dependencies |
compose_image |
str
|
docker image name. Override |
compose_depends_condition |
ComposeDependsCondition
|
Condition for all dependend
services. Override |
compose_healthcheck |
Optional[Dict[str, Any]]
|
Healtcheck section, if any.
Override |
compose_command |
Optional[str]
|
|
compose_entrypoint |
Optional[str]
|
|
compose_working_dir |
Optional[str]
|
|
compose_volumes |
Optional[List[str]]
|
|
compose_volumes_config |
Optional[Dict[str, Dict[str, Any]]]
|
Global |
compose_environment |
Optional[Dict[str, str]]
|
|
compose_extra |
Optional[Dict[str, Any]]
|
Additional parameters to be merged
with the compose config.
Override |
service_discovery |
Optional[Dict[str, Union[int, Dict[str, Any]]]]
|
Optional name -> port mappings.
Override |
allow_scale |
bool
|
If the service allows running multiple instances. |
require_slots |
bool
|
If the service requires slots creation. |
expose_http_prefix |
Optional[str]
|
Optional prefix to be exposed on edge proxy.
Override |
require_http_auth |
bool
|
True, if the service protected by http auth proxy. |
rewrite_http_prefix |
Optional[str]
|
If set, rewrite matched http prefix before passing request to upstream. |
get_compose_command(config, svc)
¶
Get docker-compose.yml command
section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
Command, if not empty |
get_compose_config(config, svc)
¶
Generate config for docker-compose target.
The following functions are used to build config:
get_compose_image
-vto buildimage
section.iter_dependencies
- to builddepends_on
section.get_compose_working_dir
- to buildworking_dir
section.get_compose_command
- to buildcommand
section.get_compose_entrypoint
- to buildentrypoint
section.get_compose_volumes
- to buildvolumes
section.get_compose_networks
- to buildnetworks
section.get_compose_ports
- to buildports
section.get_compose_environment
- to buildenvironments
section.get_compose_healthcheck
- to buildhealthcheck
section.get_compose_extra
to add the extra parameters to the result.get_compose_logging
- to buildlogging
section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
dict of the docker-compose configuration. |
get_compose_depends_condition(config, svc)
¶
Get condition for all dependend services.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
Returns:
Type | Description |
---|---|
ComposeDependsCondition
|
Dependency start condition. |
get_compose_entrypoint(config, svc)
¶
Get docker-compose.yml entrypoint
section.
Args:
config: Gufo Thor config instance
svc: Service's config from services
part, if any.
Returns: Entrypoint, if not empty
get_compose_environment(config, svc)
¶
Get docker-compose.yml environment
section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
Returns:
Type | Description |
---|---|
Optional[Dict[str, str]]
|
Dict of environment, if not empty |
get_compose_extra(config, svc)
¶
Get dict to be merged with compose config/.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
Returns:
Type | Description |
---|---|
Optional[Dict[str, Any]]
|
Dict of extra settings. |
get_compose_healthcheck(config, svc)
¶
Get docker-compose.yml healthcheck
section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
Returns:
Type | Description |
---|---|
Optional[Dict[str, Any]]
|
Dict of healthcheck, if not empty |
get_compose_image(config, svc)
¶
Get docker-compose.yml image
section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
Returns:
Type | Description |
---|---|
str
|
Image name. |
get_compose_logging(config, svc)
¶
Get docker-compose.yml logging
section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
Returns:
Type | Description |
---|---|
Optional[Dict[str, Any]]
|
Dict of logging, if not empty |
get_compose_networks(config, svc)
¶
Get docker-compose.yml networks
section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
Returns:
Type | Description |
---|---|
Optional[Dict[str, Any]]
|
Networks dict, if not empty |
get_compose_ports(config, svc)
¶
Get docker-compose.yml ports
section.
Args:
config: Gufo Thor config instance
svc: Service's config from services
part, if any.
Returns: List of ports config, if not empty
get_compose_volumes(config, svc)
¶
Get docker-compose.yml volumes
section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
Returns:
Type | Description |
---|---|
Optional[List[str]]
|
List of volumes config, if not empty. |
get_compose_volumes_config(config, svc)
¶
Get docker-compose.yml global volumes
section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
Returns:
Type | Description |
---|---|
Optional[Dict[str, Dict[str, Any]]]
|
Dict of name -> volumes config |
get_compose_working_dir(config, svc)
¶
Get docker-compose.yml working_dir
section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
Working dir, if not empty |
get_deps_dot()
staticmethod
¶
Build dependencies graph in dot format.
Returns:
Type | Description |
---|---|
str
|
Dependencies graph. |
get_expose_http_prefix(config, svc)
¶
Iterate over exposed http paths.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
get_service_discovery(config, svc)
¶
Get name to port mappings for service discovery.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
Returns:
Type | Description |
---|---|
Optional[Dict[str, Union[int, Dict[str, Any]]]]
|
Service name -> port mappings |
iter_dependencies()
¶
Iterator yielding the name of dependencies.
Returns:
Type | Description |
---|---|
Iterable[BaseService]
|
An iterable of strings which represent the names dependencies. |
prepare_compose_config(config, svc, services)
¶
Prepare service configs.
Called after the get_compose_dirs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
Gufo Thor config instance |
required |
svc |
Optional[ServiceConfig]
|
Service's config from |
required |
services |
List[BaseService]
|
List of all services. |
required |
render_file(path, tpl, **kwargs)
classmethod
¶
Apply a context to the template and write to file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
File path |
required |
tpl |
str
|
Template name (relative to |
required |
kwargs |
Union[str, int, List[Any]]
|
Template context |
{}
|
resolve(services)
staticmethod
¶
Resolve services to all dependencies.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
services |
Iterable[str]
|
Iterable of basic services. |
required |
Returns:
Type | Description |
---|---|
List[BaseService]
|
Iterable of all basic services and their dependencies. |
ComposeDependsCondition
¶
Bases: Enum
depends_on condition.
Attributes:
Name | Type | Description |
---|---|---|
STARTED |
Run dependends after the service is started. |
|
HEALTHY |
Run dependends after the service is started and entered the healhy state. |
|
COMPLETED_SUCCESSFULLY |
Run dependends after the service is started and terminated successfully. |