mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-12 12:32:58 +00:00
Add tags prefix support
This commit is contained in:
@@ -1,11 +0,0 @@
|
|||||||
# Copyright (c) Jupyter Development Team.
|
|
||||||
# Distributed under the terms of the Modified BSD License.
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def github_set_env(env_name: str, env_value: str) -> None:
|
|
||||||
if not os.environ.get("GITHUB_ACTIONS") or not os.environ.get("GITHUB_ENV"):
|
|
||||||
return
|
|
||||||
|
|
||||||
with open(os.environ["GITHUB_ENV"], "a") as f:
|
|
||||||
f.write(f"{env_name}={env_value}\n")
|
|
@@ -3,19 +3,24 @@
|
|||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import platform
|
||||||
|
|
||||||
import plumbum
|
import plumbum
|
||||||
|
|
||||||
from tagging.docker_runner import DockerRunner
|
from tagging.docker_runner import DockerRunner
|
||||||
from tagging.get_taggers_and_manifests import get_taggers_and_manifests
|
from tagging.get_taggers_and_manifests import get_taggers_and_manifests
|
||||||
from tagging.github_set_env import github_set_env
|
|
||||||
|
|
||||||
docker = plumbum.local["docker"]
|
docker = plumbum.local["docker"]
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def tag_image(short_image_name: str, owner: str) -> None:
|
def get_tags_prefix() -> str:
|
||||||
|
machine = platform.machine()
|
||||||
|
return "" if machine == "x86_64" else f"{machine}-"
|
||||||
|
|
||||||
|
|
||||||
|
def tag_image(short_image_name: str, owner: str, tags_prefix: str) -> None:
|
||||||
"""
|
"""
|
||||||
Tags <owner>/<short_image_name>:latest with the tags reported by all taggers
|
Tags <owner>/<short_image_name>:latest with the tags reported by all taggers
|
||||||
for the given image.
|
for the given image.
|
||||||
@@ -29,22 +34,19 @@ def tag_image(short_image_name: str, owner: str) -> None:
|
|||||||
image = f"{owner}/{short_image_name}:latest"
|
image = f"{owner}/{short_image_name}:latest"
|
||||||
|
|
||||||
with DockerRunner(image) as container:
|
with DockerRunner(image) as container:
|
||||||
tags = []
|
|
||||||
for tagger in taggers:
|
for tagger in taggers:
|
||||||
tagger_name = tagger.__class__.__name__
|
tagger_name = tagger.__class__.__name__
|
||||||
tag_value = tagger.tag_value(container)
|
tag_value = tagger.tag_value(container)
|
||||||
tags.append(tag_value)
|
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
f"Applying tag, tagger_name: {tagger_name} tag_value: {tag_value}"
|
f"Applying tag, tagger_name: {tagger_name} tag_value: {tag_value}"
|
||||||
)
|
)
|
||||||
docker["tag", image, f"{owner}/{short_image_name}:{tag_value}"]()
|
docker[
|
||||||
|
"tag", image, f"{owner}/{short_image_name}:{tags_prefix}{tag_value}"
|
||||||
if tags:
|
]()
|
||||||
env_name = f'{short_image_name.replace("-", "_")}_EXTRA_TAG_ARGS'
|
if tags_prefix != "":
|
||||||
docker_build_tag_args = " ".join(
|
LOGGER.info("Changing :latest tag to include tags_prefix")
|
||||||
[f"-t {owner}/{short_image_name}:{tag}" for tag in tags]
|
docker["tag", image, f"{owner}/{short_image_name}:{tags_prefix}latest"]()
|
||||||
)
|
docker["rmi", image]()
|
||||||
github_set_env(env_name, docker_build_tag_args)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -59,4 +61,7 @@ if __name__ == "__main__":
|
|||||||
arg_parser.add_argument("--owner", default="jupyter", help="Owner of the image")
|
arg_parser.add_argument("--owner", default="jupyter", help="Owner of the image")
|
||||||
args = arg_parser.parse_args()
|
args = arg_parser.parse_args()
|
||||||
|
|
||||||
tag_image(args.short_image_name, args.owner)
|
tags_prefix = get_tags_prefix()
|
||||||
|
LOGGER.info(f"Using: {tags_prefix=}")
|
||||||
|
|
||||||
|
tag_image(args.short_image_name, args.owner, tags_prefix)
|
||||||
|
Reference in New Issue
Block a user