mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-08 02:24:04 +00:00
109 lines
3.2 KiB
Python
109 lines
3.2 KiB
Python
# Copyright (c) Jupyter Development Team.
|
|
# Distributed under the terms of the Modified BSD License.
|
|
import logging
|
|
from plumbum.cmd import docker
|
|
from .docker_runner import run_simple_command
|
|
from .git_helper import GitHelper
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def quoted_output(container, cmd: str) -> str:
|
|
return "\n".join([
|
|
"```",
|
|
run_simple_command(container, cmd, print_result=False),
|
|
"```"
|
|
])
|
|
|
|
|
|
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:
|
|
"""Common interface for all manifests"""
|
|
@staticmethod
|
|
def markdown_piece(container) -> str:
|
|
raise NotImplementedError
|
|
|
|
|
|
class CondaEnvironmentManifest(ManifestInterface):
|
|
@staticmethod
|
|
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 markdown_piece(container) -> str:
|
|
return "\n".join([
|
|
"## Apt Packages",
|
|
"",
|
|
quoted_output(container, "apt list --installed")
|
|
])
|
|
|
|
|
|
class RPackagesManifest(ManifestInterface):
|
|
@staticmethod
|
|
def markdown_piece(container) -> str:
|
|
return "\n".join([
|
|
"## R Packages",
|
|
"",
|
|
quoted_output(container, "R --version"),
|
|
"",
|
|
quoted_output(container, "R --silent -e 'installed.packages(.Library)[, c(1,3)]'")
|
|
])
|
|
|
|
|
|
class JuliaPackagesManifest(ManifestInterface):
|
|
@staticmethod
|
|
def markdown_piece(container) -> str:
|
|
return "\n".join([
|
|
"## Julia Packages",
|
|
"",
|
|
quoted_output(container, "julia -E 'using InteractiveUtils; versioninfo()'"),
|
|
"",
|
|
quoted_output(container, "julia -E 'import Pkg; Pkg.status()'")
|
|
])
|
|
|
|
|
|
class SparkInfoManifest(ManifestInterface):
|
|
@staticmethod
|
|
def markdown_piece(container) -> str:
|
|
return "\n".join([
|
|
"## Apache Spark",
|
|
"",
|
|
quoted_output(container, "/usr/local/spark/bin/spark-submit --version"),
|
|
])
|