diff --git a/tagging/create_manifests.py b/tagging/create_manifests.py index 2b988f1c..7ba61f3c 100755 --- a/tagging/create_manifests.py +++ b/tagging/create_manifests.py @@ -43,6 +43,22 @@ def append_build_history_line(short_image_name, owner, wiki_path, all_tags, cont f.write(file) +def create_manifest_file(short_image_name, owner, wiki_path, manifests, container): + manifest_names = [manifest.__name__ for manifest in manifests] + logger.info(f"Using manifests: {manifest_names}") + + commit_sha_tag = SHATagger.tag_value(container) # first 12 letters of commit hash + manifest_file = os.path.join(wiki_path, f"manifests/{short_image_name}-{commit_sha_tag}.md") + + markdown_pieces = [manifest.markdown_piece(container) for manifest in manifests] + # TODO: remove this filter + markdown_pieces = [piece for piece in markdown_pieces if piece is not None] + markdown_content = "\n\n".join(markdown_pieces) + "\n" + + with open(manifest_file, "w") as f: + f.write(markdown_content) + + def create_manifests(short_image_name, owner, wiki_path): logger.info(f"Creating manifests for image: {short_image_name}") taggers, manifests = get_taggers_and_manifests(short_image_name) @@ -52,9 +68,7 @@ def create_manifests(short_image_name, owner, wiki_path): with DockerRunner(image) as container: all_tags = [tagger.tag_value(container) for tagger in taggers] append_build_history_line(short_image_name, owner, wiki_path, all_tags, container) - - manifest_names = [manifest.__name__ for manifest in manifests] - logger.info(f"Using manifests: {manifest_names}") + create_manifest_file(short_image_name, owner, wiki_path, manifests, container) if __name__ == "__main__": diff --git a/tagging/docker_runner.py b/tagging/docker_runner.py index 9b0302cb..4d2ddb15 100644 --- a/tagging/docker_runner.py +++ b/tagging/docker_runner.py @@ -33,7 +33,7 @@ def run_simple_command(container, cmd, print_result=True): logger.info(f"Running cmd: '{cmd}' on container: {container}") out = container.exec_run(cmd) assert out.exit_code == 0, f"Command: {cmd} failed" - result = out.output.decode("utf-8").strip() + result = out.output.decode("utf-8").rstrip() if print_result: logger.info(f"Command result: {result}") return result diff --git a/tagging/manifests.py b/tagging/manifests.py index db9e5fa1..45b289cf 100644 --- a/tagging/manifests.py +++ b/tagging/manifests.py @@ -1,31 +1,52 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. import logging +from docker_runner import run_simple_command logger = logging.getLogger(__name__) +def quoted_output(container, cmd: str) -> str: + return "\n".join([ + "```", + run_simple_command(container, cmd, print_result=False), + "```" + ]) + + class ManifestInterface: """Common interface for all manifests""" @staticmethod - def manifest_piece(container): + def markdown_piece(container) -> str: raise NotImplementedError class BuildInfoManifest(ManifestInterface): @staticmethod - def manifest_piece(container): + def markdown_piece(container) -> str: return None class CondaEnvironmentManifest(ManifestInterface): @staticmethod - def manifest_piece(container): - return None + def markdown_piece(container) -> str: + return "\n".join([ + "## Python Packages", + "", + quoted_output(container, "python --version"), + "", + quoted_output(container, "conda info"), + "", + quoted_output(container, "conda list") + ]) class AptPackagesManifest(ManifestInterface): @staticmethod - def manifest_piece(container): - return None + def markdown_piece(container) -> str: + return "\n".join([ + "## Apt Packages", + "", + quoted_output(container, "apt list --installed") + ])