sigs.k8s.io/cluster-api@v1.7.1/hack/docker-image-verify.sh (about)

     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  
    20  _tmp="$(pwd)/_tmp"
    21  cleanup() {
    22    rm -rf "${_tmp}"
    23  }
    24  trap "cleanup" EXIT SIGINT
    25  cleanup
    26  mkdir -p "${_tmp}"
    27  
    28  function TESTIMAGE() {
    29    IMAGE="${1}"
    30    ARCH="${2}"
    31    GREPGOPATH="${3}"
    32    BINARYPATH="${4:-manager}"
    33  
    34    echo "> Testing $IMAGE"
    35  
    36    docker save "${IMAGE}" -o "${_tmp}"/img.tar
    37    mkdir -p "${_tmp}"/extracted-img "${_tmp}"/extracted
    38    tar -xf "${_tmp}"/img.tar -C "${_tmp}"/extracted-img/
    39    while IFS= read -r -d '' layer
    40    do
    41      tar -xf "${layer}" -C "${_tmp}"/extracted
    42    done <   <(find "${_tmp}"/extracted-img/ -name "*.tar" -print0)
    43  
    44    go version -m "${_tmp}"/extracted/"${BINARYPATH}" | grep -E $'\tpath' | grep -E -q -e "${GREPGOPATH}" || (echo "FAILED ${IMAGE} expected value for path: \"${GREPGOPATH}\""; go version -m "${_tmp}"/extracted/"${BINARYPATH}" | grep -E $'\tpath'; exit 1)
    45    go version -m "${_tmp}"/extracted/"${BINARYPATH}" | grep -q -E "GOARCH=${ARCH}$" || (echo "Failed ${IMAGE} expected GOARCH to be \"$ARCH\""; go version -m "${_tmp}"/extracted/"${BINARYPATH}" | grep "GOARCH="; exit 1)
    46  
    47    rm -rf "${_tmp}"/img.tar "${_tmp}"/extracted-img "${_tmp}"/extracted
    48  }
    49  
    50  for arch in ${ALL_ARCH}; do
    51    TESTIMAGE "${REGISTRY}/cluster-api-controller-${arch}:${TAG}" "${arch}" "sigs.k8s.io/cluster-api$"
    52    TESTIMAGE "${REGISTRY}/kubeadm-bootstrap-controller-${arch}:${TAG}" "${arch}" "sigs.k8s.io/cluster-api/bootstrap/kubeadm$"
    53    TESTIMAGE "${REGISTRY}/kubeadm-control-plane-controller-${arch}:${TAG}" "${arch}" "sigs.k8s.io/cluster-api/controlplane/kubeadm$"
    54    TESTIMAGE "${REGISTRY}/capd-manager-${arch}:${TAG}" "${arch}" "sigs.k8s.io/cluster-api/test/infrastructure/docker$"
    55    TESTIMAGE "${REGISTRY}/capim-manager-${arch}:${TAG}" "${arch}" "sigs.k8s.io/cluster-api/test/infrastructure/inmemory$"
    56    TESTIMAGE "${REGISTRY}/test-extension-${arch}:${TAG}" "${arch}" "sigs.k8s.io/cluster-api/test/extension$"
    57    TESTIMAGE "${REGISTRY}/clusterctl-${arch}:${TAG}" "${arch}" "sigs.k8s.io/cluster-api/cmd/clusterctl$" "clusterctl"
    58  done