mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-12 20:42:57 +00:00
Implement manifest header and improve GitHelper
This commit is contained in:
@@ -8,7 +8,7 @@ import os
|
|||||||
from docker_runner import DockerRunner
|
from docker_runner import DockerRunner
|
||||||
from get_taggers_and_manifests import get_taggers_and_manifests
|
from get_taggers_and_manifests import get_taggers_and_manifests
|
||||||
from git_helper import GitHelper
|
from git_helper import GitHelper
|
||||||
from taggers import SHATagger
|
from manifests import ManifestHeader
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -18,19 +18,19 @@ BUILD_TIMESTAMP = datetime.datetime.utcnow().isoformat()[:-7] + "Z"
|
|||||||
MARKDOWN_LINE_BREAK = "<br />"
|
MARKDOWN_LINE_BREAK = "<br />"
|
||||||
|
|
||||||
|
|
||||||
def append_build_history_line(short_image_name, owner, wiki_path, all_tags, container):
|
def append_build_history_line(short_image_name, owner, wiki_path, all_tags):
|
||||||
logger.info("Appending build history line")
|
logger.info("Appending build history line")
|
||||||
|
|
||||||
date_column = f"`{BUILD_TIMESTAMP}`"
|
date_column = f"`{BUILD_TIMESTAMP}`"
|
||||||
image_column = MARKDOWN_LINE_BREAK.join(
|
image_column = MARKDOWN_LINE_BREAK.join(
|
||||||
f"`{owner}/{short_image_name}:{tag_value}`" for tag_value in all_tags
|
f"`{owner}/{short_image_name}:{tag_value}`" for tag_value in all_tags
|
||||||
)
|
)
|
||||||
commit_sha_tag = SHATagger.tag_value(container) # first 12 letters of commit hash
|
commit_hash = GitHelper.commit_hash()
|
||||||
commit_hash = GitHelper.commit_hash() # full commit hash
|
commit_hash_tag = GitHelper.commit_hash_tag()
|
||||||
links_column = MARKDOWN_LINE_BREAK.join([
|
links_column = MARKDOWN_LINE_BREAK.join([
|
||||||
f"[Git diff](https://github.com/jupyter/docker-stacks/commit/{commit_hash})",
|
f"[Git diff](https://github.com/jupyter/docker-stacks/commit/{commit_hash})",
|
||||||
f"[Dockerfile](https://github.com/jupyter/docker-stacks/blob/{commit_hash}/{short_image_name}/Dockerfile)"
|
f"[Dockerfile](https://github.com/jupyter/docker-stacks/blob/{commit_hash}/{short_image_name}/Dockerfile)"
|
||||||
f"[Build manifest](./{short_image_name}-{commit_sha_tag})"
|
f"[Build manifest](./{short_image_name}-{commit_hash_tag})"
|
||||||
])
|
])
|
||||||
build_history_line = "|".join([date_column, image_column, links_column]) + "|"
|
build_history_line = "|".join([date_column, image_column, links_column]) + "|"
|
||||||
|
|
||||||
@@ -47,12 +47,11 @@ def create_manifest_file(short_image_name, owner, wiki_path, manifests, containe
|
|||||||
manifest_names = [manifest.__name__ for manifest in manifests]
|
manifest_names = [manifest.__name__ for manifest in manifests]
|
||||||
logger.info(f"Using manifests: {manifest_names}")
|
logger.info(f"Using manifests: {manifest_names}")
|
||||||
|
|
||||||
commit_sha_tag = SHATagger.tag_value(container) # first 12 letters of commit hash
|
commit_hash_tag = GitHelper.commit_hash_tag()
|
||||||
manifest_file = os.path.join(wiki_path, f"manifests/{short_image_name}-{commit_sha_tag}.md")
|
manifest_file = os.path.join(wiki_path, f"manifests/{short_image_name}-{commit_hash_tag}.md")
|
||||||
|
|
||||||
markdown_pieces = [manifest.markdown_piece(container) for manifest in manifests]
|
markdown_pieces = [ManifestHeader.create_header(short_image_name, owner, BUILD_TIMESTAMP)] + \
|
||||||
# TODO: remove this filter
|
[manifest.markdown_piece(container) for manifest in manifests]
|
||||||
markdown_pieces = [piece for piece in markdown_pieces if piece is not None]
|
|
||||||
markdown_content = "\n\n".join(markdown_pieces) + "\n"
|
markdown_content = "\n\n".join(markdown_pieces) + "\n"
|
||||||
|
|
||||||
with open(manifest_file, "w") as f:
|
with open(manifest_file, "w") as f:
|
||||||
@@ -67,7 +66,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)
|
||||||
create_manifest_file(short_image_name, owner, wiki_path, manifests, container)
|
create_manifest_file(short_image_name, owner, wiki_path, manifests, container)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -9,6 +9,10 @@ class GitHelper:
|
|||||||
def commit_hash():
|
def commit_hash():
|
||||||
return git["rev-parse", "HEAD"]().strip()
|
return git["rev-parse", "HEAD"]().strip()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def commit_hash_tag():
|
||||||
|
return GitHelper.commit_hash()[:12]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def commit_message():
|
def commit_message():
|
||||||
return git["log", -1, "--pretty=%B"]().strip()
|
return git["log", -1, "--pretty=%B"]().strip()
|
||||||
|
@@ -9,7 +9,7 @@ from taggers import TaggerInterface, \
|
|||||||
RVersionTagger, TensorflowVersionTagger, JuliaVersionTagger, \
|
RVersionTagger, TensorflowVersionTagger, JuliaVersionTagger, \
|
||||||
SparkVersionTagger, HadoopVersionTagger, JavaVersionTagger
|
SparkVersionTagger, HadoopVersionTagger, JavaVersionTagger
|
||||||
from manifests import ManifestInterface, \
|
from manifests import ManifestInterface, \
|
||||||
BuildInfoManifest, CondaEnvironmentManifest, AptPackagesManifest
|
CondaEnvironmentManifest, AptPackagesManifest
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -28,7 +28,7 @@ ALL_IMAGES = {
|
|||||||
JupyterNotebookVersionTagger, JupyterLabVersionTagger, JupyterHubVersionTagger
|
JupyterNotebookVersionTagger, JupyterLabVersionTagger, JupyterHubVersionTagger
|
||||||
],
|
],
|
||||||
manifests=[
|
manifests=[
|
||||||
BuildInfoManifest, CondaEnvironmentManifest, AptPackagesManifest
|
CondaEnvironmentManifest, AptPackagesManifest
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
"minimal-notebook": ImageDescription(
|
"minimal-notebook": ImageDescription(
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
# 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 plumbum.cmd import docker
|
||||||
from docker_runner import run_simple_command
|
from docker_runner import run_simple_command
|
||||||
|
from git_helper import GitHelper
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -15,6 +17,32 @@ def quoted_output(container, cmd: str) -> str:
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
class ManifestHeader:
|
||||||
|
"""ManifestHeader doesn't fall under common interface and we run it separately"""
|
||||||
|
@staticmethod
|
||||||
|
def create_header(short_image_name, owner, build_timestamp) -> str:
|
||||||
|
commit_hash = GitHelper.commit_hash()
|
||||||
|
commit_hash_tag = GitHelper.commit_hash_tag()
|
||||||
|
commit_message = GitHelper.commit_message()
|
||||||
|
|
||||||
|
image_size = docker["images", f"{owner}/{short_image_name}:latest", "--format", '{{.Size}}']().rstrip()
|
||||||
|
|
||||||
|
return "\n".join([
|
||||||
|
f"# Build manifest for image: {short_image_name}:{commit_hash_tag}",
|
||||||
|
"",
|
||||||
|
"## Build Info",
|
||||||
|
"",
|
||||||
|
f"* Build datetime: {build_timestamp}",
|
||||||
|
f"* Docker image: {owner}/{short_image_name}:{commit_hash_tag}",
|
||||||
|
f"* Docker image size: {image_size}",
|
||||||
|
f"* Git commit SHA: [{commit_hash}](https://github.com/jupyter/docker-stacks/commit/{commit_hash})",
|
||||||
|
"* Git commit message:",
|
||||||
|
"```",
|
||||||
|
f"{commit_message}",
|
||||||
|
"```"
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
class ManifestInterface:
|
class ManifestInterface:
|
||||||
"""Common interface for all manifests"""
|
"""Common interface for all manifests"""
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -22,12 +50,6 @@ class ManifestInterface:
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class BuildInfoManifest(ManifestInterface):
|
|
||||||
@staticmethod
|
|
||||||
def markdown_piece(container) -> str:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class CondaEnvironmentManifest(ManifestInterface):
|
class CondaEnvironmentManifest(ManifestInterface):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def markdown_piece(container) -> str:
|
def markdown_piece(container) -> str:
|
||||||
|
@@ -38,7 +38,7 @@ class TaggerInterface:
|
|||||||
class SHATagger(TaggerInterface):
|
class SHATagger(TaggerInterface):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def tag_value(container):
|
def tag_value(container):
|
||||||
return GitHelper.commit_hash()[:12]
|
return GitHelper.commit_hash_tag()
|
||||||
|
|
||||||
|
|
||||||
class UbuntuVersionTagger(TaggerInterface):
|
class UbuntuVersionTagger(TaggerInterface):
|
||||||
|
Reference in New Issue
Block a user