| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
function printHelp() { |
| 4 |
>&2 echo "USAGE: $0 [-r] |
| 5 |
|
| 6 |
Untars the influxdb source tarball mounted at /influxdb-src.tar.gz, |
| 7 |
then emits a tarball of influxdb binaries to /out, |
| 8 |
which must be a mounted volume if you want to access the file. |
| 9 |
|
| 10 |
Relies upon environment variables GOOS and GOARCH to determine what to build. |
| 11 |
Respects CGO_ENABLED. |
| 12 |
|
| 13 |
To build with race detection enabled, pass the -r flag. |
| 14 |
" |
| 15 |
} |
| 16 |
|
| 17 |
RACE_FLAG="" |
| 18 |
|
| 19 |
while getopts hr arg; do |
| 20 |
case "$arg" in |
| 21 |
h) printHelp; exit 1;; |
| 22 |
r) RACE_FLAG="-race";; |
| 23 |
esac |
| 24 |
done |
| 25 |
|
| 26 |
|
| 27 |
if [ -z "$GOOS" ] || [ -z "$GOARCH" ]; then |
| 28 |
>&2 echo 'The environment variables $GOOS and $GOARCH must both be set.' |
| 29 |
exit 1 |
| 30 |
fi |
| 31 |
|
| 32 |
|
| 33 |
# Extract tarball into GOPATH. |
| 34 |
tar xz -C "$GOPATH" -f /influxdb-src.tar.gz |
| 35 |
|
| 36 |
SHA=$(jq -r .sha < "$GOPATH/src/github.com/influxdata/influxdb/.metadata.json") |
| 37 |
|
| 38 |
|
| 39 |
SUFFIX= |
| 40 |
if [ "$CGO_ENABLED" == "0" ]; then |
| 41 |
# Only add the static suffix to the filename when explicitly requested. |
| 42 |
SUFFIX=_static |
| 43 |
elif [ -n "$RACE_FLAG" ]; then |
| 44 |
# -race depends on cgo, so this option is exclusive from CGO_ENABLED. |
| 45 |
SUFFIX=_race |
| 46 |
fi |
| 47 |
|
| 48 |
TARBALL_NAME="influxdb_bin_${GOOS}_${GOARCH}${SUFFIX}-${SHA}.tar.gz" |
| 49 |
|
| 50 |
# note: according to https://github.com/golang/go/wiki/GoArm |
| 51 |
# we want to support armel using GOARM=5 |
| 52 |
# and we want to support armhf using GOARM=6 |
| 53 |
# no GOARM setting is necessary for arm64 |
| 54 |
if [ $GOARCH == "armel" ]; then |
| 55 |
GOARCH=arm |
| 56 |
GOARM=5 |
| 57 |
fi |
| 58 |
|
| 59 |
if [ $GOARCH == "armhf" ]; then |
| 60 |
GOARCH=arm |
| 61 |
GOARM=6 |
| 62 |
fi |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
OUTDIR=$(mktemp -d) |
| 67 |
for cmd in \ |
| 68 |
influxdb/cmd/influxd \ |
| 69 |
influxdb/cmd/influx_stress \ |
| 70 |
influxdb/cmd/influx \ |
| 71 |
influxdb/cmd/influx_inspect \ |
| 72 |
influxdb/cmd/influx_tsm \ |
| 73 |
; do |
| 74 |
# Build all the binaries into $OUTDIR. |
| 75 |
# Windows binaries will get the .exe suffix as expected. |
| 76 |
(cd "$OUTDIR" && go build $RACE_FLAG -i "github.com/influxdata/$cmd") |
| 77 |
done |
| 78 |
|
| 79 |
|
| 80 |
(cd "$OUTDIR" && tar czf "/out/$TARBALL_NAME" ./*) |
| 81 |
(cd /out && md5sum "$TARBALL_NAME" > "$TARBALL_NAME.md5") |
| 82 |
(cd /out && sha256sum "$TARBALL_NAME" > "$TARBALL_NAME.sha256") |