forked from yekaifeng/skylark
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild-binary.sh
executable file
·41 lines (34 loc) · 1021 Bytes
/
build-binary.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
#!/bin/bash -x
set -e
if [ $# != 2 ]
then
echo "usage: build-binary.sh source_directory version"
echo "example: ./build-binary.sh oam-docker-ipam 1.0.1"
echo "this script require these environemt: go, tar, bzip2"
echo "final product is the binary file in bin directory"
exit 1
fi
cwd=$(pwd)
source_dir=$1
version=$2
export GOPATH=$cwd
export GOBIN=$GOPATH/bin
rm -rf $GOBIN
rm -rf $GOPATH/src
rm -rf $GOPATH/pkg
mkdir -p $GOBIN
mkdir -p $GOPATH/src
go env
# copy go deps into src dir
echo "copying source ..."
cp -rf $GOPATH/$source_dir/Godeps/_workspace/src/* $GOPATH/src/
cp -rf $GOPATH/$source_dir $GOPATH/src
# envs
gitCommit=$(git rev-parse --short HEAD)
buildAt=$(date -u +%Y-%m-%d_%H:%M:%S)
pkg="oam-docker-ipam"
BUILD_FLAGS="-X $pkg/version.version=$version -X $pkg/version.gitCommit=${gitCommit} -X $pkg/version.buildAt=$buildAt -w -s"
# create version info
sed -i "s/1.0.0/$version/g" $GOPATH/src/$source_dir/main.go
# build
go build -a -ldflags "${BUILD_FLAGS}" -o bin/oam-docker-ipam $pkg