Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 09a49cd

Browse files
authored
add ability to upgrade via renovate (#11)
Signed-off-by: Anurag <[email protected]>
1 parent abe8198 commit 09a49cd

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

hack/semver-upgrade.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2023 The Kubernetes Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
set -x
20+
21+
semver_upgrade() {
22+
IFS=. read -r version minor patch <<EOF
23+
$VERSION
24+
EOF
25+
26+
case "$1" in
27+
patch) tag="$version.$minor.$((patch+1))"; ;;
28+
major) tag="$((version+1)).0.0"; ;;
29+
*) tag="$version.$((minor+1)).0"; ;;
30+
esac
31+
32+
echo $tag
33+
}

hack/upgrade-builder-image.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2023 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This script is executed in the Update-Bot container.
18+
# It checks if the Dockerfile for the build container has changed.
19+
# If so, it uses the version of the main branch as the basis for creating a new image tag.
20+
# The script also checks if the image tag for the build image exists in the main branch.
21+
# We assume that only one branch and one PR will be created for the changes in the build container.
22+
# Therefore, we can update this branch as many times as we want and reuse the next available tag after the one from the main branch.
23+
24+
set -o errexit
25+
set -o nounset
26+
set -o pipefail
27+
28+
export BUILDER_IMAGE=ghcr.io/sovereigncloudstack/cspo-builder
29+
30+
REPO_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}")/..)
31+
cd "${REPO_ROOT}" || exit 1
32+
33+
source "${REPO_ROOT}/hack/semver-upgrade.sh"
34+
35+
if git diff --exit-code .builder-image-version.txt images/builder/Dockerfile images/builder/build.sh > /dev/null; then
36+
echo "nothing seems to have changed."
37+
exit 0
38+
fi
39+
40+
if [ "${CI:-false}" = true ] ; then
41+
echo "$BUILD_IMAGE_TOKEN" | docker login ghcr.io -u "$BUILD_IMAGE_USER" --password-stdin
42+
fi
43+
44+
VERSION=$(git fetch --quiet origin main && git show origin/main:.builder-image-version.txt)
45+
if [ -z "$VERSION" ]; then
46+
echo "failed to find BUILDER_IMAGE_VERSION in Makefile of origin/main branch"
47+
exit 1
48+
fi
49+
export VERSION
50+
51+
NEW_VERSION=$(semver_upgrade patch "$VERSION")
52+
export NEW_VERSION
53+
54+
if ! docker manifest inspect "$BUILDER_IMAGE:$VERSION" > /dev/null; then
55+
echo "could not find image $BUILDER_IMAGE:$VERSION"
56+
exit 1
57+
fi
58+
echo "$NEW_VERSION" > .builder-image-version.txt
59+
echo "Wrote new version $NEW_VERSION to .builder-image-version.txt"
60+
61+
if docker manifest inspect ghcr.io/sovereigncloudstack/cspo-builder:${NEW_VERSION} > /dev/null ; echo $?; then
62+
63+
sed -i -e "/^BUILDER_IMAGE_VERSION /s/:=.*$/:= ${NEW_VERSION}/" Makefile
64+
grep -r -E 'ghcr.io/sovereigncloudstack/cspo-builder:[0-9].*.*' -l | xargs sed -i -e "s/ghcr.io\/sovereigncloudstack\/cspo-builder:${VERSION}/ghcr.io\/sovereigncloudstack\/cspo-builder:${NEW_VERSION}/g"
65+
docker build -t ghcr.io/sovereigncloudstack/cspo-builder:${NEW_VERSION} ./images/builder
66+
docker push ghcr.io/sovereigncloudstack/cspo-builder:${NEW_VERSION}
67+
else
68+
exit 1
69+
fi

0 commit comments

Comments
 (0)