-
Notifications
You must be signed in to change notification settings - Fork 46
/
build.sh
executable file
·101 lines (85 loc) · 3.69 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
: '
Copyright 2021 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 -e
START_DIR=`pwd`
BUILD_FROM_SOURCE=0
VARIABLES_FILE="sync/shared/variables.yaml"
download_binaries () {
for bin in kubelet kube-proxy kubeadm kubectl
do
# windows binaries
curl "https://storage.googleapis.com/k8s-release-dev/ci/${KUBERNETES_VERSION}/bin/windows/amd64/${bin}.exe" -o $START_DIR/sync/windows/bin/${bin}.exe
# linux binaries
curl "https://storage.googleapis.com/k8s-release-dev/ci/${KUBERNETES_VERSION}/bin/linux/amd64/${bin}" -o $START_DIR/sync/linux/bin/${bin}; chmod +x $START_DIR/sync/linux/bin/${bin}
done
}
build_binaries () {
echo "building kube locally inside `pwd` from $1"
echo "changing into directory $1 to start the build"
pushd $1
echo "running docker build ~ checking memory, make sure its > 4G!!!"
if [[ `docker system info | grep Memory | cut -d' ' -f 4 |cut -d'.' -f 1` -gt 4 ]] || [[ `docker system info | grep memFree | cut -d' ' -f 4 |cut -d'.' -f 1` -gt 4000000000 ]]; then
echo "Proceeding with build, docker daemon memory is ok"
else
echo "Insufficient LOCAL memory to build k8s before the vagrant builder starts"
exit 1
fi
# use the kubernetes/build/run script to build specific targets...
./build/run.sh make kubelet KUBE_BUILD_PLATFORMS=windows/amd64
./build/run.sh make kube-proxy KUBE_BUILD_PLATFORMS=windows/amd64
./build/run.sh make kubeadm KUBE_BUILD_PLATFORMS=windows/amd64
./build/run.sh make kubelet KUBE_BUILD_PLATFORMS=linux/amd64
./build/run.sh make kubectl KUBE_BUILD_PLATFORMS=linux/amd64
./build/run.sh make kubeadm KUBE_BUILD_PLATFORMS=linux/amd64
}
copy_to_sync () {
# TODO replace with https://github.com/kubernetes-sigs/sig-windows-tools/issues/152 at some point
echo "Copying files to sync in ... $START_DIR"
# Windows binaries
cp -f ./_output/dockerized/bin/windows/amd64/kubelet.exe $START_DIR/sync/windows/bin
cp -f ./_output/dockerized/bin/windows/amd64/kube-proxy.exe $START_DIR/sync/windows/bin
cp -f ./_output/dockerized/bin/windows/amd64/kubeadm.exe $START_DIR/sync/windows/bin
# Linux binaries
cp -f ./_output/dockerized/bin/linux/amd64/kubelet $START_DIR/sync/linux/bin
cp -f ./_output/dockerized/bin/linux/amd64/kubectl $START_DIR/sync/linux/bin
cp -f ./_output/dockerized/bin/linux/amd64/kubeadm $START_DIR/sync/linux/bin
popd
}
cleanup () {
echo "Cleaning up the kubernetes directory"
pwd
rm -rf ../kubernetes
}
# Test if it should be build from source
[[
$(awk '/build_from_source/ {print $2}' ${VARIABLES_FILE} | sed -e 's/^"//' -e 's/"$//' | head -1) =~ "true"
]] && BUILD_FROM_SOURCE=1
mkdir -p $START_DIR/sync/windows/bin
mkdir -p $START_DIR/sync/linux/bin
# check if theres an input for the path
if [[ $BUILD_FROM_SOURCE -eq 1 ]] ;then
# Check if variable is set
if [ -z "$1" ]; then
echo "build_from_source is true but no path passed to the script, exiting."
exit 1
fi
echo "Directory Kubernetes provided... building"
build_binaries $1
copy_to_sync
cleanup
else
version=`awk '/kubernetes_version/ {print $2}' ${VARIABLES_FILE} | sed -e 's/^"//' -e 's/"$//' | head -1`
KUBERNETES_VERSION=`curl -f https://storage.googleapis.com/k8s-release-dev/ci/latest-${version}.txt`
download_binaries
fi