Skip to content

Commit

Permalink
add upgrade-base-images script
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
  • Loading branch information
inteon committed Jul 10, 2024
1 parent 7706dc0 commit 9f53093
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ FORCE:
patch-go-version:
@./scripts/patch_go_version.sh

.PHONY: upgrade-base-images
upgrade-base-images:
@CRANE="crane" \
./scripts/upgrade_base_images.sh

## SHA learning targets

.PHONY: learn-tools-shas
Expand All @@ -53,6 +58,7 @@ help: ## Show this help
@echo "Usage: make [target] ..."
@echo
@echo "make patch-go-version"
@echo "make upgrade-base-images"
@echo
@echo "make learn-tools-shas"
@echo "make learn-image-shas"
63 changes: 63 additions & 0 deletions scripts/upgrade_base_images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

# Copyright 2022 The cert-manager Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

# This script updates all found occurances of the base images listed below
# it automatically fetches the latest digest for these images.

base_images=(
"quay.io/jetstack/base-static"
"quay.io/jetstack/base-static-csi"
)

if [ -z "$CRANE" ]; then
echo "CRANE is not set"
exit 1
fi

# Find latest digests for each base image
learn_data=()

for image in "${base_images[@]}"; do
replace=$($CRANE digest "$image:latest")

learn_data+=("s|$image@.*$|$image@$replace|g")
done

# Update all files with the new digests

script_dir=$(dirname "$(realpath "$0")")

pushd "${script_dir}/.." > /dev/null

# see https://stackoverflow.com/a/53408233
sed_args='-i'''
if [[ $(uname -s) == "Darwin" ]]; then
sed_args=(-i '')
fi

module_files=$(find ./modules/ -maxdepth 2 -name "00_mod.mk" -type f)

for replace in "${learn_data[@]}"; do
for file in $module_files; do
sed "${sed_args[@]}" "$replace" "$file";
done
done

popd

0 comments on commit 9f53093

Please sign in to comment.