...

Text file src/sigs.k8s.io/gateway-api/hack/update-conformance-image-refs.sh

Documentation: sigs.k8s.io/gateway-api/hack

     1#!/bin/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
    18set -o errexit
    19set -o nounset
    20set -o pipefail
    21
    22# Wrap sed to deal with GNU and BSD sed flags.
    23run::sed() {
    24    local -r vers="$(sed --version < /dev/null 2>&1 | grep -q GNU && echo gnu || echo bsd)"
    25    case "$vers" in
    26        gnu) sed -i "$@" ;;
    27        *) sed -i '' "$@" ;;
    28esac
    29}
    30
    31IMAGES=(
    32  "${REGISTRY}/echo-advanced"
    33  "${REGISTRY}/echo-basic"
    34)
    35
    36# Export so we can use run::sed in subshells
    37# https://stackoverflow.com/questions/4321456/find-exec-a-shell-function-in-linux
    38export -f run::sed
    39
    40for IMAGE in ${IMAGES[@]}; do
    41  echo "Fetching latest tags for $IMAGE"
    42  TAG_FILE=$(mktemp)
    43  go run github.com/google/go-containerregistry/cmd/gcrane@latest ls "$IMAGE" --json \
    44    | jq -r '.tags[]' \
    45    | grep -v latest \
    46    | sort -rV \
    47    | head -n1 > "$TAG_FILE"
    48
    49  export REPO=${IMAGE#"${REGISTRY}"}
    50  export IMAGE_TAG=$(cat "$TAG_FILE")
    51  export IMAGE
    52  echo "Found tag $IMAGE_TAG - updating manifests..."
    53  find . -type f -name "*.yaml" -exec bash -c 'run::sed -e "s,image:.*${REPO}.*$,image: ${IMAGE}:${IMAGE_TAG},g" "$0"' {} \;
    54done
    55
    56

View as plain text