-
Notifications
You must be signed in to change notification settings - Fork 39
/
build.sh
executable file
·85 lines (73 loc) · 1.43 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
build() {
echo "Building"
build_windows
build_linux
build_docker $1
}
package() {
echo "Packaging"
package_windows $1
package_linux $1
}
clean() {
echo "Cleaning"
clean_windows
clean_linux
}
build_windows() {
echo "Building windows"
GOOS=windows GOARCH=amd64 go build .
}
package_windows() {
echo "Packaging windows"
version=$1
mkdir windows
mv bigip_exporter.exe windows/
cp LICENSE windows/
tar -zcvf bigip_exporter-$version.windows-amd64.tar.gz windows
}
clean_windows() {
echo "Cleaning windows"
rm -rf windows
}
build_linux() {
echo "Building linux"
GOOS=linux GOARCH=amd64 go build .
}
package_linux() {
echo "Packaging linux"
version=$1
mkdir linux
mv bigip_exporter linux/
cp LICENSE linux/
tar -zcvf bigip_exporter-$version.linux-amd64.tar.gz linux
}
clean_linux() {
echo "Cleaning linux"
rm -rf linux
}
fmt() {
find . -not -path "./vendor/*" -name "*.go" -exec go fmt {} \;
}
build_docker() {
version=$1
id=$(docker build . | awk 'END {print $3}')
if [[ $? != 0 ]]; then
echo "Docker build failed"
exit 1
fi
echo $id
docker tag $id expressenab/bigip_exporter:$version
docker tag $id expressenab/bigip_exporter:latest
docker push expressenab/bigip_exporter:$version
docker push expressenab/bigip_exporter:latest
}
if [[ $# == 0 ]]; then
echo "At least one argument is needed"
elif [[ $1 == "fmt" ]]; then
fmt
else
build $1
package $1
clean
fi