41 lines
977 B
Python
41 lines
977 B
Python
import os
|
|
|
|
import requests
|
|
|
|
import config
|
|
|
|
|
|
DOCKER_COMPOSE_PATH = config.portainer_compose_dir + '/{}/docker-compose.yml'
|
|
BASH_COMPANION_SCRIPT = os.getcwd() + '/docker_updater.sh'
|
|
REPO_UPDATER_SCRIPT = os.getcwd() + '/update_repo.sh'
|
|
|
|
|
|
def update_repositories():
|
|
for repo_path in config.git_repositories:
|
|
os.system(f"{REPO_UPDATER_SCRIPT} {repo_path}")
|
|
|
|
|
|
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__':
|
|
update_repositories()
|
|
|
|
headers = {
|
|
"accept": "application/json",
|
|
"X-API-Key": config.access_token
|
|
}
|
|
|
|
api_url = f"{config.portainer_url}/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)
|
|
|
|
os.system('docker image prune -fa')
|