forked from fstab/grok_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·233 lines (204 loc) · 7.33 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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/bash
set -e
if [[ $(go version) != *"go1.11"* && $(go version) != *"go1.12"* ]] ; then
echo "grok_exporter uses Go 1.11 Modules. Please use Go version >= 1.11." >&2
echo "Version found is $(go version)" >&2
exit 1
fi
export GO111MODULE=on
#=======================================================================================
# 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.9-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 vet ./... && go test ./...
}
function create_vendor {
go mod vendor
}
function remove_vendor {
rm -fr ./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
}
function cleanup {
revert_legacy_static_linking
remove_vendor
}
# Make sure revert_legacy_static_linking is called even if a compile error makes this script terminate early
trap cleanup 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:/go/src/github.com/fstab/grok_exporter \
--net none \
--user $(id -u):$(id -g) \
--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:/go/src/github.com/fstab/grok_exporter \
--net none \
--user $(id -u):$(id -g) \
--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:/go/src/github.com/fstab/grok_exporter \
--net none \
--user $(id -u):$(id -g) \
--rm -ti fstab/grok_exporter-compiler-arm64v8 \
./compile-linux.sh -ldflags "$VERSION_FLAGS" -o "dist/grok_exporter-$VERSION.linux-arm64v8/grok_exporter"
}
function run_docker_linux_arm32v6 {
docker run \
-v $GOPATH/src/github.com/fstab/grok_exporter:/go/src/github.com/fstab/grok_exporter \
--net none \
--user $(id -u):$(id -g) \
--rm -ti fstab/grok_exporter-compiler-arm32v6 \
./compile-linux.sh -ldflags "$VERSION_FLAGS" -o "dist/grok_exporter-$VERSION.linux-arm32v6/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_linux_arm32v6 {
echo "Building dist/grok_exporter-$VERSION.linux-arm32v6.zip"
enable_legacy_static_linking
run_docker_linux_arm32v6
revert_legacy_static_linking
create_zip_file grok_exporter-$VERSION.linux-arm32v6
}
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"
if [ "$(uname)" != "Darwin" ]; then
echo "WARNING: Darwin releases can only be built on macOS." >&2
else
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
fi
}
#--------------------------------------------------------------
# main
#--------------------------------------------------------------
case $1 in
linux-amd64)
rm -rf dist/grok_exporter-*.linux-amd64*
run_tests
create_vendor
release_linux_amd64
remove_vendor
;;
linux-arm64v8)
rm -rf dist/grok_exporter-*.linux-arm64v8*
run_tests
create_vendor
release_linux_arm64v8
remove_vendor
;;
linux-arm32v6)
rm -rf dist/grok_exporter-*.linux-arm32v6*
run_tests
create_vendor
release_linux_arm32v6
remove_vendor
;;
darwin-amd64)
rm -rf dist/grok_exporter-*.darwin-amd64*
run_tests
create_vendor
release_darwin_amd64
remove_vendor
;;
windows-amd64)
rm -rf dist/grok_exporter-*.windows-amd64*
run_tests
create_vendor
release_windows_amd64
remove_vendor
;;
all-amd64)
rm -rf dist/grok_exporter-*.*-amd64*
run_tests
create_vendor
release_linux_amd64
release_darwin_amd64
release_windows_amd64
remove_vendor
;;
all)
rm -rf dist/grok_exporter-*
run_tests
create_vendor
release_linux_amd64
release_darwin_amd64
release_windows_amd64
release_linux_arm64v8
release_linux_arm32v6
remove_vendor
;;
*)
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 ' - linux-arm32v6' >&2
echo ' - all-amd64' >&2
echo ' - all' >&2
exit -1
esac