Skip to content

Commit 0d2fa86

Browse files
authored
Make refresh images github workflow push latest (#6208)
Signed-off-by: Jonathan Berkhahn <[email protected]> Signed-off-by: Jonathan Berkhahn <[email protected]>
1 parent a1b976e commit 0d2fa86

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

.github/workflows/freshen-images/build.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ while [[ $# -gt 0 ]]; do
3535
FORCE=1
3636
;;
3737
--tags)
38-
TAGS=$(echo $2 | sed -E 's/,/ /g')
38+
TAGS=($(echo $2 | sed -E 's/,/ /g'))
3939
shift
4040
;;
4141
--image-id)
@@ -83,15 +83,23 @@ ansible-operator)
8383
# ansible-operator has a base image that must be rebuilt in advance if necessary.
8484
# This script will detect that the base is fresh when inspecting ansible-operator's
8585
# Dockerfile and build it.
86-
for tag in $TAGS; do
87-
build_ansible_base $tag "$PLATFORMS"
86+
for i in ${!TAGS[*]}; do
87+
if (($i=0)); then
88+
build_ansible_base ${TAGS[$i]} "$PLATFORMS" true
89+
else
90+
build_ansible_base ${TAGS[$i]} "$PLATFORMS" false
91+
fi
8892
done
8993
;;
9094
esac
9195

9296
# Build the image defined by IMAGE_ID for each tag for a set of platforms.
93-
for tag in $TAGS; do
94-
build_generic $tag $IMAGE_ID "$PLATFORMS"
97+
for i in ${!TAGS[*]}; do
98+
if (($i=0)); then
99+
build_generic ${TAGS[$i]} $IMAGE_ID "$PLATFORMS" true
100+
else
101+
build_generic ${TAGS[$i]} $IMAGE_ID "$PLATFORMS" false
102+
fi
95103
done
96104

97105
popd

.github/workflows/freshen-images/lib.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ function is_dockerfile_fresh() {
5353
function build_ansible_base() {
5454
local tag=$1
5555
local platforms=$2
56+
local buildlatest=$3
5657
local dockerfile=./images/ansible-operator/base.Dockerfile
5758

59+
5860
git checkout refs/tags/$tag
5961
local ansible_base_image_tag=$(grep -oP 'FROM \K(quay\.io/operator-framework/ansible-operator-base:.+)' ./images/ansible-operator/Dockerfile)
6062
# Attempt to get the git ref that built this image from the git_commit image label,
@@ -69,8 +71,13 @@ function build_ansible_base() {
6971
echo "Skipping build of $dockerfile, it is FRESH!"
7072
else
7173
# dockerfile is not fresh, rebuildng image
72-
echo "Rebuilding image [$ansible_base_image_tag] for [$platforms]"
73-
_buildx --tag $ansible_base_image_tag --platform "$platforms" --file "$dockerfile" $IMAGE_DO --build-arg GIT_COMMIT=$ansible_base_git_ref ./images/ansible-operator
74+
if $buildlatest; then
75+
echo "Rebuilding image [$ansible_base_image_tag] and latest for [$platforms]"
76+
_buildx --tag $ansible_base_image_tag --tag quay.io/operator-framework/ansible-operator-base:latest --platform "$platforms" --file "$dockerfile" $IMAGE_DO --build-arg GIT_COMMIT=$ansible_base_git_ref ./images/ansible-operator
77+
else
78+
echo "Rebuilding image [$ansible_base_image_tag] for [$platforms]"
79+
_buildx --tag $ansible_base_image_tag --platform "$platforms" --file "$dockerfile" $IMAGE_DO --build-arg GIT_COMMIT=$ansible_base_git_ref ./images/ansible-operator
80+
fi
7481
fi
7582
}
7683

@@ -82,16 +89,23 @@ function build_generic() {
8289
local tag=$1
8390
local id=$2
8491
local platforms=$3
92+
local buildlatest=$4
8593
local tag_maj_min="quay.io/operator-framework/${id}:$(echo $tag | grep -Eo "v[1-9]+\.[0-9]+")"
8694
local tag_full="quay.io/operator-framework/${id}:${tag}"
95+
local tag_latest="quay.io/operator-framework/${id}:latest"
8796
local dockerfile=./images/${id}/Dockerfile
8897

8998
git checkout refs/tags/$tag
9099
if is_dockerfile_fresh "$dockerfile"; then
91100
echo "Skipping build of $dockerfile, it is FRESH!"
92101
else
93102
# dockerfile is not fresh, rebuildng image
94-
echo "Rebuilding image [$tag_maj_min] for [$platforms]"
95-
_buildx --builder=container --tag "$tag_maj_min" --tag "$tag_full" --platform "$platforms" --file "$dockerfile" $IMAGE_DO .
103+
if $buildlatest; then
104+
echo "Rebuilding image [$tag_maj_min] and latest for [$platforms]"
105+
_buildx --builder=container --tag "$tag_maj_min" --tag "$tag_full" --tag "$tag_latest" --platform "$platforms" --file "$dockerfile" $IMAGE_DO .
106+
else
107+
echo "Rebuilding image [$tag_maj_min] for [$platforms]"
108+
_buildx --builder=container --tag "$tag_maj_min" --tag "$tag_full" --platform "$platforms" --file "$dockerfile" $IMAGE_DO .
109+
fi
96110
fi
97111
}

0 commit comments

Comments
 (0)