def retrive_autopatched_image_history_and_upload_to_s3()

in src/patch_helper.py [0:0]


def retrive_autopatched_image_history_and_upload_to_s3(image_uri):
    """
    In this method , we extract the overall_history.txt file from the image and then upload it to the s3 bucket.
    The extracted data is also returned by this function.

    :param image_uri: str, Image URI
    :return: str, overall_history.txt data
    """
    docker_run_cmd = f"docker run -id --entrypoint='/bin/bash' {image_uri} "
    container_id = run(f"{docker_run_cmd}", hide=True).stdout.strip()
    try:
        docker_exec_cmd = f"docker exec -i {container_id}"
        history_retrieval_command = (
            f"cat {PATCHING_INFO_PATH_WITHIN_DLC}/patch-details/overall_history.txt"
        )
        data = run(f"{docker_exec_cmd} {history_retrieval_command}", hide=True)
        upload_path = get_unique_s3_path_for_uploading_data_to_pr_creation_bucket(
            image_uri=image_uri.replace("-multistage-common", ""), file_name="overall_history.txt"
        )
        tag_set = [
            {
                "Key": "upload_path",
                "Value": remove_repo_root_folder_path_from_the_given_path(
                    given_path=get_overall_history_path(
                        image_uri=image_uri.replace("-multistage-common", "")
                    )
                ),
            },
            {"Key": "image_uri", "Value": image_uri.replace("-multistage-common", "")},
        ]
        upload_data_to_pr_creation_s3_bucket(
            upload_data=data.stdout, s3_filepath=upload_path, tag_set=tag_set
        )
    finally:
        run(f"docker rm -f {container_id}", hide=True, warn=True)
    return data.stdout