Merge pull request #144 from squeed/build-fixes

build: some small improvements; bump to go1.10
This commit is contained in:
Dan Williams 2018-04-25 10:41:32 -05:00 committed by GitHub
commit 1df359a210
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 35 additions and 46 deletions

2
.gitignore vendored
View File

@ -26,3 +26,5 @@ _testmain.go
bin/ bin/
gopath/ gopath/
.vagrant .vagrant
/release-*

View File

@ -1,8 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
cd $(dirname "$0")
if [ "$(uname)" == "Darwin" ]; then if [ "$(uname)" == "Darwin" ]; then
export GOOS=linux export GOOS="${GOOS:-linux}"
fi fi
ORG_PATH="github.com/containernetworking" ORG_PATH="github.com/containernetworking"
@ -13,7 +14,6 @@ if [ ! -h gopath/src/${REPO_PATH} ]; then
ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255 ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255
fi fi
export GO15VENDOREXPERIMENT=1
export GOPATH=${PWD}/gopath export GOPATH=${PWD}/gopath
export GO="${GO:-go}" export GO="${GO:-go}"
@ -25,12 +25,6 @@ for d in $PLUGINS; do
if [ -d "$d" ]; then if [ -d "$d" ]; then
plugin="$(basename "$d")" plugin="$(basename "$d")"
echo " $plugin" echo " $plugin"
# use go install so we don't duplicate work $GO build -o "${PWD}/bin/$plugin" "$@" "$REPO_PATH"/$d
if [ -n "$FASTBUILD" ]
then
GOBIN=${PWD}/bin $GO install -pkgdir $GOPATH/pkg "$@" $REPO_PATH/$d
else
$GO build -o "${PWD}/bin/$plugin" -pkgdir "$GOPATH/pkg" "$@" "$REPO_PATH/$d"
fi
fi fi
done done

View File

@ -25,7 +25,7 @@ import (
func TestIntegration(t *testing.T) { func TestIntegration(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Integration Suite") RunSpecs(t, "integration")
} }
var echoServerBinaryPath string var echoServerBinaryPath string

View File

@ -23,5 +23,5 @@ import (
func TestIp(t *testing.T) { func TestIp(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Ip Suite") RunSpecs(t, "pkg/ip")
} }

View File

@ -23,5 +23,5 @@ import (
func TestIpam(t *testing.T) { func TestIpam(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Ipam Suite") RunSpecs(t, "pkg/ipam")
} }

View File

@ -30,5 +30,5 @@ func TestNs(t *testing.T) {
runtime.LockOSThread() runtime.LockOSThread()
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "pkg/ns Suite") RunSpecs(t, "pkg/ns")
} }

View File

@ -9,5 +9,5 @@ import (
func TestEchosvr(t *testing.T) { func TestEchosvr(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Testutils Echosvr Suite") RunSpecs(t, "pkg/testutils/echosvr")
} }

View File

@ -23,5 +23,5 @@ import (
func TestHwaddr(t *testing.T) { func TestHwaddr(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Hwaddr Suite") RunSpecs(t, "pkg/utils/hwaddr")
} }

View File

@ -23,5 +23,5 @@ import (
func TestUtils(t *testing.T) { func TestUtils(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Utils Suite") RunSpecs(t, "pkg/utils")
} }

View File

@ -23,5 +23,5 @@ import (
func TestDHCP(t *testing.T) { func TestDHCP(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "DHCP Suite") RunSpecs(t, "plugins/ipam/dhcp")
} }

View File

@ -23,5 +23,5 @@ import (
func TestAllocator(t *testing.T) { func TestAllocator(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Allocator Suite") RunSpecs(t, "plugins/ipam/host-local/backend/allocator")
} }

View File

@ -23,5 +23,5 @@ import (
func TestLock(t *testing.T) { func TestLock(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Disk Suite") RunSpecs(t, "plugins/ipam/host-local/backend/disk")
} }

View File

@ -23,5 +23,5 @@ import (
func TestHostLocal(t *testing.T) { func TestHostLocal(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "HostLocal Suite") RunSpecs(t, "plugins/ipam/host-local")
} }

View File

@ -23,5 +23,5 @@ import (
func TestBridge(t *testing.T) { func TestBridge(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "bridge Suite") RunSpecs(t, "plugins/main/bridge")
} }

View File

@ -23,5 +23,5 @@ import (
func TestVlan(t *testing.T) { func TestVlan(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "host-device Suite") RunSpecs(t, "plugins/main/host-device")
} }

View File

@ -23,5 +23,5 @@ import (
func TestIpvlan(t *testing.T) { func TestIpvlan(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "ipvlan Suite") RunSpecs(t, "plugins/main/ipvlan")
} }

View File

@ -27,7 +27,7 @@ var pathToLoPlugin string
func TestLoopback(t *testing.T) { func TestLoopback(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Loopback Suite") RunSpecs(t, "plugins/main/loopback")
} }
var _ = BeforeSuite(func() { var _ = BeforeSuite(func() {

View File

@ -23,5 +23,5 @@ import (
func TestMacvlan(t *testing.T) { func TestMacvlan(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "macvlan Suite") RunSpecs(t, "plugins/main/macvlan")
} }

View File

@ -23,5 +23,5 @@ import (
func TestPtp(t *testing.T) { func TestPtp(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "ptp Suite") RunSpecs(t, "plugins/main/ptp")
} }

View File

@ -23,5 +23,5 @@ import (
func TestVlan(t *testing.T) { func TestVlan(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "vlan Suite") RunSpecs(t, "plugins/main/vlan")
} }

View File

@ -36,7 +36,7 @@ import (
func TestTBF(t *testing.T) { func TestTBF(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "bandwidth suite") RunSpecs(t, "plugins/meta/bandwidth")
} }
var echoServerBinaryPath string var echoServerBinaryPath string

View File

@ -22,5 +22,5 @@ import (
func TestFlannel(t *testing.T) { func TestFlannel(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Flannel Suite") RunSpecs(t, "plugins/meta/flannel")
} }

View File

@ -37,7 +37,7 @@ func TestPortmap(t *testing.T) {
rand.Seed(config.GinkgoConfig.RandomSeed) rand.Seed(config.GinkgoConfig.RandomSeed)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "portmap Suite") RunSpecs(t, "plugins/meta/portmap")
} }
var echoServerBinaryPath string var echoServerBinaryPath string

View File

@ -23,5 +23,5 @@ import (
func TestTuning(t *testing.T) { func TestTuning(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "tuning Suite") RunSpecs(t, "plugins/meta/tuning")
} }

View File

@ -11,5 +11,5 @@ import (
func TestSample(t *testing.T) { func TestSample(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "sample suite") RunSpecs(t, "plugins/sample")
} }

View File

@ -2,11 +2,12 @@
set -xe set -xe
SRC_DIR="${SRC_DIR:-$PWD}" SRC_DIR="${SRC_DIR:-$PWD}"
BUILDFLAGS="-a --ldflags '-extldflags \"-static\"'"
TAG=$(git describe --tags --dirty) TAG=$(git describe --tags --dirty)
RELEASE_DIR=release-${TAG} RELEASE_DIR=release-${TAG}
BUILDFLAGS="-ldflags '-extldflags -static -X main._buildVersion=${TAG}'"
OUTPUT_DIR=bin OUTPUT_DIR=bin
# Always clean first # Always clean first
@ -14,10 +15,10 @@ rm -Rf ${SRC_DIR}/${RELEASE_DIR}
mkdir -p ${SRC_DIR}/${RELEASE_DIR} mkdir -p ${SRC_DIR}/${RELEASE_DIR}
mkdir -p ${OUTPUT_DIR} mkdir -p ${OUTPUT_DIR}
docker run -i -v ${SRC_DIR}:/opt/src --rm golang:1.9-alpine \ docker run -ti -v ${SRC_DIR}:/go/src/github.com/containernetworking/plugins --rm golang:1.10-alpine \
/bin/sh -xe -c "\ /bin/sh -xe -c "\
apk --no-cache add bash tar; apk --no-cache add bash tar;
cd /opt/src; umask 0022; cd /go/src/github.com/containernetworking/plugins; umask 0022;
for arch in amd64 arm arm64 ppc64le s390x; do \ for arch in amd64 arm arm64 ppc64le s390x; do \
rm -f ${OUTPUT_DIR}/*; \ rm -f ${OUTPUT_DIR}/*; \
CGO_ENABLED=0 GOARCH=\$arch ./build.sh ${BUILDFLAGS}; \ CGO_ENABLED=0 GOARCH=\$arch ./build.sh ${BUILDFLAGS}; \
@ -25,9 +26,6 @@ docker run -i -v ${SRC_DIR}:/opt/src --rm golang:1.9-alpine \
FILENAME=cni-plugins-\$arch-${TAG}.\$format; \ FILENAME=cni-plugins-\$arch-${TAG}.\$format; \
FILEPATH=${RELEASE_DIR}/\$FILENAME; \ FILEPATH=${RELEASE_DIR}/\$FILENAME; \
tar -C ${OUTPUT_DIR} --owner=0 --group=0 -caf \$FILEPATH .; \ tar -C ${OUTPUT_DIR} --owner=0 --group=0 -caf \$FILEPATH .; \
if [ \"\$arch\" == \"amd64\" ]; then \
cp \$FILEPATH ${RELEASE_DIR}/cni-${TAG}.\$format; \
fi; \
done; \ done; \
done; done;
cd ${RELEASE_DIR}; cd ${RELEASE_DIR};

11
test.sh
View File

@ -10,17 +10,12 @@ source ./build.sh
echo "Running tests" echo "Running tests"
# test everything that's not in vendor
pushd "$GOPATH/src/$REPO_PATH" >/dev/null
ALL_PKGS="$(go list ./... | grep -v vendor | xargs echo)"
popd >/dev/null
GINKGO_FLAGS="-p --randomizeAllSpecs --randomizeSuites --failOnPending --progress" GINKGO_FLAGS="-p --randomizeAllSpecs --randomizeSuites --failOnPending --progress"
# user has not provided PKG override # user has not provided PKG override
if [ -z "$PKG" ]; then if [ -z "$PKG" ]; then
GINKGO_FLAGS="$GINKGO_FLAGS -r ." GINKGO_FLAGS="$GINKGO_FLAGS -r ."
LINT_TARGETS="$ALL_PKGS" LINT_TARGETS="./..."
# user has provided PKG override # user has provided PKG override
else else
@ -28,9 +23,9 @@ else
LINT_TARGETS="$PKG" LINT_TARGETS="$PKG"
fi fi
cd "$GOPATH/src/$REPO_PATH" sudo -E bash -c "umask 0; cd ${GOPATH}/src/${REPO_PATH}; PATH=${GOROOT}/bin:$(pwd)/bin:${PATH} ginkgo ${GINKGO_FLAGS}"
sudo -E bash -c "umask 0; PATH=${GOROOT}/bin:$(pwd)/bin:${PATH} ginkgo ${GINKGO_FLAGS}"
cd ${GOPATH}/src/${REPO_PATH};
echo "Checking gofmt..." echo "Checking gofmt..."
fmtRes=$(go fmt $LINT_TARGETS) fmtRes=$(go fmt $LINT_TARGETS)
if [ -n "${fmtRes}" ]; then if [ -n "${fmtRes}" ]; then