Esempio n. 1
0
def download_dcos_installer(ssh_tunnel: ssh_client.Tunnelled,
                            installer_path: str, download_url: str):
    """Response status 403 is fatal for curl's retry. Additionally, S3 buckets
    have been returning 403 for valid uploads for 10-15 minutes after CI finished build
    Therefore, give a five minute buffer to help stabilize CI
    """
    log.info('Attempting to download installer from: ' + download_url)
    try:
        ssh_tunnel.command(curl(download_url, installer_path))
    except Exception:
        log.exception('Download failed!')
        raise
Esempio n. 2
0
def prepare_bootstrap(ssh_tunnel: ssh_client.Tunnelled,
                      download_url: str) -> str:
    """ Will setup a host as a 'bootstrap' host. This includes:
    * creating a genconf dir so its not owned by the root user, which happens
        if you run the installer without a genconf directory
    * downloading the installer from `download_url`
    """
    log.info('Setting up installer on bootstrap host')
    ssh_tunnel.command(['mkdir', '-p', 'genconf'])
    bootstrap_home = ssh_tunnel.command(['pwd']).decode().strip()
    installer_path = os.path.join(bootstrap_home, 'dcos_generate_config.sh')
    download_dcos_installer(ssh_tunnel, installer_path, download_url)
    return installer_path
Esempio n. 3
0
def do_genconf(ssh_tunnel: ssh_client.Tunnelled, genconf_dir: str,
               installer_path: str):
    """ runs --genconf with the installer
    if an nginx is running, kill it and restart the nginx to host the files
    Args:
        ssh_tunnel: tunnel to the host running the installer
        genconf_dir: path on localhost of genconf directory to transfer
        installer_path: path of the installer on the remote host
    """
    log.debug('Copying config to host bootstrap host')
    installer_dir = os.path.dirname(installer_path)
    # copy config to genconf/
    ssh_tunnel.copy_file(genconf_dir, installer_dir)
    # try --genconf
    log.info('Running --genconf command...')
    ssh_tunnel.command(['sudo', 'bash', installer_path, '--genconf'],
                       stdout=sys.stdout.buffer)
    # if OK we just need to restart nginx
    host_share_path = os.path.join(installer_dir, 'genconf/serve')
    volume_mount = host_share_path + ':/usr/share/nginx/html'
    nginx_service_name = 'dcos-bootstrap-nginx'
    log.info('Starting nginx server to host bootstrap packages')
    if get_docker_service_status(ssh_tunnel, nginx_service_name):
        ssh_tunnel.command(['sudo', 'docker', 'rm', '-f', nginx_service_name])
    start_docker_service(
        ssh_tunnel, nginx_service_name,
        ['--publish=80:80', '--volume=' + volume_mount, 'nginx'])
Esempio n. 4
0
def start_docker_service(ssh_tunnel: ssh_client.Tunnelled, docker_name: str,
                         docker_args: list):
    ssh_tunnel.command(
        ['sudo', 'docker', 'run', '--name', docker_name, '--detach=true'] +
        docker_args)
Esempio n. 5
0
def get_docker_service_status(ssh_tunnel: ssh_client.Tunnelled,
                              docker_name: str) -> str:
    return ssh_tunnel.command([
        'sudo', 'docker', 'ps', '-q', '--filter', 'name=' + docker_name,
        '--filter', 'status=running'
    ]).decode().strip()