Browse code

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 <admwiggin@gmail.com>

Tianon Gravi authored on 2015/01/17 14:00:44
Showing 8 changed files
... ...
@@ -97,9 +97,6 @@ RUN cd /usr/local/go/src \
97 97
 			./make.bash --no-clean 2>&1; \
98 98
 	done
99 99
 
100
-# Reinstall standard library with netgo
101
-RUN go clean -i net && go install -tags netgo std
102
-
103 100
 # We still support compiling with older Go, so need to grab older "gofmt"
104 101
 ENV GOFMT_VERSION 1.3.3
105 102
 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
... ...
@@ -48,13 +48,11 @@ DEFAULT_BUNDLES=(
48 48
 	binary
49 49
 
50 50
 	test-unit
51
-	test-integration
52 51
 	test-integration-cli
53 52
 	test-docker-py
54 53
 
55 54
 	dynbinary
56
-	dyntest-unit
57
-	dyntest-integration
55
+	test-integration
58 56
 
59 57
 	cover
60 58
 	cross
... ...
@@ -113,7 +111,8 @@ fi
113 113
 EXTLDFLAGS_STATIC='-static'
114 114
 # ORIG_BUILDFLAGS is necessary for the cross target which cannot always build
115 115
 # with options like -race.
116
-ORIG_BUILDFLAGS=( -a -tags "netgo static_build $DOCKER_BUILDTAGS" )
116
+ORIG_BUILDFLAGS=( -a -tags "netgo static_build $DOCKER_BUILDTAGS" -installsuffix netgo )
117
+# see https://github.com/golang/go/issues/9369#issuecomment-69864440 for why -installsuffix is necessary here
117 118
 BUILDFLAGS=( $BUILDFLAGS "${ORIG_BUILDFLAGS[@]}" )
118 119
 # Test timeout.
119 120
 : ${TIMEOUT:=30m}
120 121
new file mode 100644
... ...
@@ -0,0 +1,29 @@
0
+#!/bin/bash
1
+set -e
2
+
3
+# dockerinit still needs to be a static binary, even if docker is dynamic
4
+go build \
5
+	-o "$DEST/dockerinit-$VERSION" \
6
+	"${BUILDFLAGS[@]}" \
7
+	-ldflags "
8
+		$LDFLAGS
9
+		$LDFLAGS_STATIC
10
+		-extldflags \"$EXTLDFLAGS_STATIC\"
11
+	" \
12
+	./dockerinit
13
+echo "Created binary: $DEST/dockerinit-$VERSION"
14
+ln -sf "dockerinit-$VERSION" "$DEST/dockerinit"
15
+
16
+sha1sum=
17
+if command -v sha1sum &> /dev/null; then
18
+	sha1sum=sha1sum
19
+elif command -v shasum &> /dev/null; then
20
+	# Mac OS X - why couldn't they just use the same command name and be happy?
21
+	sha1sum=shasum
22
+else
23
+	echo >&2 'error: cannot find sha1sum command or equivalent'
24
+	exit 1
25
+fi
26
+
27
+# sha1 our new dockerinit to ensure separate docker and dockerinit always run in a perfect pair compiled for one another
28
+export DOCKER_INITSHA1="$($sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)"
... ...
@@ -4,39 +4,14 @@ set -e
4 4
 DEST=$1
5 5
 
6 6
 if [ -z "$DOCKER_CLIENTONLY" ]; then
7
-	# dockerinit still needs to be a static binary, even if docker is dynamic
8
-	go build \
9
-		-o "$DEST/dockerinit-$VERSION" \
10
-		"${BUILDFLAGS[@]}" \
11
-		-ldflags "
12
-			$LDFLAGS
13
-			$LDFLAGS_STATIC
14
-			-extldflags \"$EXTLDFLAGS_STATIC\"
15
-		" \
16
-		./dockerinit
17
-	echo "Created binary: $DEST/dockerinit-$VERSION"
18
-	ln -sf "dockerinit-$VERSION" "$DEST/dockerinit"
7
+	source "$(dirname "$BASH_SOURCE")/.dockerinit"
19 8
 	
20 9
 	hash_files "$DEST/dockerinit-$VERSION"
21
-	
22
-	sha1sum=
23
-	if command -v sha1sum &> /dev/null; then
24
-		sha1sum=sha1sum
25
-	elif command -v shasum &> /dev/null; then
26
-		# Mac OS X - why couldn't they just use the same command name and be happy?
27
-		sha1sum=shasum
28
-	else
29
-		echo >&2 'error: cannot find sha1sum command or equivalent'
30
-		exit 1
31
-	fi
32
-	
33
-	# sha1 our new dockerinit to ensure separate docker and dockerinit always run in a perfect pair compiled for one another
34
-	export DOCKER_INITSHA1="$($sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)"
35 10
 else
36 11
 	# DOCKER_CLIENTONLY must be truthy, so we don't need to bother with dockerinit :)
37 12
 	export DOCKER_INITSHA1=""
38 13
 fi
39
-# exported so that "dyntest" can easily access it later without recalculating it
14
+# DOCKER_INITSHA1 is exported so that other bundlescripts can easily access it later without recalculating it
40 15
 
41 16
 (
42 17
 	export LDFLAGS_STATIC_DOCKER="-X $DOCKER_PKG/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X $DOCKER_PKG/dockerversion.INITPATH \"$DOCKER_INITPATH\""
43 18
deleted file mode 100644
... ...
@@ -1,18 +0,0 @@
1
-#!/bin/bash
2
-set -e
3
-
4
-DEST=$1
5
-INIT=$DEST/../dynbinary/dockerinit-$VERSION
6
-
7
-if [ ! -x "$INIT" ]; then
8
-	echo >&2 'error: dynbinary must be run before dyntest-integration'
9
-	false
10
-fi
11
-
12
-(
13
-	export TEST_DOCKERINIT_PATH="$INIT"
14
-	export LDFLAGS_STATIC_DOCKER="
15
-		-X $DOCKER_PKG/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\"
16
-	"
17
-	source "$(dirname "$BASH_SOURCE")/test-integration"
18
-)
19 1
deleted file mode 100644
... ...
@@ -1,18 +0,0 @@
1
-#!/bin/bash
2
-set -e
3
-
4
-DEST=$1
5
-INIT=$DEST/../dynbinary/dockerinit-$VERSION
6
-
7
-if [ ! -x "$INIT" ]; then
8
-	echo >&2 'error: dynbinary must be run before dyntest-unit'
9
-	false
10
-fi
11
-
12
-(
13
-	export TEST_DOCKERINIT_PATH="$INIT"
14
-	export LDFLAGS_STATIC_DOCKER="
15
-		-X $DOCKER_PKG/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\"
16
-	"
17
-	source "$(dirname "$BASH_SOURCE")/test-unit"
18
-)
... ...
@@ -3,8 +3,18 @@ set -e
3 3
 
4 4
 DEST=$1
5 5
 
6
+INIT=$DEST/../dynbinary/dockerinit-$VERSION
7
+[ -x "$INIT" ] || {
8
+	source "$(dirname "$BASH_SOURCE")/.dockerinit"
9
+	INIT="$DEST/dockerinit"
10
+}
11
+export TEST_DOCKERINIT_PATH="$INIT"
12
+
6 13
 bundle_test_integration() {
7
-	LDFLAGS="$LDFLAGS $LDFLAGS_STATIC_DOCKER" go_test_dir ./integration \
14
+	LDFLAGS="
15
+		$LDFLAGS
16
+		-X $DOCKER_PKG/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\"
17
+	" go_test_dir ./integration \
8 18
 		"-coverpkg $(find_dirs '*.go' | sed 's,^\.,'$DOCKER_PKG',g' | paste -d, -s)"
9 19
 }
10 20
 
... ...
@@ -23,7 +23,7 @@ bundle_test_unit() {
23 23
 			TESTDIRS=$(find_dirs '*_test.go')
24 24
 		fi
25 25
 		(
26
-			export LDFLAGS="$LDFLAGS $LDFLAGS_STATIC_DOCKER"
26
+			export LDFLAGS
27 27
 			export TESTFLAGS
28 28
 			export HAVE_GO_TEST_COVER
29 29
 			export DEST