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. 👍

Signed-off-by: Andrew "Tianon" Page <admwiggin@gmail.com>
This commit is contained in:
Tianon Gravi 2015-01-16 22:00:44 -07:00
parent 27602f2a21
commit 232d59baeb
8 changed files with 46 additions and 72 deletions

View file

@ -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

View file

@ -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}

29
project/make/.dockerinit Normal file
View file

@ -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)"

View file

@ -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\""

View file

@ -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"
)

View file

@ -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"
)

View file

@ -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)"
}

View file

@ -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