#!/usr/bin/env bash # Copyright 2017 The Kubernetes 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 TASK=$1 IMAGE=$2 KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE}")/../.." && pwd -P)" # Mapping of go ARCH to actual architectures shipped part of multiarch/qemu-user-static project declare -A QEMUARCHS=( ["amd64"]="x86_64" ["arm"]="arm" ["arm64"]="aarch64" ["ppc64le"]="ppc64le" ["s390x"]="s390x" ) # Returns list of all supported architectures from BASEIMAGE file listArchs() { cut -d "=" -f 1 ${IMAGE}/BASEIMAGE } # Returns baseimage need to used in Dockerfile for any given architecture getBaseImage() { arch=$1 echo $(grep "${arch}=" BASEIMAGE | cut -d= -f2) } # This function will build test image for all the architectures # mentioned in BASEIMAGE file. In the absence of BASEIMAGE file, # it will build for all the supported arch list - amd64, arm, # arm64, ppc64le, s390x build() { if [[ -f ${IMAGE}/BASEIMAGE ]]; then archs=$(listArchs) else archs=${!QEMUARCHS[@]} fi for arch in ${archs}; do echo "Building image for ${IMAGE} ARCH: ${arch}..." # Create a temporary directory for every architecture and copy the image content # and build the image from temporary directory temp_dir=$(mktemp -d) cp -r ${IMAGE}/* ${temp_dir} if [[ -f ${IMAGE}/Makefile ]]; then # make bin will take care of all the prerequisites needed # for building the docker image make -C ${IMAGE} bin ARCH=${arch} TARGET=${temp_dir} fi pushd ${temp_dir} # image tag TAG=$(