Пример #1
0
def export_docker_images(
        project: Project,
        destination: str,
        commit: Optional[str],
        extra_docker_images: Iterable[str] = (),
) -> None:
    commit = expand_commit_id(project.directory, commit=(commit or 'HEAD'))
    docker_images = {
        step.image
        for step in project.get_config(commit).steps.values()
    }
    docker_images |= set(extra_docker_images)
    for i, image in enumerate(docker_images, 1):
        output_path = os.path.join(destination,
                                   sanitize_filename(f'docker-{image}.tar'))
        if image not in extra_docker_images:
            print_parcel_progress('::: Pulling image {}/{} ({})'.format(
                i,
                len(docker_images),
                image,
            ))
            subprocess.check_call(['docker', 'pull', image])
        print_parcel_progress(
            f'::: Exporting image {i}/{len(docker_images)} ({image})')
        export_docker_image(image, output_path)
Пример #2
0
def parcel(destination, commit, code, valohai_local_run, docker_images,
           unparcel_script):
    project = get_project(require=True)

    if not destination:
        destination = sanitize_filename('{}-parcel-{}'.format(
            project.name,
            time.strftime('%Y%m%d-%H%M%S'),
        ))

    click.echo('Packing {} to directory {}'.format(
        click.style(project.name, bold=True, fg='blue'),
        click.style(destination, bold=True, fg='green'),
    ))

    ensure_makedirs(destination)

    extra_docker_images = []

    if code in ('bundle', 'archive', 'tarball'):
        export_code(project, destination, mode=code)

    if valohai_local_run:
        export_valohai_local_run(project, destination)

    if docker_images:
        export_docker_images(project, destination, commit, extra_docker_images)

    if unparcel_script:
        write_unparcel_script(destination)

    success('Parcel {} created!'.format(destination))
Пример #3
0
def parcel(
    destination: Optional[str],
    commit: Optional[str],
    code: str,
    valohai_local_run: bool,
    docker_images: bool,
    unparcel_script: bool,
) -> None:
    project = get_project(require=True)

    if not destination:
        destination = sanitize_filename(
            f'{project.name}-parcel-{time.strftime("%Y%m%d-%H%M%S")}')

    click.echo(
        f'Packing {click.style(project.name, bold=True, fg="blue")} '
        f'to directory {click.style(destination, bold=True, fg="green")}')

    ensure_makedirs(destination)

    extra_docker_images: List[str] = []

    if code in ('bundle', 'archive', 'tarball'):
        export_code(project, destination, mode=code)

    if valohai_local_run:
        export_valohai_local_run(destination)

    if docker_images:
        export_docker_images(project, destination, commit, extra_docker_images)

    if unparcel_script:
        write_unparcel_script(destination)

    success(f'Parcel {destination} created!')
Пример #4
0
def export_docker_images(project, destination, commit, extra_docker_images=()):
    commit = expand_commit_id(project.directory, commit=(commit or 'HEAD'))
    docker_images = set(step.image
                        for step in project.get_config(commit).steps.values())
    docker_images |= set(extra_docker_images)
    for i, image in enumerate(docker_images, 1):
        output_path = os.path.join(
            destination, sanitize_filename('docker-{}.tar'.format(image)))
        if image not in extra_docker_images:
            print_parcel_progress('::: Pulling image {}/{} ({})'.format(
                i,
                len(docker_images),
                image,
            ))
            subprocess.check_call(['docker', 'pull', image])
        print_parcel_progress('::: Exporting image {}/{} ({})'.format(
            i,
            len(docker_images),
            image,
        ))
        export_docker_image(image, output_path)