Skip to content

Commit e2810b9

Browse files
committed
Add script to help bump ubi-minimal base image
I used this script to create three PRs for https://issues.redhat.com/browse/EC-1343 just now.
1 parent 53737e8 commit e2810b9

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

hack/ubi-base-image-bump.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
# Copyright The Conforma Contributors
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+
# SPDX-License-Identifier: Apache-2.0
17+
18+
#
19+
# Renovate should do be generating a PR for this automatically, but there
20+
# are times want to do it immediately, in which case you can use this script.
21+
#
22+
23+
set -o errexit
24+
set -o nounset
25+
set -o pipefail
26+
27+
# Find latest digest
28+
UBI_MINIMAL=registry.access.redhat.com/ubi9/ubi-minimal:latest
29+
NEW_DIGEST=$(skopeo inspect --raw docker://$UBI_MINIMAL | sha256sum | awk '{print $1}')
30+
echo "Found $UBI_MINIMAL:latest@$NEW_DIGEST"
31+
32+
# Update docker files
33+
DOCKER_FILES=(Dockerfile Dockerfile.dist)
34+
for d in "${DOCKER_FILES[@]}" ; do
35+
echo "Updating $d"
36+
sed -E "s!^FROM $UBI_MINIMAL@sha256:[0-9a-f]{64}\$!FROM $UBI_MINIMAL@sha256:$NEW_DIGEST!" -i $d
37+
done
38+
39+
[[ ${1:-""} == "--sed-only" ]] && exit
40+
41+
# Update rpms.lock.yaml maybe
42+
hack/update-rpm-lock.sh
43+
44+
[[ ${1:-""} == "--no-commit" ]] && exit
45+
46+
# Make a branch and a commit
47+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
48+
PR_BRANCH="ubi-bump-$CURRENT_BRANCH-$(date +%y%m%d%H%M%S)"
49+
git checkout -b $PR_BRANCH
50+
git add ${DOCKER_FILES[@]} rpms.lock.yaml
51+
git commit -m "chore(deps): Update ubi-minimal base image"
52+
53+
[[ ${1:-""} == "--no-push" ]] && exit
54+
55+
# Push the branch ready to make a PR
56+
git push origin $PR_BRANCH:$PR_BRANCH
57+
# Todo maybe: gh pr create ...
58+
echo ""
59+
echo "***********************************************************************"
60+
echo " Click the 'Create a pull request...' link above and create a PR."
61+
echo " Be careful to choose the correct target branch: $CURRENT_BRANCH"
62+
echo "***********************************************************************"

0 commit comments

Comments
 (0)