forked from harvester/harvester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·38 lines (30 loc) · 1.35 KB
/
build
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
#!/bin/bash
set -e
source $(dirname $0)/version
cd $(dirname $0)/..
mkdir -p bin
if [ "$(uname)" = "Linux" ]; then
OTHER_LINKFLAGS="-extldflags -static -s"
fi
# add coverage flags if there is no tag and it's on master or a version branch like v1.3
COMMIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
COMMIT_TAG=$(git tag --points-at HEAD | head -n 1)
if [[ "$COMMIT_TAG" == "" ]] && [[ "$COMMIT_BRANCH" == master || "$COMMIT_BRANCH" =~ ^v[0-9]+\.[0-9]+$ ]]; then
COVERPKG="-coverpkg=github.com/harvester/harvester/..."
COVER_FLAGS="-cover $COVERPKG"
fi
LINKFLAGS="-X github.com/harvester/harvester/pkg/version.Version=$VERSION
-X github.com/harvester/harvester/pkg/version.GitCommit=$COMMIT
-X github.com/harvester/harvester/pkg/settings.InjectDefaults=$DEFAULT_VALUES $LINKFLAGS"
build_binary () {
local BINARY="$1"
local PKG_PATH="$2"
CGO_ENABLED=0 go build -o "bin/${BINARY}" -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" $COVER_FLAGS "${PKG_PATH}"
if [ "$CROSS" = "true" ] && [ "$ARCH" = "amd64" ]; then
GOOS=darwin go build -ldflags "$LINKFLAGS" -o "bin/${BINARY}-darwin" "${PKG_PATH}"
GOOS=windows go build -ldflags "$LINKFLAGS" -o "bin/${BINARY}-windows" "${PKG_PATH}"
fi
}
build_binary "harvester" "."
build_binary "harvester-webhook" "./cmd/webhook"
build_binary "upgrade-helper" "./cmd/upgradehelper"