Ejemplo n.º 1
0
def start_server(slug, interface_folder, action, path_to_code, python3,
                 tmp_file_name=None):
    env_name = conf.default_domain_data['interpreter']
    docker_filename = '/root/' + os.path.basename(path_to_code)
    client = docker.from_env()
    folder = Folder(slug)

    logging.info('Interface Folder {}'.format(interface_folder))
    return client.containers.run(folder.image_name_cli(),
            ' '.join(('python -u', '/root/interface/src/main.py', slug, action, env_name, docker_filename,
                  str(conf.console_server_port), str(conf.log_level), tmp_file_name or '-')),
            volumes={
                tmp_folder(interface_folder): {
                    'bind': '/root/interface',
                    'mode': 'rw'
                },
                path_to_code: {
                    'bind': docker_filename,
                    'mode': 'rw'
                }
            },
            ports={
                (str(conf.console_server_port) + '/tcp'): conf.console_server_port
            },
            name=NAME_CLI_INTERFACE,
            network_mode=NAME_CLI_NETWORK,
            stdout=True,
            detach=True,
            tty=True
        )
Ejemplo n.º 2
0
def can_check_mission(slug):
    folder = Folder(slug)
    docker = DockerClient()

    try:
        docker.images.get(folder.image_name())
        docker.images.get(folder.image_name_cli())
    except ImageNotFound:
        return False
    else:
        return True
Ejemplo n.º 3
0
def rebuild_cli_interface(slug):
    folder = Folder(slug)
    build_folder = folder.interface_cli_folder_path()
    img_name = folder.image_name_cli()

    logging.info("[interface] Build docker image %s from %s", img_name,
                 build_folder)

    docker = DockerClient()
    try:
        docker.build(name_image=img_name, path=tmp_folder(build_folder))
    except BuildError as e:
        logging.warning('Build Error:')
        for item in e.build_log:
            logging.warning(item.get('stream'))
        logging.warning(list(e.build_log))
        logging.warning(e.msg)