-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall-dependencies.sh
executable file
·95 lines (76 loc) · 2.9 KB
/
install-dependencies.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
#!/bin/sh
set -eu
# This script must run in two modes:
#
# - When being used to set up a devcontainer.
# In this mode the code is not checked out yet,
# and we can install the tools globally.
#
# - When being used to install tools locally.
# In this mode the code is already checked out,
# and we do not want to pollute the user’s system.
#
# To distinguish between these modes we will
# have the devcontainer script pass an argument:
if [ "$1" = "devcontainer" ]; then
TOOL_DEST=/usr/local/bin
KUBEBUILDER_DEST=/usr/local/kubebuilder
else
TOOL_DEST=$(git rev-parse --show-toplevel)/hack/tools
mkdir -p "$TOOL_DEST"
KUBEBUILDER_DEST="$TOOL_DEST/kubebuilder"
fi
if ! command -v go > /dev/null 2>&1; then
echo "Go must be installed manually: https://golang.org/doc/install"
exit 1
fi
if ! command -v az > /dev/null 2>&1; then
echo "Azure CLI must be installed manually: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli"
exit 1
fi
echo "Installing tools to $TOOL_DEST"
# Install Go tools
TMPDIR=$(mktemp -d)
clean() {
chmod +w -R "$TMPDIR"
rm -rf "$TMPDIR"
}
trap clean EXIT
export GOBIN=$TOOL_DEST
export GOPATH=$TMPDIR
export GOCACHE=$TMPDIR/cache
export GO111MODULE=on
echo "Installing Go tools…"
# go tools for vscode are preinstalled by base image (see first comment in Dockerfile)
go get \
k8s.io/code-generator/cmd/[email protected] \
sigs.k8s.io/controller-tools/cmd/[email protected] \
sigs.k8s.io/[email protected] \
sigs.k8s.io/kustomize/kustomize/[email protected]
if [ "$1" != "devcontainer" ]; then
echo "Installing golangci-lint…"
# golangci-lint is provided by base image if in devcontainer
# this command copied from there
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$TOOL_DEST" 2>&1
fi
# Install go-task (task runner)
echo "Installing go-task…"
curl -sL "https://github.com/go-task/task/releases/download/v3.0.0/task_linux_amd64.tar.gz" | tar xz -C "$TOOL_DEST" task
# Install kubebuilder
os=$(go env GOOS)
arch=$(go env GOARCH)
echo "Installing kubebuilder ($os $arch)…"
#curl -L "https://go.kubebuilder.io/dl/2.3.1/${os}/${arch}" | tar -xz -C /tmp/
#mv "/tmp/kubebuilder_2.3.1_${os}_${arch}" "$KUBEBUILDER_DEST"
curl -L -o kubebuilder "https://go.kubebuilder.io/dl/latest/${os}/${arch}"
chmod +x kubebuilder && mv kubebuilder /usr/local/bin/
#chmod +x /tmp/kubebuilder && mv /tmp/kubebuilder "$KUBEBUILDER_DEST"
#curl -L -o /tmp/kubebuilder https://go.kubebuilder.io/dl/latest/$(go env GOOS)/$(go env GOARCH)
echo "Installed tools: $(ls "$TOOL_DEST")"
if [ "$1" = "devcontainer" ]; then
echo "Setting up k8s webhook certificates"
mkdir -p /tmp/k8s-webhook-server/serving-certs
openssl genrsa 2048 > tls.key
openssl req -new -x509 -nodes -sha256 -days 3650 -key tls.key -subj '/' -out tls.crt
mv tls.key tls.crt /tmp/k8s-webhook-server/serving-certs
fi