Ejemplo n.º 1
0
import docker

from Exceptions import ImageNotFoundException, FailedUpdatingContainerException, FailedCleaningServiceException, \
    FailedUpdatingServiceException
from Logger import Logger
from ConfigReader import ConfigReader

client = docker.from_env()
config_reader = ConfigReader()

login, password = config_reader.get_gitlab_credentials()
client.login(username=login, password=password, registry='registry.gitlab.com')
logger = Logger()


# Pull image from given location.
def refresh_image(location):
    try:
        logger.log_line(f'Pulling image {location}, this may take a while.')
        client.images.pull(location)
        logger.log_line(f'Pulled image {location}')
    except Exception:
        raise ImageNotFoundException(f'Image not found at {location}!')


# Restart all containers running an old version of the passed image.
def restart_outdated_containers(location, revision):
    try:
        restarted = False
        containers = client.containers.list(all=True)
        for container in containers: