1#!/bin/bash 2 3# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY 4# 5# The original version of this file is located in the https://github.com/istio/common-files repo. 6# If you're looking at this file in a different repo and want to make a change, please go to the 7# common-files repo, make the change there and check it in. Then come back to this repo and run 8# "make update-common". 9 10# Copyright Istio Authors 11# 12# Licensed under the Apache License, Version 2.0 (the "License"); 13# you may not use this file except in compliance with the License. 14# You may obtain a copy of the License at 15# 16# http://www.apache.org/licenses/LICENSE-2.0 17# 18# Unless required by applicable law or agreed to in writing, software 19# distributed under the License is distributed on an "AS IS" BASIS, 20# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21# See the License for the specific language governing permissions and 22# limitations under the License. 23 24set -e 25 26LOCAL_ARCH=$(uname -m) 27export LOCAL_ARCH 28# Pass environment set target architecture to build system 29if [[ ${TARGET_ARCH} ]]; then 30 export TARGET_ARCH 31elif [[ ${LOCAL_ARCH} == x86_64 ]]; then 32 export TARGET_ARCH=amd64 33elif [[ ${LOCAL_ARCH} == armv8* ]]; then 34 export TARGET_ARCH=arm64 35elif [[ ${LOCAL_ARCH} == aarch64* ]]; then 36 export TARGET_ARCH=arm64 37elif [[ ${LOCAL_ARCH} == armv* ]]; then 38 export TARGET_ARCH=arm 39else 40 echo "This system's architecture, ${LOCAL_ARCH}, isn't supported" 41 exit 1 42fi 43 44LOCAL_OS=$(uname) 45export LOCAL_OS 46# Pass environment set target operating-system to build system 47if [[ ${TARGET_OS} ]]; then 48 export TARGET_OS 49elif [[ $LOCAL_OS == Linux ]]; then 50 export TARGET_OS=linux 51 readlink_flags="-f" 52elif [[ $LOCAL_OS == Darwin ]]; then 53 export TARGET_OS=darwin 54 readlink_flags="" 55else 56 echo "This system's OS, $LOCAL_OS, isn't supported" 57 exit 1 58fi 59 60# Build image to use 61if [[ "${IMAGE_VERSION:-}" == "" ]]; then 62 export IMAGE_VERSION=release-1.6-2020-05-08T22-06-04 63fi 64if [[ "${IMAGE_NAME:-}" == "" ]]; then 65 export IMAGE_NAME=build-tools 66fi 67 68export UID 69DOCKER_GID=$(grep '^docker:' /etc/group | cut -f3 -d:) 70export DOCKER_GID 71 72TIMEZONE=$(readlink $readlink_flags /etc/localtime | sed -e 's/^.*zoneinfo\///') 73export TIMEZONE 74 75export TARGET_OUT="${TARGET_OUT:-$(pwd)/out/${TARGET_OS}_${TARGET_ARCH}}" 76export TARGET_OUT_LINUX="${TARGET_OUT_LINUX:-$(pwd)/out/linux_amd64}" 77 78export CONTAINER_TARGET_OUT="${CONTAINER_TARGET_OUT:-/work/out/${TARGET_OS}_${TARGET_ARCH}}" 79export CONTAINER_TARGET_OUT_LINUX="${CONTAINER_TARGET_OUT_LINUX:-/work/out/linux_amd64}" 80 81export IMG="${IMG:-gcr.io/istio-testing/${IMAGE_NAME}:${IMAGE_VERSION}}" 82 83export CONTAINER_CLI="${CONTAINER_CLI:-docker}" 84 85export ENV_BLOCKLIST="${ENV_BLOCKLIST:-^_\|PATH\|SHELL\|EDITOR\|TMUX\|USER\|HOME\|PWD\|TERM\|GO\|rvm\|SSH\|TMPDIR\|CC\|CXX}" 86 87# Remove functions from the list of exported variables, they mess up with the `env` command. 88for f in $(declare -F -x | cut -d ' ' -f 3); 89do 90 unset -f "${f}" 91done 92 93# Set up conditional host mounts for docker and kubernetes config 94export CONDITIONAL_HOST_MOUNTS=${CONDITIONAL_HOST_MOUNTS:-} 95if [[ -d "${HOME}/.docker" ]]; then 96 CONDITIONAL_HOST_MOUNTS+="--mount type=bind,source=${HOME}/.docker,destination=/config/.docker,readonly " 97fi 98if [[ -d "${HOME}/.config/gcloud" ]]; then 99 CONDITIONAL_HOST_MOUNTS+="--mount type=bind,source=${HOME}/.config/gcloud,destination=/config/.config/gcloud,readonly " 100fi 101if [[ -d "${HOME}/.kube" ]]; then 102 CONDITIONAL_HOST_MOUNTS+="--mount type=bind,source=${HOME}/.kube,destination=/home/.kube " 103fi 104 105# Avoid recursive calls to make from attempting to start an additional container 106export BUILD_WITH_CONTAINER=0 107 108# For non container build, we need to write env to file 109if [[ "${1}" == "envfile" ]]; then 110 echo "TARGET_OUT_LINUX=${TARGET_OUT_LINUX}" 111 echo "TARGET_OUT=${TARGET_OUT}" 112 echo "TIMEZONE=${TIMEZONE}" 113 echo "LOCAL_OS=${LOCAL_OS}" 114 echo "TARGET_OS=${TARGET_OS}" 115 echo "LOCAL_ARCH=${LOCAL_ARCH}" 116 echo "TARGET_ARCH=${TARGET_ARCH}" 117 echo "BUILD_WITH_CONTAINER=0" 118fi 119