(image_name: str, temporary_path: str)
return temp_archive_filename
Do a `docker save <image_name> -o <temporary_path>` and return the
    `temporary_path`.
Do a `docker save <image_name> -o <temporary_path>` and return the
    `temporary_path`.
Do a docker save <image_name > - o <temporary_path > and return the temporary_path .
def docker_save_to_tmp(image_name: str, temporary_path: str) -> Path:
    """
    Do a `docker save <image_name> -o <temporary_path>` and return the
    `temporary_path`.
    """
    temp_archive_filename = Path(temporary_path) / (
        image_name.replace("/", "--") + ".tar"
    )
    command = ["docker", "save", image_name, "-o", str(temp_archive_filename)]

    try:
        with yaspin(text="Saving docker image"):
            subprocess.run(
                command,
                check=True,
                stderr=subprocess.PIPE,
                timeout=DOCKER_COMMAND_TIMEOUT,
            )
    except subprocess.CalledProcessError as exc:
        err_string = str(exc.stderr)
        if "No such image" in err_string or "reference does not exist" in err_string:
            docker_pull_image(image_name)

            return docker_save_to_tmp(image_name, temporary_path)
        raise click.ClickException("Unable to save docker archive")
    except subprocess.TimeoutExpired:
        raise click.ClickException('Command "{}" timed out'.format(" ".join(command)))

    return temp_archive_filename
def docker_save_to_tmp ( image_name : str , temporary_path : str ) -> Path : temp_archive_filename = Path ( temporary_path ) / ( image_name . replace ( "/" , "--" ) + ".tar" ) command = [ "docker" , "save" , image_name , "-o" , str ( temp_archive_filename ) ] try : with yaspin ( text = "Saving docker image" ) : subprocess . run ( command , check = True , stderr = subprocess . PIPE , timeout = DOCKER_COMMAND_TIMEOUT , ) except subprocess . CalledProcessError as exc : err_string = str ( exc . stderr ) if "No such image" in err_string or "reference does not exist" in err_string : docker_pull_image ( image_name ) return docker_save_to_tmp ( image_name , temporary_path ) raise click . ClickException ( "Unable to save docker archive" ) except subprocess . TimeoutExpired : raise click . ClickException ( 'Command "{}" timed out' . format ( " " . join ( command ) ) ) return temp_archive_filename