diff --git a/pyouroboros/config.py b/pyouroboros/config.py index f46d7921..73610292 100644 --- a/pyouroboros/config.py +++ b/pyouroboros/config.py @@ -8,7 +8,7 @@ class Config(object): 'PROMETHEUS_PORT', 'NOTIFIERS', 'REPO_USER', 'REPO_PASS', 'CLEANUP', 'RUN_ONCE', 'LATEST', 'CRON', 'INFLUX_URL', 'INFLUX_PORT', 'INFLUX_USERNAME', 'INFLUX_PASSWORD', 'INFLUX_DATABASE', 'INFLUX_SSL', 'INFLUX_VERIFY_SSL', 'DATA_EXPORT', 'SELF_UPDATE', 'LABEL_ENABLE', 'DOCKER_TLS', 'LABELS_ONLY', - 'DRY_RUN', 'HOSTNAME', 'DOCKER_TLS_VERIFY', 'SWARM'] + 'DRY_RUN', 'HOSTNAME', 'DOCKER_TLS_VERIFY', 'SWARM', 'IMAGE_TAG'] hostname = environ.get('HOSTNAME') interval = 300 @@ -22,6 +22,7 @@ class Config(object): data_export = None log_level = 'info' latest = False + image_tag = None cleanup = False run_once = False dry_run = False @@ -112,6 +113,9 @@ def parse(self): if self.interval < 30: self.interval = 30 + + if self.latest: + self.image_tag = 'latest' for option in ['docker_sockets', 'notifiers', 'monitor', 'ignore']: if isinstance(getattr(self, option), str): diff --git a/pyouroboros/dockerclient.py b/pyouroboros/dockerclient.py index d9f00874..dbfe7a35 100644 --- a/pyouroboros/dockerclient.py +++ b/pyouroboros/dockerclient.py @@ -76,17 +76,15 @@ def pull(self, image_object): except IndexError: self.logger.error('Malformed or missing tag. Skipping...') raise ConnectionError - if self.config.latest and image.tags[0][-6:] != 'latest': + + if self.config.image_tag: if ':' in tag: - split_tag = tag.split(':') - if len(split_tag) == 2: - if '/' not in split_tag[1]: - tag = split_tag[0] - else: - tag = ':'.join(split_tag[:-1]) - tag = f'{tag}:latest' + split_tag = tag.rpartition(':') + if '/' not in split_tag[2]: + tag = split_tag[0] + tag = f'{tag}:{self.config.image_tag}' - self.logger.debug('Checking tag: %s', tag) + self.logger.debug('Pulling tag: %s', tag) try: if self.config.dry_run: registry_data = self.client.images.get_registry_data(tag) @@ -103,17 +101,17 @@ def pull(self, image_object): raise ConnectionError elif 'unauthorized' in str(e): if self.config.dry_run: - self.logger.error('dry run : Upstream authentication issue while checking %s. See: ' + self.logger.error('Dry run: Upstream authentication issue while checking %s. See: ' 'https://github.com/docker/docker-py/issues/2225', tag) raise ConnectionError else: self.logger.critical("Invalid Credentials. Exiting") exit(1) elif 'Client.Timeout' in str(e): - self.logger.critical("Couldn't find an image on docker.com for %s. Local Build?", image.tags[0]) + self.logger.critical("Couldn't find an image on docker.com for %s. Local Build?", tag) raise ConnectionError - elif ('pull access' or 'TLS handshake') in str(e): - self.logger.critical("Couldn't pull. Skipping. Error: %s", e) + else: + self.logger.critical("Couldn't pull image %s. Skipping. Error: %s", tag, e) raise ConnectionError def get_running(self): @@ -185,13 +183,14 @@ def update(self): try: latest_image = self.pull(current_image) except ConnectionError: + self.logger.error('Ignoring container %s due to connection error while pulling', container.name) continue if self.config.dry_run: # Ugly hack for repo digest repo_digest_id = current_image.attrs['RepoDigests'][0].split('@')[1] if repo_digest_id != latest_image.id: - self.logger.info('dry run : %s would be updated', container.name) + self.logger.info('Dry run: %s would be updated', container.name) continue # If current running container is running latest image diff --git a/pyouroboros/ouroboros.py b/pyouroboros/ouroboros.py index 53439a94..8ec23a2d 100644 --- a/pyouroboros/ouroboros.py +++ b/pyouroboros/ouroboros.py @@ -89,6 +89,9 @@ def main(): docker_group.add_argument('-L', '--latest', default=Config.latest, dest='LATEST', action='store_true', help='Check for latest image instead of pulling current tag') + docker_group.add_argument('-g', '--image-tag', default=Config.image_tag, dest='IMAGE_TAG', + help='Check for specified tag, regardless of what is being used') + docker_group.add_argument('-r', '--repo-user', default=Config.repo_user, dest='REPO_USER', help='Private docker registry username\n' 'EXAMPLE: foo@bar.baz')