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