forked from sorintlab/stolon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·81 lines (63 loc) · 2.83 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
#!/bin/bash
set -e
BASEDIR=$(readlink -f $(dirname $0))
BINDIR=${BASEDIR}/bin
if [ $PWD != $BASEDIR ]; then
cd $BASEDIR
fi
ORG_PATH="github.com/sorintlab"
REPO_PATH="${ORG_PATH}/stolon"
export GOPATH=${PWD}/gopath
rm -f $GOPATH/src/${REPO_PATH}
mkdir -p $GOPATH/src/${ORG_PATH}
ln -s ${PWD} $GOPATH/src/${REPO_PATH}
mkdir -p ${BINDIR}
# 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
if [ -z $use_go_install ]; then
echo "Cannot find/create a go stdlib created with cgo disabled for the go release installed at ${go_root_dir} since ${go_root_dir}/pkg is not writable by `whoami`"
echo "The build will use \"go build\" instead of \"go install\". This is slower since every run will need to rebuild all the needed packages."
echo "To speed up the build you should make ${go_root_dir}/pkg writable for `whoami` for at least the first build"
echo "or manually rebuild stdlib executing the command 'CGO_ENABLED=0 go install -a -installsuffix cgo std' from a user with write access to ${go_root_dir}/pkg"
for cmd in sentinel proxy; do
CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags '-s' -o ${BINDIR}/stolon-${cmd} ${REPO_PATH}/cmd/${cmd}
done
CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags '-s' -o ${BINDIR}/stolonctl ${REPO_PATH}/cmd/stolonctl
else
for cmd in sentinel proxy; do
CGO_ENABLED=0 go install -installsuffix cgo -ldflags '-s' ${REPO_PATH}/cmd/${cmd}
rm -f ${BINDIR}/stolon-${cmd}
cp ${GOPATH}/bin/${cmd} ${BINDIR}/stolon-${cmd}
done
CGO_ENABLED=0 go install -installsuffix cgo -ldflags '-s' ${REPO_PATH}/cmd/stolonctl
rm -f ${BINDIR}/stolonctl
cp ${GOPATH}/bin/stolonctl ${BINDIR}/
fi
# stolon-keeper cannot be statically built since it needs to get its current
# running user and this is not available with cgo disabled
go install ${REPO_PATH}/cmd/keeper
rm -f ${BINDIR}/stolon-keeper
cp ${GOPATH}/bin/keeper ${BINDIR}/stolon-keeper
# Copy binaries to Dockerfile image directories
DOCKERIMAGE=${BASEDIR}/examples/kubernetes/image/docker
mkdir -p ${DOCKERIMAGE}/bin/
rm -f ${DOCKERIMAGE}/bin/*
for cmd in stolon-keeper stolon-sentinel stolon-proxy; do
cp ${BINDIR}/${cmd} ${DOCKERIMAGE}/bin/
done