From 6f45fb83855bfb73bf781004e8c841fb9df76382 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Mon, 27 Aug 2018 10:09:41 +0200 Subject: [PATCH] *: update go version to go1.11 and simplify build * use go 1.10.x and 1.11.x on travis * Remove the build hack that uses a local GOPATH: * Use `go_import_path` on travis and create a symlink to the main org repo on semaphore * Users forking stolon repo on github should just use git remotes in the main repo clone * Remove messages to build a cgo enabled stdlib, go build cache introduced in go 1.10 also caches this. * Always use `go build` instead of `go install` so we can directly place binaries in the project bin dir and choose the binary name --- .gitignore | 1 - .travis.yml | 4 +++- build | 41 +++++----------------------------------- scripts/semaphore-k8s.sh | 7 +++++-- scripts/semaphore.sh | 7 +++++-- test | 5 ----- 6 files changed, 18 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index f31e99f01..07e2128d1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,4 @@ Session.vim # bin/ -/gopath/ /release/ diff --git a/.travis.yml b/.travis.yml index 78382989e..a4c480ffa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/build b/build index 39e356b10..2ccca2f2f 100755 --- a/build +++ b/build @@ -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" @@ -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 diff --git a/scripts/semaphore-k8s.sh b/scripts/semaphore-k8s.sh index 00c875e9a..9d75fffb9 100755 --- a/scripts/semaphore-k8s.sh +++ b/scripts/semaphore-k8s.sh @@ -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 diff --git a/scripts/semaphore.sh b/scripts/semaphore.sh index 634198a9f..ad5621761 100755 --- a/scripts/semaphore.sh +++ b/scripts/semaphore.sh @@ -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" diff --git a/test b/test index 937209d59..d01a90dfb 100755 --- a/test +++ b/test @@ -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")