mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-17 06:52:56 +00:00
Make manifests and manifests.py itself more beautiful
This commit is contained in:
@@ -10,15 +10,15 @@ docker = plumbum.local["docker"]
|
||||
|
||||
|
||||
def quoted_output(container: Container, cmd: str) -> str:
|
||||
return "\n".join(
|
||||
[
|
||||
"```text",
|
||||
DockerRunner.run_simple_command(container, cmd, print_result=False).strip(
|
||||
"\n"
|
||||
),
|
||||
"```",
|
||||
]
|
||||
)
|
||||
cmd_output = DockerRunner.run_simple_command(container, cmd, print_result=False)
|
||||
# For example, `mamba info --quiet` adds redundant empty lines
|
||||
cmd_output = cmd_output.strip("\n")
|
||||
# For example, R packages list contains trailing backspaces
|
||||
cmd_output = "\n".join(line.rstrip() for line in cmd_output.split("\n"))
|
||||
return f"""\
|
||||
```text
|
||||
{cmd_output}
|
||||
```"""
|
||||
|
||||
|
||||
class ManifestHeader:
|
||||
@@ -32,7 +32,7 @@ class ManifestHeader:
|
||||
commit_hash_tag = GitHelper.commit_hash_tag()
|
||||
commit_message = GitHelper.commit_message()
|
||||
|
||||
# Unfortunately, docker images doesn't work when specifying `docker.io` as registry
|
||||
# Unfortunately, `docker images` doesn't work when specifying `docker.io` as registry
|
||||
fixed_registry = registry + "/" if registry != "docker.io" else ""
|
||||
|
||||
image_size = docker[
|
||||
@@ -42,23 +42,20 @@ class ManifestHeader:
|
||||
"{{.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: `{registry}/{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:",
|
||||
"",
|
||||
"```text",
|
||||
f"{commit_message}",
|
||||
"```",
|
||||
]
|
||||
)
|
||||
return f"""\
|
||||
# Build manifest for image: {short_image_name}:{commit_hash_tag}
|
||||
|
||||
## Build Info
|
||||
|
||||
- Build datetime: {build_timestamp}
|
||||
- Docker image: `{registry}/{owner}/{short_image_name}:{commit_hash_tag}`
|
||||
- Docker image size: {image_size}
|
||||
- Git commit SHA: [{commit_hash}](https://github.com/jupyter/docker-stacks/commit/{commit_hash})
|
||||
- Git commit message:
|
||||
|
||||
```text
|
||||
{commit_message}
|
||||
```"""
|
||||
|
||||
|
||||
class ManifestInterface:
|
||||
@@ -72,78 +69,57 @@ class ManifestInterface:
|
||||
class CondaEnvironmentManifest(ManifestInterface):
|
||||
@staticmethod
|
||||
def markdown_piece(container: Container) -> str:
|
||||
return "\n".join(
|
||||
[
|
||||
"## Python Packages",
|
||||
"",
|
||||
DockerRunner.run_simple_command(container, "python --version"),
|
||||
"",
|
||||
"`mamba info --quiet`:",
|
||||
"",
|
||||
quoted_output(container, "mamba info --quiet"),
|
||||
"",
|
||||
"`mamba list`:",
|
||||
"",
|
||||
quoted_output(container, "mamba list"),
|
||||
]
|
||||
)
|
||||
return f"""\
|
||||
## Python Packages
|
||||
|
||||
{DockerRunner.run_simple_command(container, "python --version")}
|
||||
|
||||
`mamba info --quiet`:
|
||||
|
||||
{quoted_output(container, "mamba info --quiet")}
|
||||
|
||||
`mamba list`:
|
||||
|
||||
{quoted_output(container, "mamba list")}"""
|
||||
|
||||
|
||||
class AptPackagesManifest(ManifestInterface):
|
||||
@staticmethod
|
||||
def markdown_piece(container: Container) -> str:
|
||||
return "\n".join(
|
||||
[
|
||||
"## Apt Packages",
|
||||
"",
|
||||
"`apt list --installed`:",
|
||||
"",
|
||||
quoted_output(container, "apt list --installed"),
|
||||
]
|
||||
)
|
||||
return f"""\
|
||||
## Apt Packages
|
||||
|
||||
`apt list --installed`:
|
||||
|
||||
{quoted_output(container, "apt list --installed")}"""
|
||||
|
||||
|
||||
class RPackagesManifest(ManifestInterface):
|
||||
@staticmethod
|
||||
def markdown_piece(container: Container) -> str:
|
||||
return "\n".join(
|
||||
[
|
||||
"## R Packages",
|
||||
"",
|
||||
quoted_output(container, "R --version"),
|
||||
"",
|
||||
quoted_output(
|
||||
container,
|
||||
"R --silent -e 'installed.packages(.Library)[, c(1,3)]'",
|
||||
),
|
||||
]
|
||||
)
|
||||
return f"""\
|
||||
## 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: Container) -> str:
|
||||
return "\n".join(
|
||||
[
|
||||
"## Julia Packages",
|
||||
"",
|
||||
quoted_output(
|
||||
container,
|
||||
"julia -E 'using InteractiveUtils; versioninfo()'",
|
||||
),
|
||||
"",
|
||||
quoted_output(container, "julia -E 'import Pkg; Pkg.status()'"),
|
||||
]
|
||||
)
|
||||
return f"""\
|
||||
## 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: Container) -> str:
|
||||
return "\n".join(
|
||||
[
|
||||
"## Apache Spark",
|
||||
"",
|
||||
quoted_output(container, "/usr/local/spark/bin/spark-submit --version"),
|
||||
]
|
||||
)
|
||||
return f"""\
|
||||
## Apache Spark
|
||||
|
||||
{quoted_output(container, "/usr/local/spark/bin/spark-submit --version")}"""
|
||||
|
Reference in New Issue
Block a user