Esempio n. 1
0
def healthcheck(url: str, services: str, restart: bool = False):
    """Ensure the running containers are healthy."""
    logger = build_logger('main')
    infos = DockerInfos(url)
    logger.info('remote hostname=%s', infos.hostname)
    docker_operator = DockerOperator(infos)
    docker_operator.is_remote_reachable()
    docker_operator.list_healthy_containers(restart)
Esempio n. 2
0
 def __init__(self,
              infos: DockerInfos,
              logger: Optional[logging.Logger] = None):
     self.client = docker.DockerClient(infos.url)
     if logger is not None:
         self.logger = logger
     else:
         self.logger = build_logger(self.__class__.__name__)
     self.logger.info('setup DockerClient')
Esempio n. 3
0
def build(url: str, services: str, tag: str = 'latest'):
    """Build the Service on the remote host."""
    # TODO: Add progressbar
    logger = build_logger('main')
    infos = DockerInfos(url)
    logger.info('remote hostname=%s', infos.hostname)
    docker_operator = DockerOperator(infos)
    docker_operator.is_remote_reachable()
    for service in services:
        service_path = Path(service)
        name = service_path.absolute().name
        docker_operator.build_service(service_path, name, tag=tag)
Esempio n. 4
0
def deploy(url: str, services: str, tag: str = 'latest'):
    """Deploy the Service on the remote host."""
    # TODO: Add progressbar
    logger = build_logger('main')
    infos = DockerInfos(url)
    logger.info('remote hostname=%s', infos.hostname)
    docker_operator = DockerOperator(infos)
    docker_operator.is_remote_reachable()
    for service in services:
        service_path = Path(service).absolute()
        image_name = service_path.name
        docker_operator.run_container(
            image_name,
            image_tag=tag,
        )
Esempio n. 5
0
 def __init__(self,
              infos: SSHInfos,
              logger: Optional[logging.Logger] = None):
     self.client = paramiko.client.SSHClient()
     self.infos = infos
     self.client.load_system_host_keys()
     self.client.connect(
         infos.hostname,
         port=infos.port,
         username=infos.username,
         password=infos.password,
     )
     if logger is not None:
         self.logger = logger
     else:
         self.logger = build_logger(self.__class__.__name__)
     self.logger.info('setup SSHClient targeting %s', infos.hostname)
Esempio n. 6
0
def config(hostname: str, port: int, username: str, password: str):
    """Configure Docker on the remote host."""
    logger = build_logger('main')
    ssh_infos = SSHInfos(hostname, username, password, port=port)
    logger.info('remote hostname=%s', ssh_infos.hostname)
    remote = SSHOperator(ssh_infos)
    logger.info('check if docker is installed')
    docker_installed = remote.is_docker_installed()
    logger.info(
        'docker is %sinstalled',
        "" if docker_installed else 'not ',
    )
    if not docker_installed:
        remote.install_docker()
        return

    logger.info('check if docker is up-to-date')
    docker_up_to_date = remote.is_docker_up_to_date()
    logger.info(
        'docker is %sup_to_date',
        "" if docker_up_to_date else 'not ',
    )
    if not docker_up_to_date:
        remote.install_docker()