From 232d59baeb13778abc242a602ca434d83e1eb6e8 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Fri, 16 Jan 2015 22:00:44 -0700 Subject: [PATCH] Let's try fixing "netgo" again Since "go test" doesn't seem to support "-installsuffix" as quite the same perfect solution that "go build" is happy to let it be, let's just switch those crappy old "integration/" tests to use our separate static dockerinit binary so we don't have to worry about compiling the entire test harness statically. :+1: Signed-off-by: Andrew "Tianon" Page --- Dockerfile | 3 --- project/make.sh | 7 +++---- project/make/.dockerinit | 29 +++++++++++++++++++++++++++++ project/make/dynbinary | 29 ++--------------------------- project/make/dyntest-integration | 18 ------------------ project/make/dyntest-unit | 18 ------------------ project/make/test-integration | 12 +++++++++++- project/make/test-unit | 2 +- 8 files changed, 46 insertions(+), 72 deletions(-) create mode 100644 project/make/.dockerinit delete mode 100644 project/make/dyntest-integration delete mode 100644 project/make/dyntest-unit diff --git a/Dockerfile b/Dockerfile index 59d9ced906..dd23f561a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -97,9 +97,6 @@ RUN cd /usr/local/go/src \ ./make.bash --no-clean 2>&1; \ done -# Reinstall standard library with netgo -RUN go clean -i net && go install -tags netgo std - # We still support compiling with older Go, so need to grab older "gofmt" ENV GOFMT_VERSION 1.3.3 RUN curl -sSL https://storage.googleapis.com/golang/go${GOFMT_VERSION}.$(go env GOOS)-$(go env GOARCH).tar.gz | tar -C /go/bin -xz --strip-components=2 go/bin/gofmt diff --git a/project/make.sh b/project/make.sh index f7919515cf..bb2a3419fa 100755 --- a/project/make.sh +++ b/project/make.sh @@ -48,13 +48,11 @@ DEFAULT_BUNDLES=( binary test-unit - test-integration test-integration-cli test-docker-py dynbinary - dyntest-unit - dyntest-integration + test-integration cover cross @@ -113,7 +111,8 @@ fi EXTLDFLAGS_STATIC='-static' # ORIG_BUILDFLAGS is necessary for the cross target which cannot always build # with options like -race. -ORIG_BUILDFLAGS=( -a -tags "netgo static_build $DOCKER_BUILDTAGS" ) +ORIG_BUILDFLAGS=( -a -tags "netgo static_build $DOCKER_BUILDTAGS" -installsuffix netgo ) +# see https://github.com/golang/go/issues/9369#issuecomment-69864440 for why -installsuffix is necessary here BUILDFLAGS=( $BUILDFLAGS "${ORIG_BUILDFLAGS[@]}" ) # Test timeout. : ${TIMEOUT:=30m} diff --git a/project/make/.dockerinit b/project/make/.dockerinit new file mode 100644 index 0000000000..73df8fce01 --- /dev/null +++ b/project/make/.dockerinit @@ -0,0 +1,29 @@ +#!/bin/bash +set -e + +# dockerinit still needs to be a static binary, even if docker is dynamic +go build \ + -o "$DEST/dockerinit-$VERSION" \ + "${BUILDFLAGS[@]}" \ + -ldflags " + $LDFLAGS + $LDFLAGS_STATIC + -extldflags \"$EXTLDFLAGS_STATIC\" + " \ + ./dockerinit +echo "Created binary: $DEST/dockerinit-$VERSION" +ln -sf "dockerinit-$VERSION" "$DEST/dockerinit" + +sha1sum= +if command -v sha1sum &> /dev/null; then + sha1sum=sha1sum +elif command -v shasum &> /dev/null; then + # Mac OS X - why couldn't they just use the same command name and be happy? + sha1sum=shasum +else + echo >&2 'error: cannot find sha1sum command or equivalent' + exit 1 +fi + +# sha1 our new dockerinit to ensure separate docker and dockerinit always run in a perfect pair compiled for one another +export DOCKER_INITSHA1="$($sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)" diff --git a/project/make/dynbinary b/project/make/dynbinary index 5064a799bd..39fcd35767 100644 --- a/project/make/dynbinary +++ b/project/make/dynbinary @@ -4,39 +4,14 @@ set -e DEST=$1 if [ -z "$DOCKER_CLIENTONLY" ]; then - # dockerinit still needs to be a static binary, even if docker is dynamic - go build \ - -o "$DEST/dockerinit-$VERSION" \ - "${BUILDFLAGS[@]}" \ - -ldflags " - $LDFLAGS - $LDFLAGS_STATIC - -extldflags \"$EXTLDFLAGS_STATIC\" - " \ - ./dockerinit - echo "Created binary: $DEST/dockerinit-$VERSION" - ln -sf "dockerinit-$VERSION" "$DEST/dockerinit" + source "$(dirname "$BASH_SOURCE")/.dockerinit" hash_files "$DEST/dockerinit-$VERSION" - - sha1sum= - if command -v sha1sum &> /dev/null; then - sha1sum=sha1sum - elif command -v shasum &> /dev/null; then - # Mac OS X - why couldn't they just use the same command name and be happy? - sha1sum=shasum - else - echo >&2 'error: cannot find sha1sum command or equivalent' - exit 1 - fi - - # sha1 our new dockerinit to ensure separate docker and dockerinit always run in a perfect pair compiled for one another - export DOCKER_INITSHA1="$($sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)" else # DOCKER_CLIENTONLY must be truthy, so we don't need to bother with dockerinit :) export DOCKER_INITSHA1="" fi -# exported so that "dyntest" can easily access it later without recalculating it +# DOCKER_INITSHA1 is exported so that other bundlescripts can easily access it later without recalculating it ( export LDFLAGS_STATIC_DOCKER="-X $DOCKER_PKG/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X $DOCKER_PKG/dockerversion.INITPATH \"$DOCKER_INITPATH\"" diff --git a/project/make/dyntest-integration b/project/make/dyntest-integration deleted file mode 100644 index 1cc7349aba..0000000000 --- a/project/make/dyntest-integration +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -set -e - -DEST=$1 -INIT=$DEST/../dynbinary/dockerinit-$VERSION - -if [ ! -x "$INIT" ]; then - echo >&2 'error: dynbinary must be run before dyntest-integration' - false -fi - -( - export TEST_DOCKERINIT_PATH="$INIT" - export LDFLAGS_STATIC_DOCKER=" - -X $DOCKER_PKG/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" - " - source "$(dirname "$BASH_SOURCE")/test-integration" -) diff --git a/project/make/dyntest-unit b/project/make/dyntest-unit deleted file mode 100644 index cffef98512..0000000000 --- a/project/make/dyntest-unit +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -set -e - -DEST=$1 -INIT=$DEST/../dynbinary/dockerinit-$VERSION - -if [ ! -x "$INIT" ]; then - echo >&2 'error: dynbinary must be run before dyntest-unit' - false -fi - -( - export TEST_DOCKERINIT_PATH="$INIT" - export LDFLAGS_STATIC_DOCKER=" - -X $DOCKER_PKG/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" - " - source "$(dirname "$BASH_SOURCE")/test-unit" -) diff --git a/project/make/test-integration b/project/make/test-integration index 9512cc4e36..5cb7102bc8 100644 --- a/project/make/test-integration +++ b/project/make/test-integration @@ -3,8 +3,18 @@ set -e DEST=$1 +INIT=$DEST/../dynbinary/dockerinit-$VERSION +[ -x "$INIT" ] || { + source "$(dirname "$BASH_SOURCE")/.dockerinit" + INIT="$DEST/dockerinit" +} +export TEST_DOCKERINIT_PATH="$INIT" + bundle_test_integration() { - LDFLAGS="$LDFLAGS $LDFLAGS_STATIC_DOCKER" go_test_dir ./integration \ + LDFLAGS=" + $LDFLAGS + -X $DOCKER_PKG/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" + " go_test_dir ./integration \ "-coverpkg $(find_dirs '*.go' | sed 's,^\.,'$DOCKER_PKG',g' | paste -d, -s)" } diff --git a/project/make/test-unit b/project/make/test-unit index 59700e86f5..9225b33a06 100644 --- a/project/make/test-unit +++ b/project/make/test-unit @@ -23,7 +23,7 @@ bundle_test_unit() { TESTDIRS=$(find_dirs '*_test.go') fi ( - export LDFLAGS="$LDFLAGS $LDFLAGS_STATIC_DOCKER" + export LDFLAGS export TESTFLAGS export HAVE_GO_TEST_COVER export DEST