#!/bin/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 global TASK := $1 global IMAGE := $2 global KUBE_ROOT := $[cd "$[dirname $(BASH_SOURCE)]/../.." && pwd -P]TODO # 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 proc listArchs { cut -d "=" -f 1 $(IMAGE)/BASEIMAGE } # Returns baseimage need to used in Dockerfile for any given architecture proc getBaseImage { global 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 proc build { if [[ -f ${IMAGE}/BASEIMAGE ]] { global archs := $[listArchs] } else { global archs := $(!QEMUARCHS[@]) } for arch in [$(archs)] { 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 global temp_dir := $[mktemp -d] cp -r $(IMAGE)/* $(temp_dir) if [[ -f ${IMAGE}/Makefile ]] { # make bin will take care of all the prerequisites needed # for building the docker image make -C $(IMAGE) bin ARCH=$(arch) TARGET=$(temp_dir) } pushd $(temp_dir) # image tag global TAG := $[ spids: [76 84] ) (/../..) ) } ) (C {(pwd)} {(-P)}) ] op_id: Op_DAmp ) ] ) left_token: spids: [72 93] ) ) } spids: [70] ) ] spids: [70] ) (Assignment keyword: Assign_Declare flags: ["'-A'"] pairs: [ (assign_pair lhs: (LhsName name:QEMUARCHS) op: Equal rhs: { (ArrayLiteralPart words: [ {(Lit_Other "[") (DQ (amd64)) (Lit_Other "]") (Lit_Other "=") (DQ (x86_64))} {(Lit_Other "[") (DQ (arm)) (Lit_Other "]") (Lit_Other "=") (DQ (arm))} {(Lit_Other "[") (DQ (arm64)) (Lit_Other "]") (Lit_Other "=") (DQ (aarch64))} {(Lit_Other "[") (DQ (ppc64le)) (Lit_Other "]") (Lit_Other "=") (DQ (ppc64le))} {(Lit_Other "[") (DQ (s390x)) (Lit_Other "]") (Lit_Other "=") (DQ (s390x))} ] ) } spids: [104] ) ] spids: [100] ) (FuncDef name: listArchs body: (BraceGroup children: [(C {(cut)} {(-d)} {(DQ ("="))} {(-f)} {(1)} {(${ VSub_Name IMAGE) (/BASEIMAGE)})] spids: [167] ) spids: [163 166] ) (FuncDef name: getBaseImage body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:arch) op: Equal rhs: {($ VSub_Number "$1")} spids: [200] ) ] spids: [200] ) (C {(echo)} { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(grep)} {(DQ (${ VSub_Name arch) ("="))} {(BASEIMAGE)}) (C {(cut)} {(-d) (Lit_Other "=")} {(-f2)}) ] negated: False ) ] ) left_token: spids: [206 226] ) } ) ] spids: [197] ) spids: [193 196] ) (FuncDef name: build body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_f child:{(${ VSub_Name IMAGE) (/BASEIMAGE)}) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:archs) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(listArchs)})]) left_token: spids: [268 270] ) } spids: [267] ) ] spids: [267] ) ] spids: [-1 264] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:archs) op: Equal rhs: { (BracedVarSub token: prefix_op: VSub_Bang bracket_op: (WholeArray op_id:Lit_At) spids: [277 283] ) } spids: [276] ) ] spids: [276] ) ] spids: [273 286] ) (ForEach iter_name: arch iter_words: [{(${ VSub_Name archs)}] do_arg_iter: False body: (DoGroup children: [ (C {(echo)} { (DQ ("Building image for ") (${ VSub_Name IMAGE) (" ARCH: ") (${ VSub_Name arch) (...) ) } ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:temp_dir) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(mktemp)} {(-d)})]) left_token: spids: [329 333] ) } spids: [328] ) ] spids: [328] ) (C {(cp)} {(-r)} {(${ VSub_Name IMAGE) (/) (Lit_Other "*")} {(${ VSub_Name temp_dir)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_f child: {(${ VSub_Name IMAGE) (/Makefile)} ) ) terminator: ) ] action: [ (C {(make)} {(-C)} {(${ VSub_Name IMAGE)} {(bin)} {(Lit_VarLike "ARCH=") (${ VSub_Name arch)} {(Lit_VarLike "TARGET=") (${ VSub_Name temp_dir)} ) ] spids: [-1 365] ) ] spids: [-1 397] ) (C {(pushd)} {(${ VSub_Name temp_dir)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TAG) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (SimpleCommand redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(VERSION)} spids: [413] ) ] ) ] ) left_token: spids: [412 415] ) } spids: [411] ) ] spids: [411] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr:(BoolUnary op_id:BoolUnary_f child:{(BASEIMAGE)})) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:BASEIMAGE) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(getBaseImage)} {(${ VSub_Name arch)})] ) left_token: spids: [434 440] ) } spids: [433] ) ] spids: [433] ) (C {(sed)} {(-i)} {(DQ ("s|BASEIMAGE|") (${ VSub_Name BASEIMAGE) ("|g"))} {(Dockerfile)} ) ] spids: [-1 430] ) ] spids: [-1 458] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (WordTest w: { (CommandSubPart command_list: (CommandList children: [ (C {(grep)} {(DQ (CROSS_BUILD_))} {(Dockerfile)}) ] ) left_token: spids: [470 478] ) } ) ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ (${ VSub_Name arch))} right: {(DQ (amd64))} ) ) terminator: ) ] action: [(C {(sed)} {(-i)} {(DQ (/CROSS_BUILD_/d))} {(Dockerfile)})] spids: [-1 505] ) ] else_action: [ (C {(sed)} {(-i)} { (DQ ("s|QEMUARCH|") (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$arch")}) ) spids: [528 533] ) ("|g") ) } {(Dockerfile)} ) (C {(docker)} {(run)} {(--rm)} {(--privileged)} {(multiarch/qemu-user-static) (Lit_Other ":") (register)} {(--reset)} ) (Pipeline children: [ (C {(curl)} {(-sSL)} {(https) (Lit_Other ":") ( //github.com/multiarch/qemu-user-static/releases/download/ ) (${ VSub_Name QEMUVERSION) (/x86_64_qemu-) (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$arch")}) ) spids: [570 575] ) (-static.tar.gz) } ) (C {(tar)} {(-xz)} {(-C)} {(${ VSub_Name temp_dir)}) ] negated: False ) (C {(sed)} {(-i)} {(DQ (s/CROSS_BUILD_//g))} {(Dockerfile)}) ] spids: [519 602] ) ] spids: [-1 483] ) ] spids: [-1 605] ) (C {(docker)} {(build)} {(--pull)} {(-t)} {(${ VSub_Name REGISTRY) (/) (${ VSub_Name IMAGE) (-) (${ VSub_Name arch) (Lit_Other ":") (${ VSub_Name TAG) } {(.)} ) (C {(popd)}) ] spids: [301 640] ) spids: [295 299] ) ] spids: [247] ) spids: [243 246] ) (FuncDef name: push body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_f child:{(${ VSub_Name IMAGE) (/BASEIMAGE)}) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:archs) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(listArchs)})]) left_token: spids: [673 675] ) } spids: [672] ) ] spids: [672] ) ] spids: [-1 669] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:archs) op: Equal rhs: { (BracedVarSub token: prefix_op: VSub_Bang bracket_op: (WholeArray op_id:Lit_At) spids: [682 688] ) } spids: [681] ) ] spids: [681] ) ] spids: [678 691] ) (ForEach iter_name: arch iter_words: [{(${ VSub_Name archs)}] do_arg_iter: False body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TAG) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (SimpleCommand redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(${ VSub_Name IMAGE) (/VERSION)} spids: [710] ) ] ) ] ) left_token: spids: [709 715] ) } spids: [708] ) ] spids: [708] ) (C {(gcloud)} {(docker)} {(--)} {(push)} {(${ VSub_Name REGISTRY) (/) (${ VSub_Name IMAGE) (-) (${ VSub_Name arch) (Lit_Other ":") (${ VSub_Name TAG) } ) ] spids: [705 743] ) spids: [699 703] ) ] spids: [652] ) spids: [648 651] ) (FuncDef name: bin body: (BraceGroup children: [ (ForEach iter_name: SRC iter_words: [{($ VSub_At "$@")}] do_arg_iter: False body: (DoGroup children: [ (C {(docker)} {(run)} {(--rm)} {(-it)} {(-v)} {(${ VSub_Name TARGET) (Lit_Other ":") (${ VSub_Name TARGET) (Lit_Other ":") (Z)} {(-v)} {(${ VSub_Name KUBE_ROOT) (Lit_Other ":") (/go/src/k8s.io/kubernetes) (Lit_Other ":") (Z)} {(golang) (Lit_Other ":") (${ VSub_Name GOLANG_VERSION)} {(/bin/bash)} {(-c)} { (DQ (" cd /go/src/k8s.io/kubernetes/test/images/") (${ VSub_Name SRC_DIR) (" && ") (" CGO_ENABLED=0 GOARM=") (${ VSub_Name GOARM) (" GOARCH=") (${ VSub_Name ARCH) (" go build -a -installsuffix cgo --ldflags '-w' -o ") (${ VSub_Name TARGET) (/) (${ VSub_Name SRC) (" ./") (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(${ VSub_Name SRC)})] ) left_token: spids: [840 846] ) ) } ) ] spids: [768 850] ) spids: [763 765] ) ] spids: [755] ) spids: [751 754] ) (C {(shift)}) (C {(eval)} {(${ VSub_Name TASK)} {(DQ ($ VSub_At "$@"))}) ] )