photoprism/scripts/build.sh

40 lines
1.4 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
if [[ -z $1 ]] || [[ -z $2 ]]; then
echo "Usage: ${0##*/} [debug|race|static|prod] [filename]" 1>&2
2021-12-15 14:56:47 +01:00
exit 1
fi
set -e
BUILD_OS=$(/bin/uname -s)
BUILD_ARCH=$("$(/usr/bin/dirname "$0")/dist/arch.sh")
BUILD_DATE=$(/bin/date -u +%y%m%d)
BUILD_VERSION=$(git describe --always)
BUILD_TAG=${BUILD_DATE}-${BUILD_VERSION}
BUILD_ID=${BUILD_TAG}-${BUILD_OS}-${BUILD_ARCH^^}
2022-03-01 18:16:50 +01:00
BUILD_NAME=${2:-photoprism}
GO_BIN=${GO_BIN:-/usr/local/go/bin/go}
GO_VER=$($GO_BIN version)
2022-02-17 19:18:37 +01:00
echo "Building PhotoPrism ${BUILD_ID} ($1)..."
2022-02-17 19:18:37 +01:00
if [[ $1 == "debug" ]]; then
BUILD_CMD=("$GO_BIN" build -ldflags "-X main.version=${BUILD_ID}-DEBUG" -o "${BUILD_NAME}" cmd/photoprism/photoprism.go)
elif [[ $1 == "race" ]]; then
BUILD_CMD=("$GO_BIN" build -race -ldflags "-X main.version=${BUILD_ID}-DEBUG" -o "${BUILD_NAME}" cmd/photoprism/photoprism.go)
2019-06-22 23:14:30 +02:00
elif [[ $1 == "static" ]]; then
BUILD_CMD=("$GO_BIN" build -a -v -ldflags "-linkmode external -extldflags \"-static -L /usr/lib -ltensorflow\" -s -w -X main.version=${BUILD_ID}" -o "${BUILD_NAME}" cmd/photoprism/photoprism.go)
else
BUILD_CMD=("$GO_BIN" build -ldflags "-extldflags \"-Wl,-rpath -Wl,\$ORIGIN/../lib\" -s -w -X main.version=${BUILD_ID}" -o "${BUILD_NAME}" cmd/photoprism/photoprism.go)
2019-06-22 23:14:30 +02:00
fi
2022-02-17 19:18:37 +01:00
# build binary
echo "=> compiling \"$BUILD_NAME\" with \"${GO_VER^}\""
echo "=> ${BUILD_CMD[*]}"
"${BUILD_CMD[@]}"
# show size
/usr/bin/du -h "${BUILD_NAME}"
2022-02-17 19:18:37 +01:00
echo "Done."