コード例 #1
0
def copy_config(file_path, config_dir, container_name):
    """Copy configuration file from host machine into docker.

    Args:
        file_path: The path of the config file being copied
        config_dir: The configuration directory on the docker container
    Returns:
        None
    """
    command = 'docker cp {0} {1}:{2}'.format(file_path, container_name,
                                             config_dir)
    shared.run_script(command)
コード例 #2
0
def docker_check():
    """Check if docker is installed/running.

    Args:
        None

    Returns:
        None
    """
    status = shared.run_script('service docker status',
                               verbose=False,
                               die=False)[0]
    if status == 0:
        return True
    elif status == 3:
        message = '''\
The docker daemon is not running.
Ensure that the docker daemon is running before installing.'''
    elif status == 4:
        message = '''\
Docker has not been installed to the system.
Ensure that docker is installed before creating the pattoo docker container.'''
    else:
        message = '''\
Unknown error code.
Ensure that docker is running and has the adequate permissions'''
    log.log2die_safe(80007, message)
コード例 #3
0
def pattoo_shared_check():
    """Check if pattoo shared is installed.

    If pattoo shared is not installed, it gets installed to the user's
    default python path

    Args:
        None

    Returns:
        None

    """
    # Try except to install pattoo shared
    try:
        import pattoo_shared
    except ModuleNotFoundError:
        print('PattooShared is missing, installing the latest version')
        shared.run_script('pip3 install PattooShared')
コード例 #4
0
def venv_check():
    """Check if "virtualenv" is installed.

    If virtualenv is not installed it gets automatically installed to the
    user's default python path

    Args:
        None

    Returns:
        None

    """
    # Check if virtualenv is installed
    try:
        import virtualenv
    except ModuleNotFoundError:
        print('virtualenv is not installed, installing the latest version')
        shared.run_script('pip3 install virtualenv')
コード例 #5
0
def image_check(image_name):
    """Check if a docker image already exists for the image specified.
    Args:
        The name of the image being checked
    Returns:
        None
    """
    status = shared.run_script('docker image inspect {}'.format(image_name),
                               die=False)[0]
    if status == 0:
        message = 'The docker image "{}" already exists'.format(image_name)
        log.log2die_safe(80009, message)
コード例 #6
0
def install(container_name, config_files, verbose=True):
    """Perform docker installation for the respective pattoo component.

    Args:
        component_name: The name of the pattoo component being dockerized
        config_files: A list of configuration files
        file_path: The filepath to the Dockerfile

    Returns:
        None
    """
    # Initialize key variables
    config_dir = os.environ.get('PATTOO_CONFIGDIR')

    # Insert ports based on config file
    server_path = os.path.join(config_dir, config_files[1])
    expose_ports(server_path, './Dockerfile')

    # Check if docker is installed/running
    docker_check()

    # Build pattoo container
    image_check('pattoo-web')
    print('Building Pattoo Web Container. This could take some time...')
    shared.run_script('docker build -t {} .'.format(container_name))

    # Run container in detached mode as pattoo
    run_command = '''\
docker run --privileged -d --network=host --name={0} {0}'''.format(
        container_name)
    shared.run_script(run_command, verbose=verbose)

    # Copy configuration files from host machine
    for config_file in config_files:
        file_path = os.path.join(config_dir, config_file)
        copy_config(file_path, config_dir, container_name)

    # Run docker installation
    install_command = '''\
docker exec -i {} setup/install.py install all'''.format(container_name)
    shared.run_script(install_command)