Skip to content

Commit c8efffd

Browse files
author
Gabriel Monroy
committed
fix(announcer): detect first exposed port instead of hardcoding to 5000/tcp
1 parent 730149c commit c8efffd

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

controller/scheduler/coreos.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,33 @@ def tearDown(self):
4848

4949
# job api
5050

51-
def create(self, name, image, command='', template=None, port=5000):
51+
def create(self, name, image, command='', template=None):
5252
"""
5353
Create a new job
5454
"""
5555
print 'Creating {name}'.format(**locals())
5656
env = self.env.copy()
57-
self._create_container(name, image, command, template or CONTAINER_TEMPLATE, env, port)
58-
self._create_log(name, image, command, LOG_TEMPLATE, env, port)
59-
self._create_announcer(name, image, command, ANNOUNCE_TEMPLATE, env, port)
57+
self._create_container(name, image, command, template or CONTAINER_TEMPLATE, env)
58+
self._create_log(name, image, command, LOG_TEMPLATE, env)
59+
self._create_announcer(name, image, command, ANNOUNCE_TEMPLATE, env)
6060

61-
# TODO: remove hardcoded ports
62-
63-
def _create_container(self, name, image, command, template, env, port):
61+
def _create_container(self, name, image, command, template, env):
6462
l = locals().copy()
6563
l.update(re.match(MATCH, name).groupdict())
6664
env.update({'FLEETW_UNIT': name + '.service'})
6765
env.update({'FLEETW_UNIT_DATA': base64.b64encode(template.format(**l))})
6866
return subprocess.check_call('fleetctl.sh submit {name}.service'.format(**l),
6967
shell=True, env=env)
7068

71-
def _create_announcer(self, name, image, command, template, env, port):
69+
def _create_announcer(self, name, image, command, template, env):
7270
l = locals().copy()
7371
l.update(re.match(MATCH, name).groupdict())
7472
env.update({'FLEETW_UNIT': name + '-announce' + '.service'})
7573
env.update({'FLEETW_UNIT_DATA': base64.b64encode(template.format(**l))})
7674
return subprocess.check_call('fleetctl.sh submit {name}-announce.service'.format(**l), # noqa
7775
shell=True, env=env)
7876

79-
def _create_log(self, name, image, command, template, env, port):
77+
def _create_log(self, name, image, command, template, env):
8078
l = locals().copy()
8179
l.update(re.match(MATCH, name).groupdict())
8280
env.update({'FLEETW_UNIT': name + '-log' + '.service'})
@@ -199,7 +197,7 @@ def attach(self, name):
199197
[Service]
200198
ExecStartPre=/usr/bin/docker pull {image}
201199
ExecStartPre=/bin/sh -c "docker inspect {name} >/dev/null 2>&1 && docker rm -f {name} || true"
202-
ExecStart=/usr/bin/docker run --name {name} -P -e PORT={port} {image} {command}
200+
ExecStart=/usr/bin/docker run --name {name} -P {image} {command}
203201
ExecStartPost=/bin/sh -c "until docker inspect {name} >/dev/null 2>&1; do sleep 1; done"; \
204202
/bin/sh -c "arping -Idocker0 -c1 `docker inspect -f '{{{{ .NetworkSettings.IPAddress }}}}' {name}`"
205203
ExecStop=/usr/bin/docker rm -f {name}
@@ -212,8 +210,8 @@ def attach(self, name):
212210
213211
[Service]
214212
EnvironmentFile=/etc/environment
215-
ExecStartPre=/bin/sh -c "until /usr/bin/docker port {name} {port} >/dev/null 2>&1; do sleep 2; done; port=$(docker port {name} {port} | cut -d ':' -f2); echo Waiting for $port/tcp...; until netstat -lnt | grep :$port >/dev/null; do sleep 1; done"
216-
ExecStart=/bin/sh -c "port=$(docker port {name} {port} | cut -d ':' -f2); echo Connected to $COREOS_PRIVATE_IPV4:$port/tcp, publishing to etcd...; while netstat -lnt | grep :$port >/dev/null; do etcdctl set /deis/services/{app}/{name} $COREOS_PRIVATE_IPV4:$port --ttl 60 >/dev/null; sleep 45; done"
213+
ExecStartPre=/bin/sh -c "until docker inspect -f '{{{{range $i, $e := .HostConfig.PortBindings }}}}{{{{$p := index $e 0}}}}{{{{$p.HostPort}}}}{{{{end}}}}' {name} >/dev/null 2>&1; do sleep 2; done; port=$(docker inspect -f '{{{{range $i, $e := .HostConfig.PortBindings }}}}{{{{$p := index $e 0}}}}{{{{$p.HostPort}}}}{{{{end}}}}' {name}); echo Waiting for $port/tcp...; until netstat -lnt | grep :$port >/dev/null; do sleep 1; done"
214+
ExecStart=/bin/sh -c "port=$(docker inspect -f '{{{{range $i, $e := .HostConfig.PortBindings }}}}{{{{$p := index $e 0}}}}{{{{$p.HostPort}}}}{{{{end}}}}' {name}); echo Connected to $COREOS_PRIVATE_IPV4:$port/tcp, publishing to etcd...; while netstat -lnt | grep :$port >/dev/null; do etcdctl set /deis/services/{app}/{name} $COREOS_PRIVATE_IPV4:$port --ttl 60 >/dev/null; sleep 45; done"
217215
ExecStop=/usr/bin/etcdctl rm --recursive /deis/services/{app}/{name}
218216
219217
[X-Fleet]

0 commit comments

Comments
 (0)