forked from fstab/grok_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·159 lines (137 loc) · 5.31 KB
/
release.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
#!/bin/bash
set -e
#=======================================================================================
# This is supposed to run on OS X.
# The Darwin release is built natively, Linux and Windows are built in a Docker container
#========================================================================================
cd $GOPATH/src/github.com/fstab/grok_exporter
export VERSION=0.2.6-SNAPSHOT
export VERSION_FLAGS="\
-X github.com/fstab/grok_exporter/exporter.Version=$VERSION
-X github.com/fstab/grok_exporter/exporter.BuildDate=$(date +%Y-%m-%d)
-X github.com/fstab/grok_exporter/exporter.Branch=$(git rev-parse --abbrev-ref HEAD)
-X github.com/fstab/grok_exporter/exporter.Revision=$(git rev-parse --short HEAD)
"
#--------------------------------------------------------------
# Make sure all tests run.
#--------------------------------------------------------------
function run_tests {
go fmt $(go list ./... | grep -v /vendor/)
go test $(go list ./... | grep -v /vendor/)
}
#--------------------------------------------------------------
# Helper functions
#--------------------------------------------------------------
function enable_legacy_static_linking {
# The compile script in the Docker image sets CGO_LDFLAGS to libonig.a, which should make grok_exporter
# statically linked with the Oniguruma library. However, this doesn't work on Darwin and CentOS 6.
# As a workaround, we set LDFLAGS directly in the header of oniguruma.go.
sed -i.bak 's;#cgo LDFLAGS: -L/usr/local/lib -lonig;#cgo LDFLAGS: /usr/local/lib/libonig.a;' oniguruma/oniguruma.go
}
function revert_legacy_static_linking {
if [ -f oniguruma/oniguruma.go.bak ] ; then
mv oniguruma/oniguruma.go.bak oniguruma/oniguruma.go
fi
}
# Make sure revert_legacy_static_linking is called even if a compile error makes this script terminate early
trap revert_legacy_static_linking EXIT
function create_zip_file {
OUTPUT_DIR=$1
cp -a logstash-patterns-core/patterns dist/$OUTPUT_DIR
cp -a example dist/$OUTPUT_DIR
cd dist
sed -i.bak s,/logstash-patterns-core/patterns,/patterns,g $OUTPUT_DIR/example/*.yml
rm $OUTPUT_DIR/example/*.yml.bak
zip --quiet -r $OUTPUT_DIR.zip $OUTPUT_DIR
rm -r $OUTPUT_DIR
cd ..
}
function run_docker_linux_amd64 {
docker run \
-v $GOPATH/src/github.com/fstab/grok_exporter:/root/go/src/github.com/fstab/grok_exporter \
--net none \
--rm -ti fstab/grok_exporter-compiler-amd64 \
./compile-linux.sh -ldflags "$VERSION_FLAGS" -o "dist/grok_exporter-$VERSION.linux-amd64/grok_exporter"
}
function run_docker_windows_amd64 {
docker run \
-v $GOPATH/src/github.com/fstab/grok_exporter:/root/go/src/github.com/fstab/grok_exporter \
--net none \
--rm -ti fstab/grok_exporter-compiler-amd64 \
./compile-windows-amd64.sh -ldflags "$VERSION_FLAGS" -o "dist/grok_exporter-$VERSION.windows-amd64/grok_exporter.exe"
}
function run_docker_linux_arm64v8 {
docker run \
-v $GOPATH/src/github.com/fstab/grok_exporter:/root/go/src/github.com/fstab/grok_exporter \
--net none \
--rm -ti fstab/grok_exporter-compiler-arm64v8 \
./compile-linux.sh -ldflags "$VERSION_FLAGS" -o "dist/grok_exporter-$VERSION.linux-arm64v8/grok_exporter"
}
#--------------------------------------------------------------
# Release functions
#--------------------------------------------------------------
function release_linux_amd64 {
echo "Building dist/grok_exporter-$VERSION.linux-amd64.zip"
enable_legacy_static_linking
run_docker_linux_amd64
revert_legacy_static_linking
create_zip_file grok_exporter-$VERSION.linux-amd64
}
function release_linux_arm64v8 {
echo "Building dist/grok_exporter-$VERSION.linux-arm64v8.zip"
run_docker_linux_arm64v8
create_zip_file grok_exporter-$VERSION.linux-arm64v8
}
function release_windows_amd64 {
echo "Building dist/grok_exporter-$VERSION.windows-amd64.zip"
run_docker_windows_amd64
create_zip_file grok_exporter-$VERSION.windows-amd64
}
function release_darwin_amd64 {
echo "Building dist/grok_exporter-$VERSION.darwin-amd64.zip"
enable_legacy_static_linking
go build -ldflags "$VERSION_FLAGS" -o dist/grok_exporter-$VERSION.darwin-amd64/grok_exporter .
revert_legacy_static_linking
create_zip_file grok_exporter-$VERSION.darwin-amd64
}
#--------------------------------------------------------------
# main
#--------------------------------------------------------------
case $1 in
linux-amd64)
rm -rf dist/*
run_tests
release_linux_amd64
;;
linux-arm64v8)
rm -rf dist/*
run_tests
release_linux_arm64v8
;;
darwin-amd64)
rm -rf dist/*
run_tests
release_darwin_amd64
;;
windows-amd64)
rm -rf dist/*
run_tests
release_windows_amd64
;;
all-amd64)
rm -rf dist/*
run_tests
release_linux_amd64
release_darwin_amd64
release_windows_amd64
;;
*)
echo 'Usage: ./release.sh <arch>' >&2
echo 'where <arch> can be:' >&2
echo ' - linux-amd64' >&2
echo ' - darwin-amd64' >&2
echo ' - windows-amd64' >&2
echo ' - linux-arm64v8' >&2
echo ' - all-amd64' >&2
exit -1
esac