-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
49 lines (42 loc) · 1.23 KB
/
build.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
#!/bin/bash
GIT_DESC=$(git describe --tags 2> /dev/null)
GIT_TAG=$(git describe --tags --abbrev=0 2> /dev/null)
GIT_COMMIT=$(git rev-parse HEAD)
GIT_COMMIT_SHORT=$(git rev-parse --short HEAD)
if [[ "$GIT_DESC" == "$GIT_TAG" ]]; then
BUILD_TYPE="stable"
BUILD_VERSION="$GIT_TAG"
else
BUILD_TYPE="dev"
BUILD_VERSION="${GIT_TAG}-dev_${GIT_COMMIT_SHORT}"
fi
if [[ -z "$BUILD_VERSION" ]]; then
BUILD_TYPE="dev"
BUILD_VERSION="dev_${GIT_COMMIT_SHORT}"
fi
if git status --porcelain | grep -E '(M|A|D|R|\?)' > /dev/null; then
BUILD_TYPE="dev-uncommitted"
BUILD_VERSION="${BUILD_VERSION}-uncommitted"
fi
cat << EOF
Build Args:
GIT_DESC=${GIT_DESC}
GIT_TAG=${GIT_TAG}
GIT_COMMIT=${GIT_COMMIT}
GIT_COMMIT_SHORT=${GIT_COMMIT_SHORT}
BUILD_TYPE=${BUILD_TYPE}
BUILD_VERSION=${BUILD_VERSION}
EOF
BUILD_FLAGS="-X main.Version=${BUILD_VERSION} -X main.BuildType=${BUILD_TYPE} -X main.BuildCommit=${GIT_COMMIT} -X main.BuildTime=$(date +%F-%Z/%T)"
echo ""
if [[ "$1" == "install" ]]; then
echo "Install kubewrap..."
CGO_ENABLED=0 go install -ldflags "${BUILD_FLAGS}"
else
echo "Build kubewrap..."
CGO_ENABLED=0 GOOS="$1" GOARCH="$2" go build -ldflags "${BUILD_FLAGS}" -o ./bin/kubewrap
fi
if [[ $? -ne 0 ]]; then
echo "Build kubewrap failed"
exit 1
fi