import time from ConfigReader import ConfigReader from GitlabAPI import get_image_info from caching import Cacher from Exceptions import ErrorConnectingAPIException, ImageNotFoundException from Docker import refresh_image, restart_outdated_containers, restart_services, run_image_once, cleanup_exited_containers from Logger import Logger config_reader = ConfigReader() cacher = Cacher() registries = config_reader.get_registries() logger = Logger() def register_images(): for registry in registries: for image in registry['images']: image_info = get_image_info(registry['user'], registry['project'], image['tag'], registry['apiToken']) if image_info.get('error'): raise ErrorConnectingAPIException('Could not connect to API!') cacher.update_or_insert_image(image_info['path'], image_info['revision']) refresh_image(image_info['location']) restart_services(image_info['location']) restart_outdated_containers(image_info['location'], image_info['revision']) cleanup_exited_containers() logger.log_line( f'Registered and updated image {image_info["location"]}')