-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmake.sh
executable file
·185 lines (146 loc) · 6.37 KB
/
make.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
set -e
dev_profile="nerd-cli-dev"
function print_help {
printf "Available Commands:\n";
awk -v sq="'" '/^function run_([a-zA-Z0-9-]*)\s*/ {print "-e " sq NR "p" sq " -e " sq NR-1 "p" sq }' make.sh \
| while read line; do eval "sed -n $line make.sh"; done \
| paste -d"|" - - \
| sed -e 's/^/ /' -e 's/function run_//' -e 's/#//' -e 's/{/ /' \
| awk -F '|' '{ print " " $2 "\t" $1}' \
| expand -t 30
}
function run_build { #compile versioned executable and place it in $GOPATH/bin
go build \
-ldflags "-X main.version=$(cat VERSION) -X main.commit=$(git rev-parse --short HEAD )" \
-tags "forceposix" \
-o $GOPATH/bin/nerd \
main.go
}
function run_dev { #setup dev environment
command -v go >/dev/null 2>&1 || { echo "executable 'go' (the language sdk) must be installed" >&2; exit 1; }
command -v minikube >/dev/null 2>&1 || { echo "executable 'minikube' (local kubernetes cluster) must be installed" >&2; exit 1; }
command -v kubectl >/dev/null 2>&1 || { echo "executable 'kubectl' (kubernetes cli https://kubernetes.io/docs/tasks/tools/install-kubectl/) must be installed" >&2; exit 1; }
command -v glide >/dev/null 2>&1 || { echo "executable glide (https://github.com/Masterminds/glide) must be installed" >&2; exit 1; }
#develop against specific version and configure flex volume to reflect prod setup
kube_version="v1.8.0"
flexvolume_config="--extra-config=controller-manager.FlexVolumePluginDir=/var/lib/kubelet/volumeplugins/ --extra-config=kubelet.VolumePluginDir=/var/lib/kubelet/volumeplugins/"
if minikube status --profile=$dev_profile | grep Running; then
echo "--> minikube vm (profile: $dev_profile) is already running (check: $kube_version), skipping restart"
minikube profile $dev_profile
else
echo "--> starting minikube using the default 'vm-driver',to configure: https://github.com/kubernetes/minikube/issues/637)"
minikube start $flexvolume_config --profile=$dev_profile --kubernetes-version=$kube_version
echo "--> sleeping to let k8s initial setup take place"
sleep 10
fi
echo "--> setting up kube config"
kubectl config set-context $dev_profile --user=$dev_profile --cluster=$dev_profile --namespace=default && kubectl config use-context $dev_profile
echo "--> setting up custom resource definition for datasets"
kubectl apply -f crd/artifacts/datasets.yaml
echo "--> installing flex volume deamon set"
kubectl apply -f cmd/flex/dataset.yml
echo "--> updating dependencies"
glide install
rm -r vendor/k8s.io/apiextensions-apiserver/vendor
echo "--> checking crd generated code is valid"
if ./crd/hack/verify-codegen.sh; then
echo "--> crd code is up-to-date"
else
echo "--> regenerating code for crd"
./crd/hack/update-codegen.sh
fi
}
function run_docs { #run godoc
command -v go >/dev/null 2>&1 || { echo "executable 'go' (the language sdk) must be installed" >&2; exit 1; }
echo "--> starting godoc service (http://localhost:6060/pkg/github.com/nerdalize/nerd)"
godoc -v -http=":6060"
}
function run_test { #unit test project
command -v go >/dev/null 2>&1 || { echo "executable 'go' (the language sdk) must be installed" >&2; exit 1; }
echo "--> sourcing test.env"
export $(cat test.env | xargs)
echo "--> running library tests"
go test -cover -v ./pkg/...
echo "--> running service tests"
go test -cover -v ./svc/...
echo "--> running command tests"
go test -cover -v ./cmd/...
echo "--> updating specs.json"
go test -v
}
function run_specs { #update specs.json
echo "--> updating specs.json"
go test -v
}
function run_release { #cross compile new release builds
mkdir -p bin
gox -ldflags "-X main.version=$(cat VERSION) -X main.commit=$(git rev-parse --short HEAD )" -tags "forceposix" -osarch="linux/amd64 windows/amd64 darwin/amd64" -output=./bin/{{.OS}}_{{.Arch}}/nerd
}
function run_publish { #publish cross compiled binaries
run_specs
cd bin/darwin_amd64; tar -zcvf ../nerd-$(cat ../../VERSION)-macos.tar.gz nerd
cd ../linux_amd64; tar -zcvf ../nerd-$(cat ../../VERSION)-linux.tar.gz nerd
cd ../windows_amd64; zip ../nerd-$(cat ../../VERSION)-win.zip ./nerd.exe; cd ../..
git tag v`cat VERSION` || true
git push --tags
github-release release \
--user nerdalize \
--repo nerd \
--tag v`cat VERSION` \
--pre-release || true
github-release upload \
--user nerdalize \
--repo nerd \
--tag v`cat VERSION` \
--name nerd-$(cat VERSION)-macos.tar.gz \
--file bin/nerd-$(cat VERSION)-macos.tar.gz || true
github-release upload \
--user nerdalize \
--repo nerd \
--tag v`cat VERSION` \
--name nerd-$(cat VERSION)-linux.tar.gz \
--file bin/nerd-$(cat VERSION)-linux.tar.gz || true
github-release upload \
--user nerdalize \
--repo nerd \
--tag v`cat VERSION` \
--name nerd-$(cat VERSION)-win.zip \
--file bin/nerd-$(cat VERSION)-win.zip || true
}
function run_flexbuild { #build docker container
command -v docker >/dev/null 2>&1 || { echo "executable 'docker' (container runtime) must be installed" >&2; exit 1; }
echo "--> building flex volume container"
docker build -f flex.Dockerfile -t nerdalize/nerd-flex-volume:$(cat VERSION) .
}
function run_flexpush { #build and push docker container
command -v docker >/dev/null 2>&1 || { echo "executable 'docker' (container runtime) must be installed" >&2; exit 1; }
echo "--> publish flex volume container"
docker push nerdalize/nerd-flex-volume:$(cat VERSION)
}
function run_crdbuild { #build docker container for custom dataset controller
command -v docker >/dev/null 2>&1 || { echo "executable 'docker' (container runtime) must be installed" >&2; exit 1; }
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o controller ./crd/
echo "--> building crd controller container"
docker build -f crd/Dockerfile -t nerdalize/custom-dataset-controller:$(cat crd/VERSION) .
}
function run_crdpush { #build and push docker container for custom dataset controller
command -v docker >/dev/null 2>&1 || { echo "executable 'docker' (container runtime) must be installed" >&2; exit 1; }
echo "--> publish crd controller container"
docker push nerdalize/custom-dataset-controller:`cat crd/VERSION`
}
case $1 in
"build") run_build ;;
"dev") run_dev ;;
"docs") run_docs ;;
"test") run_test ;;
"gen") run_gen ;;
"release") run_release ;;
"publish") run_publish ;;
"specs") run_specs ;;
"flexbuild") run_flexbuild ;;
"flexpush") run_flexpush ;;
"crdbuild") run_crdbuild ;;
"crdpush") run_crdpush ;;
*) print_help ;;
esac