Skip to content
This repository was archived by the owner on Dec 20, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions config/GantryConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ class _EnvironmentVariable(CFObject):
def __init__(self):
super(_EnvironmentVariable, self).__init__('Environment Variable')

class _RestartPolicy(CFObject):
""" A network link required by a component. """
name = CFField('name').name_field()
alias = CFField('maximumRetryCount').value_field()

def __init__(self):
super(_RestartPolicy, self).__init__('Restart Policy')


class _Component(CFObject):
""" A single gantry component. """
Expand All @@ -116,6 +124,7 @@ class _Component(CFObject):
defined_component_links = CFField('defineComponentLinks').list_of(_DefinedComponentLink).default([])
required_component_links = CFField('requireComponentLinks').list_of(_RequiredComponentLink).default([])
environment_variables = CFField('environmentVariables').list_of(_EnvironmentVariable).default([])
restart_policy = CFField('restartPolicy').kind(dict).default({})

connection_check = _HealthCheck().build({'kind': 'connection'})
termination_checks = CFField('terminationChecks').list_of(_HealthCheck).default([connection_check])
Expand All @@ -134,6 +143,13 @@ def getUser(self):

return self.user

def getRestartPolicy(self):
""" Returns the host config. """
if not self.restart_policy:
return None

return self.restart_policy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could do return self.restart_policy or None if you want to shortcut


def getCommand(self):
""" Returns the command string to run on component startup or None if none. """
if not self.command:
Expand Down Expand Up @@ -167,7 +183,7 @@ def getDefinedComponentLinks(self):
def getComponentLinks(self):
""" Returns a dict of aliases for component links required, with the values being the links' names. """
return {l.alias: l.name for l in self.required_component_links}

def getEnvironmentVariables(self):
""" Returns a dict of the defined environments variables and their values. """
return {v.name: v.value for v in self.environment_variables}
Expand All @@ -186,4 +202,4 @@ def lookupComponent(self, name):
if component.name == name:
return component

return None
return None
21 changes: 12 additions & 9 deletions runtime/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ def __init__(self, manager, config):

# The underlying config for the component.
self.config = config

def applyConfigOverrides(self, config_overrides):
""" Applies the list of configuration overrides to this component's config.

Format: ['Name=Value', 'Name.SubName=Value']
"""
for override in config_overrides:
self.config.applyOverride(override)

def getName(self):
""" Returns the name of the component. """
return self.config.name
Expand Down Expand Up @@ -223,9 +223,7 @@ def start(self):
if self.config.privileged:
report('Container will be run in privileged mode', component=self)

client.start(container, binds=self.config.getBindings(container['Id']),
volumes_from=self.config.volumes_from,
privileged=self.config.privileged)
client.start(container)

# Health check until the instance is ready.
report('Waiting for health checks...', component=self)
Expand Down Expand Up @@ -309,12 +307,17 @@ def createContainer(self, client):

self.logger.debug('Starting container for component %s with command %s', self.getName(),
command)

container = client.create_container(self.config.getFullImage(), command,
user=self.config.getUser(),
volumes=self.config.getVolumes(),
ports=[str(p) for p in self.config.getContainerPorts()],
environment=self.calculateEnvForComponent())
environment=self.calculateEnvForComponent(),
host_config=client.create_host_config(restart_policy=self.config.getRestartPolicy(),
volumes_from=self.config.volumes_from,
binds={ b.external: { "bind": b.volume } for b in self.config.bindings },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is quite long; maybe breakout the dict construction into its own variable above?

privileged=self.config.privileged
)
)

return container

Expand Down