Skip to content

Commit

Permalink
chore: Update docker retag scripts (#9401)
Browse files Browse the repository at this point in the history
* update dockerhub image retagging scripts
  • Loading branch information
MikhailKardash authored May 21, 2024
1 parent 6ed2976 commit 18ee0e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
12 changes: 9 additions & 3 deletions tools/scripts/retag-bumpenvs-yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def run(old_tag: str, new_tag: str, yaml_path: str, release: bool) -> None:
for image_type in conf:
if old_tag not in conf[image_type]["new"]:
continue
elif ":" not in conf[image_type]["new"]:
# AMIS/GCP images do not contain :
continue
elif "environments:" in conf[image_type]["new"]:
# exempt legacy environments repo
continue

replace_image(conf[image_type], new_tag, release)

with open(yaml_path, "w") as f:
Expand All @@ -37,9 +44,8 @@ def replace_image(subconf: dict, new_tag: str, release: bool) -> None:
old_tag = subconf["new"].split(":")[-1]
subconf["old"] = subconf["new"]
if release:
subconf["new"] = subconf["new"].replace("-dev:" + old_tag, ":" + new_tag)
else:
subconf["new"] = subconf["new"].replace(old_tag, new_tag)
subconf["new"] = subconf["new"].replace("-dev:", ":")
subconf["new"] = subconf["new"].replace(old_tag, new_tag)


if __name__ == "__main__":
Expand Down
11 changes: 5 additions & 6 deletions tools/scripts/update-docker-tags.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Retags all docker images from latest Environments build
# tools/scripts/update-docker-tags.sh NEW_VERSION [--release]

if [ "$#" -lt 1 ] || [ "$2" != "--release" ] || [ "$#" -gt 2 ]; then
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ] || [ -n "$2" && "$2" != "--release" ]; then
echo "usage: $0 NEW_VERSION [--release]" >&2
exit 1
fi
Expand All @@ -18,14 +18,13 @@ export OLD_TAG=$(cat tools/scripts/environments-target.txt)
export NEW_TAG="$1"

# get list of images to replace via OLD_TAG in bumpenvs.yaml
export IMAGES=$(grep -oP "(?<=new: ).*(?=,)" tools/scripts/bumpenvs.yaml | grep -F $OLD_TAG)
export IMAGES=$(grep -oP "(?<=new: ).*(?=,)" tools/scripts/bumpenvs.yaml | grep -F :$OLD_TAG)

# update tags on dockerhub
for NAME in $IMAGES; do
NEW_NAME=${NAME%%:*}:$NEW_TAG
if [ "$2" == "--release" ]; then
export NEW_NAME="$(echo $NAME | grep -oP '.*(?=-dev:)'):$NEW_TAG"
else
export NEW_NAME="$(echo $NAME | grep -o '.*:')$NEW_TAG"
NEW_NAME=${NEW_NAME/-dev:/:}
fi
echo "Adding $NEW_NAME (clone of $NAME) to docker repo"
docker buildx imagetools create $NAME --tag $NEW_NAME
Expand All @@ -42,7 +41,7 @@ else
python tools/scripts/retag-bumpenvs-yaml.py tools/scripts/bumpenvs.yaml $OLD_TAG $NEW_TAG
fi
echo "Performing bumpenvs"
python -m tools/scripts/bumpenvs.py tools/scripts/bumpenvs.yaml
python tools/scripts/bumpenvs.py tools/scripts/bumpenvs.yaml

# check to see if update-docker-tags.py resulted in any file changes or not
if [[ -z "$(git status --porcelain)" ]]; then
Expand Down

0 comments on commit 18ee0e3

Please sign in to comment.