forked from kubesphere/kubekey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·35 lines (29 loc) · 1.32 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
#! /bin/bash
GIT_COMMIT=$(git rev-parse HEAD)
GIT_SHA=$(git rev-parse --short HEAD)
GIT_TAG=$(git describe --tags --abbrev=0 --exact-match 2>/dev/null )
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
VERSION_METADATA=unreleased
VERSION=latest
# Clear the "unreleased" string in BuildMetadata
if [[ -n $GIT_TAG ]]
then
VERSION_METADATA=
VERSION=${GIT_TAG}
fi
LDFLAGS="-X github.com/kubesphere/kubekey/version.version=${VERSION}
-X github.com/kubesphere/kubekey/version.metadata=${VERSION_METADATA}
-X github.com/kubesphere/kubekey/version.gitCommit=${GIT_COMMIT}
-X github.com/kubesphere/kubekey/version.gitTreeState=${GIT_DIRTY}"
if [ -n "$1" ]; then
if [ "$1" == "-p" ] || [ "$1" == "--proxy" ]; then
# Using the most trusted Go module proxy in China
docker run --rm -e GO111MODULE=on -e GOPROXY=https://goproxy.cn -e CGO_ENABLED=0 -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang:1.17 \
go build -tags='containers_image_openpgp' -ldflags "$LDFLAGS" -v -o output/kk ./cmd/main.go;
else
echo "The option should be '-p' or '--proxy'"
fi
else
docker run --rm -e CGO_ENABLED=0 -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang:1.17 \
go build -tags='containers_image_openpgp' -ldflags "$LDFLAGS" -v -o output/kk ./cmd/main.go;
fi