Files
portainer_updater/main.py
2023-09-21 16:55:28 +02:00

32 lines
785 B
Python

import os
import requests
import config
DOCKER_COMPOSE_PATH = '/srv/docker/portainer/portainer-data/compose/{}/docker-compose.yml'
CURRENT_DIR = os.path.dirname(__file__)
BASH_COMPANION_SCRIPT = CURRENT_DIR + '/docker_updater.sh'
def update_stack(stack):
project_name = stack['Name']
compose_file = DOCKER_COMPOSE_PATH.format(stack['Id'])
os.system(f"{BASH_COMPANION_SCRIPT} {project_name} {compose_file}")
if __name__ == '__main__':
headers = {
"accept": "application/json",
"X-API-Key": config.access_token
}
api_url = "https://portainer.dorfsvald.net/api/stacks"
response = requests.get(api_url, headers=headers)
stack_list = response.json()
for s in stack_list:
if s['Status'] == 1:
update_stack(s)