forked from sorintlab/stolon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build
executable file
·81 lines (66 loc) · 2.24 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
set -e
# Cross compatibility with osx
# origin source: https://github.com/kubernetes/kubernetes/blob/master/hack/lib/init.sh#L102
function readlinkdashf() {
# run in a subshell for simpler 'cd'
(
if [[ -d "$1" ]]; then # This also catch symlinks to dirs.
cd "$1"
pwd -P
else
cd $(dirname "$1")
local f
f=$(basename "$1")
if [[ -L "$f" ]]; then
readlink "$f"
else
echo "$(pwd -P)/${f}"
fi
fi
)
}
BASEDIR=$(readlinkdashf $(dirname $0))
BINDIR=${BASEDIR}/bin
if [ $PWD != $BASEDIR ]; then
cd $BASEDIR
fi
ORG_PATH="github.com/sorintlab"
REPO_PATH="${ORG_PATH}/stolon"
mkdir -p ${BINDIR}
VERSION=${STOLON_VERSION:-$(${BASEDIR}/scripts/git-version.sh)}
LD_FLAGS="-s -X ${REPO_PATH}/cmd.Version=$VERSION"
# for static compilation we need to compile with cgo disabled (CGO_ENABLED=0),
# this will trigger a rebuild of all the packages and also the go std library
# (using a different install suffix called `cgo`, will use this since it's the
# name used by many projects but IMHO it's misleading...).
# If the user has write access to the go distribution pkg dir we can use "go
# install". If not possible we have to use `go build` which is slower since
# it'll rebuild every needed package everytime.
use_go_install=
go_root_dir=$(go env GOROOT)
go_host_os=$(go env GOHOSTOS)
go_host_arch=$(go env GOHOSTARCH)
cgodisabled_pkg_dir=${go_root_dir}/pkg/${go_host_os}_${go_host_arch}_cgo
if [ -e ${cgodisabled_pkg_dir} ]; then
use_go_install=1
fi
if [ -w ${go_root_dir}/pkg ]; then
use_go_install=1
fi
for cmd in sentinel proxy; do
CGO_ENABLED=0 go build -installsuffix cgo -ldflags "$LD_FLAGS" -o ${BINDIR}/stolon-${cmd} ${REPO_PATH}/cmd/${cmd}
done
CGO_ENABLED=0 go build -installsuffix cgo -ldflags "$LD_FLAGS" -o ${BINDIR}/stolonctl ${REPO_PATH}/cmd/stolonctl
go build -ldflags "$LD_FLAGS" -o ${BINDIR}/stolon-keeper ${REPO_PATH}/cmd/keeper
# Copy binaries to Dockerfile image directories
declare -a DOCKERFILE_PATHS
DOCKERFILE_PATHS=(${BASEDIR}/examples/kubernetes/image/docker)
for path in "${DOCKERFILE_PATHS[@]}"
do
rm -rf $path/bin/
mkdir -p $path/bin/
for cmd in stolon-keeper stolon-sentinel stolon-proxy stolonctl; do
cp ${BINDIR}/${cmd} $path/bin/
done
done