Improving logging further
This commit is contained in:
14
main.py
14
main.py
@@ -102,23 +102,29 @@ if __name__ == '__main__':
|
|||||||
client = PortainerClient(portainer_url=config.portainer_url, access_token=config.access_token)
|
client = PortainerClient(portainer_url=config.portainer_url, access_token=config.access_token)
|
||||||
|
|
||||||
for stack in client.list_stacks():
|
for stack in client.list_stacks():
|
||||||
endpoint = stack['EndpointId']
|
|
||||||
stack_name = stack['Name']
|
|
||||||
if stack['Status'] == 1:
|
if stack['Status'] == 1:
|
||||||
|
endpoint = stack['EndpointId']
|
||||||
|
stack_name = stack['Name']
|
||||||
|
|
||||||
|
print(f"Checking {stack_name} for updates.")
|
||||||
|
|
||||||
containers = client.list_stack_containers(endpoint, stack_name)
|
containers = client.list_stack_containers(endpoint, stack_name)
|
||||||
|
|
||||||
an_image_was_updated = False
|
an_image_was_updated = False
|
||||||
for c in containers:
|
for c in containers:
|
||||||
this_image_was_updated = client.update_image(endpoint, c['Image'])
|
this_image_was_updated = client.update_image(endpoint, c['Image'])
|
||||||
if this_image_was_updated:
|
if this_image_was_updated:
|
||||||
print(f"{c['Image']} was updated")
|
print(f"{c['Image']} was updated.")
|
||||||
an_image_was_updated = True
|
an_image_was_updated = True
|
||||||
|
|
||||||
if an_image_was_updated:
|
if an_image_was_updated:
|
||||||
print(f"Restarting {stack_name}")
|
print(f"{stack_name} was updated. Restarting...")
|
||||||
if endpoint == 2 and stack_name in ('portainer', 'traefik'):
|
if endpoint == 2 and stack_name in ('portainer', 'traefik'):
|
||||||
update_local_stack(stack)
|
update_local_stack(stack)
|
||||||
else:
|
else:
|
||||||
client.upgrade_stack(stack)
|
client.upgrade_stack(stack)
|
||||||
|
print(f"{stack_name} restarted.")
|
||||||
|
else:
|
||||||
|
print(f"{stack_name} is up to date. Skipping.")
|
||||||
|
|
||||||
os.system('docker image prune -fa')
|
os.system('docker image prune -fa')
|
||||||
|
|||||||
Reference in New Issue
Block a user