Exemplo n.º 1
0
def start_docker(slug, ref_extra_volume=None):
    command = "{} {} 1 2 {}".format(NAME_CLI_INTERFACE, conf.console_server_port, str(conf.log_level))
    client = DockerClient()
    folder = Folder(slug)

    logging.info('Verification: {}'.format(folder.verification_folder_path()))

    copy_tree(folder.verification_folder_path(), folder.container_verification_folder_path())
    for root, dirs, files in os.walk(folder.container_verification_folder_path()):
        for momo in dirs:
            os.chmod(os.path.join(root, momo), 0o777)
        for momo in files:
            os.chmod(os.path.join(root, momo), 0o777)

    volumes={
            tmp_folder(folder.compiled_referee_folder_path()): {
                    'bind': '/opt/mission/src',
                    'mode': 'rw'
                },
            tmp_folder(folder.compiled_envs_folder_path()): {
                    'bind': '/opt/mission/envs',
                    'mode': 'rw'
                }
        }

    if ref_extra_volume is not None:
        volumes.update(ref_extra_volume)

    return client.run(slug, command, 
        volumes=volumes,
        network_mode=NAME_CLI_NETWORK,
        name='mission__' + slug,
        detach=True)
Exemplo n.º 2
0
def rebuild_mission(slug):
    cleanup_containers()
    folder = Folder(slug)
    docker = DockerClient()
    verification_folder_path = folder.container_verification_folder_path()
    logging.info("[mission] Build docker image %s from %s", folder.image_name(), verification_folder_path)
    if os.path.exists(verification_folder_path):
        shutil.rmtree(verification_folder_path)

    copy_tree(folder.verification_folder_path(), verification_folder_path)

    try:
        docker.build(
            name_image=folder.image_name(),
            path=verification_folder_path)
    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)
        return
    rebuild_cli_interface(slug)