istio.io/istio@v0.0.0-20240520182934-d79c90f27776/tools/build-base-images.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright Istio 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 runs go tests in a package, but each test is run individually. This helps
    18  # isolate tests that are improperly depending on global state modification of other tests
    19  
    20  WD=$(dirname "$0")
    21  WD=$(cd "$WD"; pwd)
    22  ROOT=$(dirname "$WD")
    23  
    24  set -ex
    25  
    26  toJson () {
    27          python3 -c '
    28  import sys, yaml, json
    29  yml = list(y for y in yaml.safe_load_all(sys.stdin) if y)
    30  if len(yml) == 1: yml = yml[0]
    31  json.dump(yml, sys.stdout, indent=4)
    32  '
    33  }
    34  
    35  # shellcheck source=prow/lib.sh
    36  source "${ROOT}/prow/lib.sh"
    37  buildx-create
    38  
    39  HUBS="${HUBS:?specify a space separated list of hubs}"
    40  TAG="${TAG:?specify a tag}"
    41  defaultTargets="$(< "${ROOT}/tools/docker.yaml" toJson | toJson | jq '[.images[] | select(.base) | .name] | join(",")' -r)"
    42  DOCKER_TARGETS="${DOCKER_TARGETS:-${defaultTargets}}"
    43  
    44  # For multi architecture building:
    45  # See https://medium.com/@artur.klauser/building-multi-architecture-docker-images-with-buildx-27d80f7e2408 for more info
    46  # * docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
    47  # * docker buildx create --name multi-arch --platform linux/amd64,linux/arm64 --use
    48  # * export DOCKER_ARCHITECTURES="linux/amd64,linux/arm64"
    49  # Note: if you already have a container builder before running the qemu setup you will need to restart them
    50  "${ROOT}/tools/docker" --push --no-cache --no-clobber --targets="${DOCKER_TARGETS}"
    51  
    52  APKO_IMAGES=""
    53  for h in ${HUBS}; do
    54    for t in ${TAGS:-$TAG}; do
    55      APKO_IMAGES+="${h}/iptables:$t "
    56    done
    57  done
    58  
    59  # Build apko base image, which isn't part of our image building tool
    60  APKO_ARCHES="$(echo "${DOCKER_ARCHITECTURES:-arm64,amd64}" | sed 's/linux\///g')"
    61  # shellcheck disable=SC2086
    62  apko publish --arch="${APKO_ARCHES}" docker/iptables.yaml ${APKO_IMAGES}