Skip to content

Commit 8fc97cb

Browse files
authored
Add tagging config to pass params easier (#2234)
* Add tagging config to pass params easier * Shorter function signatures
1 parent 18e09a7 commit 8fc97cb

File tree

15 files changed

+148
-205
lines changed

15 files changed

+148
-205
lines changed

.github/workflows/docker-build-test-upload.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
python3 -m tagging.apps.write_tags_file
8282
--registry ${{ env.REGISTRY }}
8383
--owner ${{ env.OWNER }}
84-
--short-image-name ${{ inputs.image }}
84+
--image ${{ inputs.image }}
8585
--variant ${{ inputs.variant }}
8686
--tags-dir /tmp/jupyter/tags/
8787
shell: bash
@@ -97,7 +97,7 @@ jobs:
9797
python3 -m tagging.apps.write_manifest
9898
--registry ${{ env.REGISTRY }}
9999
--owner ${{ env.OWNER }}
100-
--short-image-name ${{ inputs.image }}
100+
--image ${{ inputs.image }}
101101
--variant ${{ inputs.variant }}
102102
--hist-lines-dir /tmp/jupyter/hist_lines/
103103
--manifests-dir /tmp/jupyter/manifests/
@@ -133,5 +133,5 @@ jobs:
133133
python3 -m tests.run_tests
134134
--registry ${{ env.REGISTRY }}
135135
--owner ${{ env.OWNER }}
136-
--short-image-name ${{ inputs.image }}
136+
--image ${{ inputs.image }}
137137
shell: bash

.github/workflows/docker-merge-tags.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
if: env.PUSH_TO_REGISTRY == 'true'
7070
run: >
7171
python3 -m tagging.apps.merge_tags
72-
--short-image-name ${{ inputs.image }}
72+
--image ${{ inputs.image }}
7373
--variant ${{ inputs.variant }}
7474
--tags-dir /tmp/jupyter/tags/
7575
shell: bash

.github/workflows/docker-tag-push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
python3 -m tagging.apps.apply_tags
6666
--registry ${{ env.REGISTRY }}
6767
--owner ${{ env.OWNER }}
68-
--short-image-name ${{ inputs.image }}
68+
--image ${{ inputs.image }}
6969
--variant ${{ inputs.variant }}
7070
--platform ${{ inputs.platform }}
7171
--tags-dir /tmp/jupyter/tags/

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ build/%: ROOT_IMAGE?=ubuntu:24.04
4141
build/%: PYTHON_VERSION?=3.12
4242
build/%: ## build the latest image for a stack using the system's architecture
4343
docker build $(DOCKER_BUILD_ARGS) --rm --force-rm \
44-
--tag "$(REGISTRY)/$(OWNER)/$(notdir $@):latest" \
44+
--tag "$(REGISTRY)/$(OWNER)/$(notdir $@)" \
4545
"./images/$(notdir $@)" \
4646
--build-arg REGISTRY="$(REGISTRY)" \
4747
--build-arg OWNER="$(OWNER)" \
@@ -82,21 +82,21 @@ hook/%: ## run post-build hooks for an image
8282
python3 -m tagging.apps.write_tags_file \
8383
--registry "$(REGISTRY)" \
8484
--owner "$(OWNER)" \
85-
--short-image-name "$(notdir $@)" \
85+
--image "$(notdir $@)" \
8686
--variant "$(VARIANT)" \
8787
--tags-dir /tmp/jupyter/tags/
8888
python3 -m tagging.apps.write_manifest \
8989
--registry "$(REGISTRY)" \
9090
--owner "$(OWNER)" \
91-
--short-image-name "$(notdir $@)" \
91+
--image "$(notdir $@)" \
9292
--variant "$(VARIANT)" \
9393
--hist-lines-dir /tmp/jupyter/hist_lines/ \
9494
--manifests-dir /tmp/jupyter/manifests/ \
9595
--repository "$(REPOSITORY)"
9696
python3 -m tagging.apps.apply_tags \
9797
--registry "$(REGISTRY)" \
9898
--owner "$(OWNER)" \
99-
--short-image-name "$(notdir $@)" \
99+
--image "$(notdir $@)" \
100100
--variant "$(VARIANT)" \
101101
--platform "$(shell uname -m)" \
102102
--tags-dir /tmp/jupyter/tags/
@@ -139,5 +139,5 @@ test/%: ## run tests against a stack
139139
python3 -m tests.run_tests \
140140
--registry "$(REGISTRY)" \
141141
--owner "$(OWNER)" \
142-
--short-image-name "$(notdir $@)"
142+
--image "$(notdir $@)"
143143
test-all: $(foreach I, $(ALL_IMAGES), test/$(I)) ## test all stacks

tagging/apps/apply_tags.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,42 @@
22
# Copyright (c) Jupyter Development Team.
33
# Distributed under the terms of the Modified BSD License.
44
import logging
5-
from pathlib import Path
65

76
import plumbum
87

98
from tagging.apps.common_cli_arguments import common_arguments_parser
10-
from tagging.utils.get_platform import unify_aarch64
9+
from tagging.utils.config import Config
1110
from tagging.utils.get_prefix import get_file_prefix_for_platform
1211

1312
docker = plumbum.local["docker"]
1413

1514
LOGGER = logging.getLogger(__name__)
1615

1716

18-
def apply_tags(
19-
*,
20-
registry: str,
21-
owner: str,
22-
short_image_name: str,
23-
variant: str,
24-
platform: str,
25-
tags_dir: Path,
26-
) -> None:
17+
def apply_tags(config: Config) -> None:
2718
"""
28-
Tags <registry>/<owner>/<short_image_name>:latest with the tags reported by all taggers for this image
19+
Tags <config.full_image()> with the tags reported by all taggers for this image
2920
"""
30-
LOGGER.info(f"Tagging image: {short_image_name}")
21+
LOGGER.info(f"Tagging image: {config.image}")
3122

32-
file_prefix = get_file_prefix_for_platform(platform, variant)
33-
image = f"{registry}/{owner}/{short_image_name}:latest"
34-
filename = f"{file_prefix}-{short_image_name}.txt"
35-
tags = (tags_dir / filename).read_text().splitlines()
23+
file_prefix = get_file_prefix_for_platform(config.platform, config.variant)
24+
filename = f"{file_prefix}-{config.image}.txt"
25+
tags = (config.tags_dir / filename).read_text().splitlines()
3626

3727
for tag in tags:
3828
LOGGER.info(f"Applying tag: {tag}")
39-
docker["tag", image, tag] & plumbum.FG
29+
docker["tag", config.full_image(), tag] & plumbum.FG
4030

4131

4232
if __name__ == "__main__":
4333
logging.basicConfig(level=logging.INFO)
4434

45-
arg_parser = common_arguments_parser(
46-
registry=True, owner=True, short_image_name=True, variant=True, tags_dir=True
35+
config = common_arguments_parser(
36+
registry=True,
37+
owner=True,
38+
image=True,
39+
variant=True,
40+
platform=True,
41+
tags_dir=True,
4742
)
48-
arg_parser.add_argument(
49-
"--platform",
50-
required=True,
51-
type=str,
52-
choices=["x86_64", "aarch64", "arm64"],
53-
help="Image platform",
54-
)
55-
args = arg_parser.parse_args()
56-
args.platform = unify_aarch64(args.platform)
57-
58-
apply_tags(**vars(args))
43+
apply_tags(config)

tagging/apps/common_cli_arguments.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
import argparse
44
from pathlib import Path
55

6+
from tagging.utils.config import Config
7+
from tagging.utils.get_platform import unify_aarch64
8+
69

710
def common_arguments_parser(
811
*,
912
registry: bool = False,
1013
owner: bool = False,
11-
short_image_name: bool = False,
14+
image: bool = False,
1215
variant: bool = False,
16+
platform: bool = False,
1317
tags_dir: bool = False,
1418
hist_lines_dir: bool = False,
1519
manifests_dir: bool = False,
16-
) -> argparse.ArgumentParser:
20+
repository: bool = False,
21+
) -> Config:
1722
"""Add common CLI arguments to parser"""
1823

1924
parser = argparse.ArgumentParser()
@@ -30,9 +35,9 @@ def common_arguments_parser(
3035
required=True,
3136
help="Owner of the image",
3237
)
33-
if short_image_name:
38+
if image:
3439
parser.add_argument(
35-
"--short-image-name",
40+
"--image",
3641
required=True,
3742
help="Short image name",
3843
)
@@ -42,6 +47,14 @@ def common_arguments_parser(
4247
required=True,
4348
help="Variant tag prefix",
4449
)
50+
if platform:
51+
parser.add_argument(
52+
"--platform",
53+
required=True,
54+
type=str,
55+
choices=["x86_64", "aarch64", "arm64"],
56+
help="Image platform",
57+
)
4558
if tags_dir:
4659
parser.add_argument(
4760
"--tags-dir",
@@ -63,5 +76,14 @@ def common_arguments_parser(
6376
type=Path,
6477
help="Directory for manifests file",
6578
)
79+
if repository:
80+
parser.add_argument(
81+
"--repository",
82+
required=True,
83+
help="Repository name on GitHub",
84+
)
85+
args = parser.parse_args()
86+
if platform:
87+
args.platform = unify_aarch64(args.platform)
6688

67-
return parser
89+
return Config(**vars(args))

tagging/apps/merge_tags.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# Copyright (c) Jupyter Development Team.
33
# Distributed under the terms of the Modified BSD License.
44
import logging
5-
from pathlib import Path
65

76
import plumbum
87

98
from tagging.apps.common_cli_arguments import common_arguments_parser
9+
from tagging.utils.config import Config
1010
from tagging.utils.get_platform import ALL_PLATFORMS
1111
from tagging.utils.get_prefix import get_file_prefix_for_platform
1212

@@ -15,23 +15,18 @@
1515
LOGGER = logging.getLogger(__name__)
1616

1717

18-
def merge_tags(
19-
*,
20-
short_image_name: str,
21-
variant: str,
22-
tags_dir: Path,
23-
) -> None:
18+
def merge_tags(config: Config) -> None:
2419
"""
2520
Merge tags for x86_64 and aarch64 images when possible.
2621
"""
27-
LOGGER.info(f"Merging tags for image: {short_image_name}")
22+
LOGGER.info(f"Merging tags for image: {config.image}")
2823

2924
all_tags: set[str] = set()
3025

3126
for platform in ALL_PLATFORMS:
32-
file_prefix = get_file_prefix_for_platform(platform, variant)
33-
filename = f"{file_prefix}-{short_image_name}.txt"
34-
file_path = tags_dir / filename
27+
file_prefix = get_file_prefix_for_platform(platform, config.variant)
28+
filename = f"{file_prefix}-{config.image}.txt"
29+
file_path = config.tags_dir / filename
3530
if file_path.exists():
3631
tags = file_path.read_text().splitlines()
3732
all_tags.update(tag.replace(platform + "-", "") for tag in tags)
@@ -62,9 +57,5 @@ def merge_tags(
6257
if __name__ == "__main__":
6358
logging.basicConfig(level=logging.INFO)
6459

65-
arg_parser = common_arguments_parser(
66-
short_image_name=True, variant=True, tags_dir=True
67-
)
68-
args = arg_parser.parse_args()
69-
70-
merge_tags(**vars(args))
60+
config = common_arguments_parser(image=True, variant=True, tags_dir=True)
61+
merge_tags(config)

0 commit comments

Comments
 (0)