diff --git a/.gitignore b/.gitignore index bb06055..0854edf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ gantry.xml venv haproxy.conf .gantry_metadata +.*.sw[opn] diff --git a/README.md b/README.md index 3f91e4a..673f6cd 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,10 @@ The configuration defines the various components of the project you want to mana "bindings": [ { "external": "/an/external/path", "volume": "/some/container/path"} ], + "dnsServers": [ + "8.8.8.8", + "8.8.4.4" + ], "defineComponentLinks": [ { "port": 8888, "name": "mycoolserver", "kind": "tcp" } ], @@ -102,6 +106,7 @@ The configuration defines the various components of the project you want to mana | terminationChecks | The various checks to run to ensure that the container is ready to be shut down | connections | | volumesFrom | Container(s), by name, whose volume(s) should be mounted into the container | | | bindings | Mapping between external hosts paths and the corresponding container volumes | | +| dnsServers | The IP addresses to override nameserver lines in container's `/etc/resolv.conf` | | | defineComponentLinks | Defines the component links exported by this component | | | requireComponentLinks | Defines the component links imported/required by this component | | | readyTimeout | Timeout in milliseconds that we will wait for a container to pass a ready check | 10,000 | diff --git a/config/GantryConfig.py b/config/GantryConfig.py index 92244a1..f0bba98 100644 --- a/config/GantryConfig.py +++ b/config/GantryConfig.py @@ -107,6 +107,7 @@ class _Component(CFObject): user = CFField('user').default('') ports = CFField('ports').list_of(_PortMapping).default([]) bindings = CFField('bindings').list_of(_VolumeBinding).default([]) + dnsServers = CFField('dnsServers').list_of(str).default([]) volumes_from = CFField('volumesFrom').list_of(str).default([]) ready_checks = CFField('readyChecks').list_of(_HealthCheck).default([]) health_checks = CFField('healthChecks').list_of(_HealthCheck).default([]) @@ -186,4 +187,4 @@ def lookupComponent(self, name): if component.name == name: return component - return None \ No newline at end of file + return None diff --git a/runtime/component.py b/runtime/component.py index 7322c05..3e3781c 100644 --- a/runtime/component.py +++ b/runtime/component.py @@ -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=container.get('Id')) # Health check until the instance is ready. report('Waiting for health checks...', component=self) @@ -309,8 +307,22 @@ def createContainer(self, client): self.logger.debug('Starting container for component %s with command %s', self.getName(), command) - + + host_config = { + "privileged": self.config.privileged + } + + if self.config.dnsServers: + host_config['dns_servers'] = self.config.dnsServers + + if self.config.bindings: + host_config['binds'] = { b.external: { "bind": b.volume } for b in self.config.bindings } + + if self.config.volumes_from: + host_config['volumes_from'] = self.config.volumes_from + host_config = client.create_host_config(**host_config) container = client.create_container(self.config.getFullImage(), command, + host_config=host_config, user=self.config.getUser(), volumes=self.config.getVolumes(), ports=[str(p) for p in self.config.getContainerPorts()],