Skip to content

Commit 8afbe01

Browse files
committed
Handle attempts to push tag several times inside python
1 parent b89b5ec commit 8afbe01

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on:
1818
type: string
1919
timeout-minutes:
2020
description: Timeout in minutes
21-
default: 10
21+
default: 15
2222
type: number
2323
secrets:
2424
REGISTRY_USERNAME:
@@ -69,10 +69,6 @@ jobs:
6969

7070
- name: Merge tags for the images 🔀
7171
run: |
72-
python3 -m tagging.apps.merge_tags \
73-
--image ${{ inputs.image }} \
74-
--variant ${{ inputs.variant }} \
75-
--tags-dir /tmp/jupyter/tags/ || \
7672
python3 -m tagging.apps.merge_tags \
7773
--image ${{ inputs.image }} \
7874
--variant ${{ inputs.variant }} \

tagging/apps/merge_tags.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Distributed under the terms of the Modified BSD License.
44
import logging
55
import os
6+
import time
67

78
import plumbum
89

@@ -63,6 +64,25 @@ def pull_missing_tags(merged_tag: str, all_local_tags: list[str]) -> list[str]:
6364
return existing_platform_tags
6465

6566

67+
def push_manifest(merged_tag: str) -> None:
68+
ATTEMPTS = 3
69+
SLEEP_TIME = 5
70+
71+
LOGGER.info(f"Pushing manifest for tag: {merged_tag}")
72+
# Retry pushing the manifest up to ATTEMPTS times in case of failure
73+
for attempt in range(ATTEMPTS):
74+
try:
75+
docker["manifest", "push", merged_tag] & plumbum.FG
76+
break
77+
except plumbum.ProcessExecutionError as e:
78+
LOGGER.warning(f"Attempt {attempt + 1} to push manifest failed: {e}")
79+
if attempt + 1 == ATTEMPTS:
80+
LOGGER.error(f"Failed to push manifest after {ATTEMPTS} attempts")
81+
raise
82+
time.sleep(SLEEP_TIME)
83+
LOGGER.info(f"Successfully pushed manifest for tag: {merged_tag}")
84+
85+
6686
def merge_tags(
6787
merged_tag: str, all_local_tags: list[str], push_to_registry: bool
6888
) -> None:
@@ -84,9 +104,7 @@ def merge_tags(
84104
docker["manifest", "create", merged_tag][existing_platform_tags] & plumbum.FG
85105
LOGGER.info(f"Successfully created manifest for tag: {merged_tag}")
86106

87-
LOGGER.info(f"Pushing manifest for tag: {merged_tag}")
88-
docker["manifest", "push", merged_tag] & plumbum.FG
89-
LOGGER.info(f"Successfully merged and pushed tag: {merged_tag}")
107+
push_manifest(merged_tag)
90108
else:
91109
LOGGER.info(f"Skipping push for tag: {merged_tag}")
92110

0 commit comments

Comments
 (0)