This commit is contained in:
Jerome Petazzoni
2015-06-08 11:22:02 -07:00
parent 60773bf68f
commit 8ff8407f8c
2 changed files with 15 additions and 12 deletions

5
dockercoins/ports.yml Normal file
View File

@@ -0,0 +1,5 @@
hasher: 80
redis: 6379
rng: 80
webui: 80

View File

@@ -9,28 +9,26 @@ stack = yaml.load(open(input_file))
# The ambassadors need to know the service port to use.
# Those ports must be declared here.
ports = dict(
redis=6379,
rng=80,
hasher=80,
)
ports = yaml.load(open("ports.yml"))
# Links are stored as {from: [to, to, ...]}.
links = {}
def generate_local_addr():
last_byte = 2
while last_byte<255:
yield "127.0.0.{}".format(last_byte)
last_byte += 1
# First, collect all links.
for service_name, service in stack.items():
if "links" in service:
for link in service["links"]:
for link, local_addr in zip(service["links"], generate_local_addr()):
if link not in ports:
print("Skipping link {} in service {} "
"(no port mapping defined). "
"Your code will probably break."
.format(link, service_name))
continue
if service_name not in links:
links[service_name] = []
links[service_name].append(link)
if "extra_hosts" not in service:
service["extra_hosts"] = {}
service["extra_hosts"][link] = local_addr
del service["links"]
if "ports" in service:
del service["ports"]