Skip to content

Commit

Permalink
Let's try fixing "netgo" again
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tianon committed Jan 19, 2015
1 parent 27602f2 commit 232d59b
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 72 deletions.
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions project/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
29 changes: 29 additions & 0 deletions project/make/.dockerinit
Original file line number Diff line number Diff line change
@@ -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)"
29 changes: 2 additions & 27 deletions project/make/dynbinary
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
Expand Down
18 changes: 0 additions & 18 deletions project/make/dyntest-integration

This file was deleted.

18 changes: 0 additions & 18 deletions project/make/dyntest-unit

This file was deleted.

12 changes: 11 additions & 1 deletion project/make/test-integration
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}

Expand Down
2 changes: 1 addition & 1 deletion project/make/test-unit
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 232d59b

Please sign in to comment.