Skip to content

Commit

Permalink
Merge pull request #1232 from camptocamp/backport/1231-to-master
Browse files Browse the repository at this point in the history
[Backport master] Strip the alt tag name, simplify
  • Loading branch information
sbrunner authored Sep 12, 2023
2 parents 620d0da + 2fe2f50 commit 2415171
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 37 deletions.
33 changes: 10 additions & 23 deletions c2cciutils/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ def docker(
image_config: c2cciutils.configuration.PublishDockerImage,
tag_src: str,
tag_dst: str,
latest: bool,
alt_tags: list[str],
images_full: list[str],
) -> bool:
Expand Down Expand Up @@ -378,17 +377,6 @@ def docker(
check=True,
)
new_images_full.append(f"{config['server']}/{image_config['name']}:{tag_dst}")
if latest:
subprocess.run(
[
"docker",
"tag",
f"{image_config['name']}:{tag_src}",
f"{config['server']}/{image_config['name']}:{tag_src}",
],
check=True,
)
new_images_full.append(f"{config['server']}/{image_config['name']}:{tag_src}")
for alt_tag in alt_tags:
subprocess.run(
[
Expand All @@ -412,18 +400,17 @@ def docker(
check=True,
)
new_images_full.append(f"{image_config['name']}:{tag_dst}")
if latest and tag_src != tag_dst:
new_images_full.append(f"{image_config['name']}:{tag_src}")
for alt_tag in alt_tags:
subprocess.run(
[
"docker",
"tag",
f"{image_config['name']}:{tag_src}",
f"{image_config['name']}:{alt_tag}",
],
check=True,
)
if tag_src != alt_tag:
subprocess.run(
[
"docker",
"tag",
f"{image_config['name']}:{tag_src}",
f"{image_config['name']}:{alt_tag}",
],
check=True,
)
new_images_full.append(f"{image_config['name']}:{alt_tag}")

for image in new_images_full:
Expand Down
19 changes: 5 additions & 14 deletions c2cciutils/scripts/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ def main() -> None:
config.get("publish", {}).get("docker", {}) if config.get("publish", {}).get("docker", False) else {},
)
if docker_config:
latest = False
full_repo = c2cciutils.get_repository()
full_repo_split = full_repo.split("/")
master_branch, _ = c2cciutils.get_master_branch(full_repo_split)
Expand All @@ -216,18 +215,19 @@ def main() -> None:

security = c2cciutils.security.Security(security_text)
version_index = security.headers.index("Version")
latest = security.data[-1][version_index] == version

row_index = -1
for index, row in enumerate(security.data):
if row[version_index] == version:
row_index = index
break

alt_tags = []
alt_tags = set()
if "Alternate Tag" in security.headers:
tag_index = security.headers.index("Alternate Tag")
alt_tags = security.data[row_index][tag_index].split(",")
alt_tags = {t.strip() for t in security.data[row_index][tag_index].split(",")}
if security.data[-1][version_index] == version:
alt_tags.add("latest")

images_src: set[str] = set()
images_full: list[str] = []
Expand Down Expand Up @@ -285,22 +285,13 @@ def main() -> None:

if args.dry_run:
print(f"Publishing {image_dst} to {name}, skipping (dry run)")
if latest:
print(f"Publishing {image_source} to {name}, skipping (dry run)")
for alt_tag in current_alt_tag:
print(
f"Publishing {image_conf['name']}:{alt_tag} to {name}, skipping (dry run)"
)
else:
success &= c2cciutils.publish.docker(
conf,
name,
image_conf,
tag_src,
tag_dst,
latest,
current_alt_tag,
images_full,
conf, name, image_conf, tag_src, tag_dst, current_alt_tag, images_full
)

if google_calendar_publish:
Expand Down

0 comments on commit 2415171

Please sign in to comment.