Skip to content

Commit

Permalink
Merge pull request #553 from sgotti/simplify_build
Browse files Browse the repository at this point in the history
*: update go version to go1.11 and simplify build
  • Loading branch information
sgotti committed Aug 27, 2018
2 parents 849e28b + 6f45fb8 commit d88775a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 47 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ Session.vim

#
bin/
/gopath/
/release/
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
language: go

go:
- 1.9.x
- 1.10.x
- 1.11.x

go_import_path: github.com/sorintlab/stolon

env:
- TARGET=amd64
Expand Down
41 changes: 5 additions & 36 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,8 @@ fi
ORG_PATH="github.com/sorintlab"
REPO_PATH="${ORG_PATH}/stolon"

# Hack to be sure that:
# * all the dependencies are vendored
# * if cloned as another repo name it will compile anyway
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}

export GO15VENDOREXPERIMENT=1

VERSION=${STOLON_VERSION:-$(${BASEDIR}/scripts/git-version.sh)}
LD_FLAGS="-s -X ${REPO_PATH}/cmd.Version=$VERSION"

Expand All @@ -72,32 +61,12 @@ 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 "$LD_FLAGS" -o ${BINDIR}/stolon-${cmd} ${REPO_PATH}/cmd/${cmd}
done
CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags "$LD_FLAGS" -o ${BINDIR}/stolonctl ${REPO_PATH}/cmd/stolonctl
else
for cmd in sentinel proxy; do
CGO_ENABLED=0 go install -installsuffix cgo -ldflags "$LD_FLAGS" ${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 "$LD_FLAGS" ${REPO_PATH}/cmd/stolonctl
rm -f ${BINDIR}/stolonctl
cp ${GOPATH}/bin/stolonctl ${BINDIR}/
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

# 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 -ldflags "$LD_FLAGS" ${REPO_PATH}/cmd/keeper
rm -f ${BINDIR}/stolon-keeper
cp ${GOPATH}/bin/keeper ${BINDIR}/stolon-keeper
go build -ldflags "$LD_FLAGS" -o ${BINDIR}/stolon-keeper ${REPO_PATH}/cmd/keeper

# Copy binaries to Dockerfile image directories
declare -a DOCKERFILE_PATHS
Expand Down
7 changes: 5 additions & 2 deletions scripts/semaphore-k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ touch $HOME/.kube/config
export KUBECONFIG=$HOME/.kube/config
sudo -E minikube start --vm-driver=none

# Precompile stdlib with cgo disable to speedup builds
sudo -E CGO_ENABLED=0 go install -a -installsuffix cgo std
# Fix build to work with the right import path also when building github forked repositories
if [[ ! -e ~/workspace/src/github.com/sorintlab/stolon ]]; then
mkdir -p ~/workspace/src/github.com/sorintlab
ln -s /home/runner/stolon ~/workspace/src/github.com/sorintlab/stolon
fi

./build

Expand Down
7 changes: 5 additions & 2 deletions scripts/semaphore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-
sudo apt-get update
sudo apt-get -y install postgresql-9.5 postgresql-9.6 postgresql-10 postgresql-11

# Precompile stdlib with cgo disable to speedup builds
sudo -E CGO_ENABLED=0 go install -a -installsuffix cgo std
# Fix build to work with the right import path also when building github forked repositories
if [[ ! -e ~/workspace/src/github.com/sorintlab/stolon ]]; then
mkdir -p ~/workspace/src/github.com/sorintlab
ln -s /home/runner/stolon ~/workspace/src/github.com/sorintlab/stolon
fi

# Run tests
export ETCD_BIN="${PWD}/etcd/etcd-v3.2.11-linux-amd64/etcd"
Expand Down
5 changes: 0 additions & 5 deletions test
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ REPO_PATH="${ORG_PATH}/stolon"

./build

# Hack to be sure that:
# * all the dependencies are vendored
# * if cloned as another repo name it will compile anyway
export GOPATH=${PWD}/gopath

# test all packages excluding integration tests
IGNORE_PKGS="(vendor/|tests/integration)"
PACKAGES=$(find . -name \*_test.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | sed "s|\./||g")
Expand Down

0 comments on commit d88775a

Please sign in to comment.