mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-10 11:32:57 +00:00
Add some manifests implementation
This commit is contained in:
@@ -43,6 +43,22 @@ def append_build_history_line(short_image_name, owner, wiki_path, all_tags, cont
|
|||||||
f.write(file)
|
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):
|
def create_manifests(short_image_name, owner, wiki_path):
|
||||||
logger.info(f"Creating manifests for image: {short_image_name}")
|
logger.info(f"Creating manifests for image: {short_image_name}")
|
||||||
taggers, manifests = get_taggers_and_manifests(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:
|
with DockerRunner(image) as container:
|
||||||
all_tags = [tagger.tag_value(container) for tagger in taggers]
|
all_tags = [tagger.tag_value(container) for tagger in taggers]
|
||||||
append_build_history_line(short_image_name, owner, wiki_path, all_tags, container)
|
append_build_history_line(short_image_name, owner, wiki_path, all_tags, container)
|
||||||
|
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}")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@@ -33,7 +33,7 @@ def run_simple_command(container, cmd, print_result=True):
|
|||||||
logger.info(f"Running cmd: '{cmd}' on container: {container}")
|
logger.info(f"Running cmd: '{cmd}' on container: {container}")
|
||||||
out = container.exec_run(cmd)
|
out = container.exec_run(cmd)
|
||||||
assert out.exit_code == 0, f"Command: {cmd} failed"
|
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:
|
if print_result:
|
||||||
logger.info(f"Command result: {result}")
|
logger.info(f"Command result: {result}")
|
||||||
return result
|
return result
|
||||||
|
@@ -1,31 +1,52 @@
|
|||||||
# Copyright (c) Jupyter Development Team.
|
# Copyright (c) Jupyter Development Team.
|
||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
import logging
|
import logging
|
||||||
|
from docker_runner import run_simple_command
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def quoted_output(container, cmd: str) -> str:
|
||||||
|
return "\n".join([
|
||||||
|
"```",
|
||||||
|
run_simple_command(container, cmd, print_result=False),
|
||||||
|
"```"
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
class ManifestInterface:
|
class ManifestInterface:
|
||||||
"""Common interface for all manifests"""
|
"""Common interface for all manifests"""
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def manifest_piece(container):
|
def markdown_piece(container) -> str:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class BuildInfoManifest(ManifestInterface):
|
class BuildInfoManifest(ManifestInterface):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def manifest_piece(container):
|
def markdown_piece(container) -> str:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class CondaEnvironmentManifest(ManifestInterface):
|
class CondaEnvironmentManifest(ManifestInterface):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def manifest_piece(container):
|
def markdown_piece(container) -> str:
|
||||||
return None
|
return "\n".join([
|
||||||
|
"## Python Packages",
|
||||||
|
"",
|
||||||
|
quoted_output(container, "python --version"),
|
||||||
|
"",
|
||||||
|
quoted_output(container, "conda info"),
|
||||||
|
"",
|
||||||
|
quoted_output(container, "conda list")
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
class AptPackagesManifest(ManifestInterface):
|
class AptPackagesManifest(ManifestInterface):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def manifest_piece(container):
|
def markdown_piece(container) -> str:
|
||||||
return None
|
return "\n".join([
|
||||||
|
"## Apt Packages",
|
||||||
|
"",
|
||||||
|
quoted_output(container, "apt list --installed")
|
||||||
|
])
|
||||||
|
Reference in New Issue
Block a user