Skip to content

Commit 9dfd73d

Browse files
author
set
committed
Use swag_url label to construct default container urls, if available
1 parent 36e04cf commit 9dfd73d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

root/app/swag-ondemand.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ def init_docker(self):
3737
def process_containers(self):
3838
containers = self.docker_client.containers.list(all=True, filters={ "label": ["swag_ondemand=enable"] })
3939
container_names = {container.name for container in containers}
40-
40+
4141
for container_name in list(self.ondemand_containers.keys()):
4242
if container_name in container_names:
4343
continue
4444
self.ondemand_containers.pop(container_name)
4545
logging.info(f"Stopped monitoring {container_name}")
46-
46+
4747
for container in containers:
48-
container_urls = container.labels.get("swag_ondemand_urls", f"https://{container.name}.,http://{container.name}.")
48+
default_url = container.labels.get("swag_url", f"{container.name}.").rstrip("*")
49+
container_urls = container.labels.get("swag_ondemand_urls", f"https://{default_url},http://{default_url}")
4950
if container.name not in self.ondemand_containers.keys():
5051
last_accessed = datetime.now()
5152
logging.info(f"Started monitoring {container.name}")
@@ -62,12 +63,12 @@ def stop_containers(self):
6263
continue
6364
self.docker_client.containers.get(container_name).stop()
6465
logging.info(f"Stopped {container_name} after {STOP_THRESHOLD}s of inactivity")
65-
66+
6667
def start_containers(self):
6768
with last_accessed_urls_lock:
6869
last_accessed_urls_combined = ",".join(last_accessed_urls)
6970
last_accessed_urls.clear()
70-
71+
7172
for container_name in self.ondemand_containers.keys():
7273
accessed = False
7374
for ondemand_url in self.ondemand_containers[container_name]["urls"].split(","):
@@ -95,7 +96,7 @@ class LogReaderThread(threading.Thread):
9596
def __init__(self):
9697
super().__init__()
9798
self.daemon = True
98-
99+
99100
def tail(self, f):
100101
f.seek(0,2)
101102
inode = os.fstat(f.fileno()).st_ino
@@ -143,6 +144,6 @@ def run(self):
143144

144145
ContainerThread().start()
145146
LogReaderThread().start()
146-
147+
147148
while True:
148149
time.sleep(1)

0 commit comments

Comments
 (0)