mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-07 01:54:04 +00:00

* feat: build cuda variants of pytorch * feat: build with variant tag * style: remove unused import * refactor: rename get_prefix params (cherry picked from commit 12b50af258c2f331d4100fb63fd41ad1a30acb1d) * revert: drop ROOT_CONTAINER addition from Makefile (cherry picked from commit f42314513df2855957a05c6ba0c748d2df26d7b0) * style: use consistent three empty lines in Makefile (cherry picked from commit 446b45aab37a37720462b5df305ce96b139cf67a) * refactor: add default value for parent-image (cherry picked from commit 32955cec99c7202f0ce50647dfc61ec98f57f741) * revert: use original workflow structure (cherry picked from commit 68c6744513636ec93d14f9bd0bbd123907efd13b) * refactor: use single build image step (cherry picked from commit 5f1ac0aeedcb5969a6d4b2a5bc939817378ab55d) * fix: run merge tags regardless of repository owner (cherry picked from commit 3fce366a98adc5db0d127f28ddf3157d13297a0f) * refactor: build cuda12 instead of cuda tag (cherry picked from commit 217144ecd322356376f04efb92792a20b4380177) * docs: add note about CUDA tags to documentation * refactor: add default value for variant in build-test-upload * refactor: swap ordering of cuda11/cuda12 variants * refactor: remove optional str type in arg parser * fix: add proper env variables to CUDA Dockerfiles * fix: remove CUDA build for aarch64 * fix: use latest NVIDIA documentation link * fix: skip aarch64 tags file for CUDA variants --------- Co-authored-by: zynaa <7562909-zynaa@users.noreply.gitlab.com>
158 lines
4.6 KiB
Python
Executable File
158 lines
4.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) Jupyter Development Team.
|
|
# Distributed under the terms of the Modified BSD License.
|
|
import argparse
|
|
import datetime
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
from docker.models.containers import Container
|
|
|
|
from tagging.docker_runner import DockerRunner
|
|
from tagging.get_prefix import get_file_prefix, get_tag_prefix
|
|
from tagging.get_taggers_and_manifests import get_taggers_and_manifests
|
|
from tagging.git_helper import GitHelper
|
|
from tagging.manifests import ManifestHeader, ManifestInterface
|
|
|
|
LOGGER = logging.getLogger(__name__)
|
|
|
|
# We use a manifest creation timestamp, which happens right after a build
|
|
BUILD_TIMESTAMP = datetime.datetime.utcnow().isoformat()[:-7] + "Z"
|
|
MARKDOWN_LINE_BREAK = "<br />"
|
|
|
|
|
|
def write_build_history_line(
|
|
short_image_name: str,
|
|
registry: str,
|
|
owner: str,
|
|
hist_lines_dir: Path,
|
|
filename: str,
|
|
all_tags: list[str],
|
|
) -> None:
|
|
LOGGER.info("Appending build history line")
|
|
|
|
date_column = f"`{BUILD_TIMESTAMP}`"
|
|
image_column = MARKDOWN_LINE_BREAK.join(
|
|
f"`{registry}/{owner}/{short_image_name}:{tag_value}`" for tag_value in all_tags
|
|
)
|
|
commit_hash = GitHelper.commit_hash()
|
|
links_column = MARKDOWN_LINE_BREAK.join(
|
|
[
|
|
f"[Git diff](https://github.com/jupyter/docker-stacks/commit/{commit_hash})",
|
|
f"[Dockerfile](https://github.com/jupyter/docker-stacks/blob/{commit_hash}/images/{short_image_name}/Dockerfile)",
|
|
f"[Build manifest](./{filename})",
|
|
]
|
|
)
|
|
build_history_line = f"| {date_column} | {image_column} | {links_column} |"
|
|
hist_lines_dir.mkdir(parents=True, exist_ok=True)
|
|
(hist_lines_dir / f"{filename}.txt").write_text(build_history_line)
|
|
|
|
|
|
def write_manifest_file(
|
|
short_image_name: str,
|
|
registry: str,
|
|
owner: str,
|
|
manifests_dir: Path,
|
|
filename: str,
|
|
manifests: list[ManifestInterface],
|
|
container: Container,
|
|
) -> None:
|
|
manifest_names = [manifest.__class__.__name__ for manifest in manifests]
|
|
LOGGER.info(f"Using manifests: {manifest_names}")
|
|
|
|
markdown_pieces = [
|
|
ManifestHeader.create_header(short_image_name, registry, owner, BUILD_TIMESTAMP)
|
|
] + [manifest.markdown_piece(container) for manifest in manifests]
|
|
markdown_content = "\n\n".join(markdown_pieces) + "\n"
|
|
|
|
manifests_dir.mkdir(parents=True, exist_ok=True)
|
|
(manifests_dir / f"{filename}.md").write_text(markdown_content)
|
|
|
|
|
|
def write_manifest(
|
|
short_image_name: str,
|
|
registry: str,
|
|
owner: str,
|
|
variant: str,
|
|
hist_lines_dir: Path,
|
|
manifests_dir: Path,
|
|
) -> None:
|
|
LOGGER.info(f"Creating manifests for image: {short_image_name}")
|
|
taggers, manifests = get_taggers_and_manifests(short_image_name)
|
|
|
|
image = f"{registry}/{owner}/{short_image_name}:latest"
|
|
|
|
file_prefix = get_file_prefix(variant)
|
|
commit_hash_tag = GitHelper.commit_hash_tag()
|
|
filename = f"{file_prefix}-{short_image_name}-{commit_hash_tag}"
|
|
|
|
with DockerRunner(image) as container:
|
|
tags_prefix = get_tag_prefix(variant)
|
|
all_tags = [
|
|
tags_prefix + "-" + tagger.tag_value(container) for tagger in taggers
|
|
]
|
|
write_build_history_line(
|
|
short_image_name, registry, owner, hist_lines_dir, filename, all_tags
|
|
)
|
|
write_manifest_file(
|
|
short_image_name,
|
|
registry,
|
|
owner,
|
|
manifests_dir,
|
|
filename,
|
|
manifests,
|
|
container,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
arg_parser = argparse.ArgumentParser()
|
|
arg_parser.add_argument(
|
|
"--short-image-name",
|
|
required=True,
|
|
help="Short image name",
|
|
)
|
|
arg_parser.add_argument(
|
|
"--hist-lines-dir",
|
|
required=True,
|
|
type=Path,
|
|
help="Directory to save history line",
|
|
)
|
|
arg_parser.add_argument(
|
|
"--manifests-dir",
|
|
required=True,
|
|
type=Path,
|
|
help="Directory to save manifest file",
|
|
)
|
|
arg_parser.add_argument(
|
|
"--registry",
|
|
required=True,
|
|
type=str,
|
|
choices=["docker.io", "quay.io"],
|
|
help="Image registry",
|
|
)
|
|
arg_parser.add_argument(
|
|
"--owner",
|
|
required=True,
|
|
help="Owner of the image",
|
|
)
|
|
arg_parser.add_argument(
|
|
"--variant",
|
|
required=True,
|
|
help="Variant tag prefix",
|
|
)
|
|
args = arg_parser.parse_args()
|
|
|
|
LOGGER.info(f"Current build timestamp: {BUILD_TIMESTAMP}")
|
|
|
|
write_manifest(
|
|
args.short_image_name,
|
|
args.registry,
|
|
args.owner,
|
|
args.variant,
|
|
args.hist_lines_dir,
|
|
args.manifests_dir,
|
|
)
|