[ADD] add static build support

This commit is contained in:
barnett 2018-12-01 16:56:03 +08:00
parent 8ff39470d0
commit 842c01337a
3 changed files with 23 additions and 3 deletions

View File

@ -3,7 +3,7 @@ VERSION=master
WORK_DIR=/go/src/github.com/goodrain/rainbond
BASE_NAME=rainbond
BASE_DOCKER=./hack/contrib/docker
BIN_PATH=./_output/${VERSION}
BIN_PATH=./_output/${GOOS}/${VERSION}
default: help
all: image ## build linux binaries, build images for docker
@ -19,6 +19,12 @@ endif
ifeq ($(origin GOOS), undefined)
GOOS = darwin
endif
ifeq ($(origin STATIC), undefined)
STATIC = false
else
STATIC = true
endif
ifeq ($(origin PUSH), undefined)
PUSH = false
endif

View File

@ -81,7 +81,6 @@ func ParseClientCommnad(args []string) {
}
}
fmt.Println("client complete")
}
type controllerServiceClient struct {

View File

@ -31,13 +31,28 @@ function localbuild() {
done
else
echo "build local $1 ${VERSION}"
go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o _output/${GOOS}/${VERSION}/rainbond-$1 ./cmd/$1
outputname="_output/${GOOS}/${VERSION}/rainbond-$1"
if [ "$GOOS" = "windows" ];then
outputname="_output/${GOOS}/${VERSION}/rainbond-$1.exe"
fi
ldflags="-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}"
if [ "$STATIC" = "true" ];then
ldflags="${ldflags} -extldflags '-static'"
fi
go build -ldflags "${ldflags}" -o ${outputname} ./cmd/$1
fi
}
case $1 in
*)
prepare
if [ "$1" = "all" ];then
for item in ${build_items[@]}
do
localbuild $item
done
fi
localbuild $1
;;
esac