Skip to content

Commit

Permalink
Merge pull request #205 from pyouroboros/patch/tag-bug
Browse files Browse the repository at this point in the history
Patch/tag bug
  • Loading branch information
dirtycajunrice authored Feb 14, 2019
2 parents ba63149 + 7c775e8 commit 95fedd7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
10 changes: 4 additions & 6 deletions pyouroboros/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Config(object):
options = ['INTERVAL', 'PROMETHEUS', 'DOCKER_SOCKETS', 'MONITOR', 'IGNORE', 'LOG_LEVEL', 'PROMETHEUS_ADDR',
'PROMETHEUS_PORT', 'NOTIFIERS', 'REPO_USER', 'REPO_PASS', 'CLEANUP', 'RUN_ONCE', 'LATEST', 'CRON',
'PROMETHEUS_PORT', 'NOTIFIERS', 'REPO_USER', 'REPO_PASS', 'CLEANUP', 'RUN_ONCE', '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']
Expand All @@ -21,7 +21,6 @@ class Config(object):
ignore = []
data_export = None
log_level = 'info'
latest = False
cleanup = False
run_once = False
dry_run = False
Expand Down Expand Up @@ -91,9 +90,8 @@ def parse(self):
setattr(self, option.lower(), opt)
except ValueError as e:
print(e)
elif option in ['LATEST', 'CLEANUP', 'RUN_ONCE', 'INFLUX_SSL', 'INFLUX_VERIFY_SSL', 'DRY_RUN',
'SELF_UPDATE', 'LABEL_ENABLE', 'DOCKER_TLS', 'LABELS_ONLY', 'DOCKER_TLS_VERIFY',
'SWARM']:
elif option in ['CLEANUP', 'RUN_ONCE', 'INFLUX_SSL', 'INFLUX_VERIFY_SSL', 'DRY_RUN', 'SWARM',
'SELF_UPDATE', 'LABEL_ENABLE', 'DOCKER_TLS', 'LABELS_ONLY', 'DOCKER_TLS_VERIFY']:
if env_opt.lower() in ['true', 'yes']:
setattr(self, option.lower(), True)
elif env_opt.lower() in ['false', 'no']:
Expand All @@ -112,7 +110,7 @@ def parse(self):

if self.interval < 30:
self.interval = 30

if self.labels_only and not self.label_enable:
self.logger.warning('labels_only enabled but not in use without label_enable')

Expand Down
46 changes: 22 additions & 24 deletions pyouroboros/dockerclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,12 @@ def recreate(self, container, latest_image):

new_container.start()

def pull(self, image_object):
"""Docker pull image tag/latest"""
image = image_object
try:
tag = image.tags[0]
except IndexError:
self.logger.error('Malformed or missing tag. Skipping...')
def pull(self, current_tag):
"""Docker pull image tag"""
tag = current_tag
if not tag:
self.logger.error('Missing tag. Skipping...')
raise ConnectionError
if self.config.latest and image.tags[0][-6:] != 'latest':
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'

self.logger.debug('Checking tag: %s', tag)
try:
if self.config.dry_run:
Expand All @@ -169,7 +157,7 @@ def pull(self, image_object):
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)
Expand Down Expand Up @@ -239,12 +227,13 @@ def socket_check(self):

for container in self.monitored:
current_image = container.image
current_tag = container.attrs['Config']['Image']
shared_image = [uct for uct in updateable if uct[1].id == current_image.id]
if shared_image:
latest_image = shared_image[0][2]
else:
try:
latest_image = self.pull(current_image)
latest_image = self.pull(current_tag)
except ConnectionError:
continue

Expand Down Expand Up @@ -390,7 +379,7 @@ def monitor_filter(self):
return monitored_services

def pull(self, tag):
"""Docker pull image tag/latest"""
"""Docker pull image tag"""
self.logger.debug('Checking tag: %s', tag)
try:
if self.config.dry_run:
Expand Down Expand Up @@ -431,8 +420,12 @@ def update(self):

for service in self.monitored:
image_string = service.attrs['Spec']['TaskTemplate']['ContainerSpec']['Image']
tag = image_string.split('@')[0]
sha256 = image_string.split('@')[1][7:]
if '@' in image_string:
tag = image_string.split('@')[0]
sha256 = image_string.split('@')[1][7:]
else:
self.logger.error('No image SHA for %s. Skipping', image_string)
continue

try:
latest_image = self.pull(tag)
Expand All @@ -450,7 +443,7 @@ def update(self):
(service, sha256[-10:], latest_image)
)

if 'ouroboros' in service.name:
if 'ouroboros' in service.name and self.config.self_update:
self.data_manager.total_updated[self.socket] += 1
self.data_manager.add(label=service.name, socket=self.socket)
self.data_manager.add(label='all', socket=self.socket)
Expand All @@ -469,4 +462,9 @@ def update(self):
self.data_manager.add(label='all', socket=self.socket)

if updated_count > 0:
self.notification_manager.send(container_tuples=updated_service_tuples, socket=self.socket, kind='update')
self.notification_manager.send(
container_tuples=updated_service_tuples,
socket=self.socket,
kind='update',
mode='service'
)
3 changes: 0 additions & 3 deletions pyouroboros/ouroboros.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ def main():
docker_group.add_argument('-c', '--cleanup', default=Config.cleanup, dest='CLEANUP', action='store_true',
help='Remove old images after updating')

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('-r', '--repo-user', default=Config.repo_user, dest='REPO_USER',
help='Private docker registry username\n'
'EXAMPLE: [email protected]')
Expand Down

0 comments on commit 95fedd7

Please sign in to comment.