Browse code

Fix dynbinary so that dockerinit can still be properly static even if it has to link against libapparmor for Ubuntu

Docker-DCO-1.1-Signed-off-by: Andrew Page <admwiggin@gmail.com> (github: tianon)

Tianon Gravi authored on 2014/03/07 11:55:22
Showing 8 changed files
... ...
@@ -82,10 +82,24 @@ if [ ! "$GOPATH" ]; then
82 82
 fi
83 83
 
84 84
 # Use these flags when compiling the tests and final binary
85
-LDFLAGS='-X github.com/dotcloud/docker/dockerversion.GITCOMMIT "'$GITCOMMIT'" -X github.com/dotcloud/docker/dockerversion.VERSION "'$VERSION'" -w'
86
-LDFLAGS_STATIC='-X github.com/dotcloud/docker/dockerversion.IAMSTATIC true -linkmode external -extldflags "-lpthread -static -Wl,--unresolved-symbols=ignore-in-object-files"'
85
+LDFLAGS='
86
+	-w
87
+	-X github.com/dotcloud/docker/dockerversion.GITCOMMIT "'$GITCOMMIT'"
88
+	-X github.com/dotcloud/docker/dockerversion.VERSION "'$VERSION'"
89
+'
90
+LDFLAGS_STATIC='-linkmode external'
91
+EXTLDFLAGS_STATIC='-static'
87 92
 BUILDFLAGS=( -a -tags "netgo $DOCKER_BUILDTAGS" )
88 93
 
94
+# A few more flags that are specific just to building a completely-static binary (see hack/make/binary)
95
+# PLEASE do not use these anywhere else.
96
+EXTLDFLAGS_STATIC_DOCKER="$EXTLDFLAGS_STATIC -lpthread -Wl,--unresolved-symbols=ignore-in-object-files"
97
+LDFLAGS_STATIC_DOCKER="
98
+	$LDFLAGS_STATIC
99
+	-X github.com/dotcloud/docker/dockerversion.IAMSTATIC true
100
+	-extldflags \"$EXTLDFLAGS_STATIC_DOCKER\"
101
+"
102
+
89 103
 HAVE_GO_TEST_COVER=
90 104
 if \
91 105
 	go help testflag | grep -- -cover > /dev/null \
... ...
@@ -2,5 +2,12 @@
2 2
 
3 3
 DEST=$1
4 4
 
5
-go build -o $DEST/docker-$VERSION -ldflags "$LDFLAGS $LDFLAGS_STATIC" "${BUILDFLAGS[@]}" ./docker
5
+go build \
6
+	-o $DEST/docker-$VERSION \
7
+	"${BUILDFLAGS[@]}" \
8
+	-ldflags "
9
+		$LDFLAGS
10
+		$LDFLAGS_STATIC_DOCKER
11
+	" \
12
+	./docker
6 13
 echo "Created binary: $DEST/docker-$VERSION"
... ...
@@ -17,7 +17,7 @@ for platform in $DOCKER_CROSSPLATFORMS; do
17 17
 		mkdir -p "$DEST/$platform" # bundles/VERSION/cross/GOOS/GOARCH/docker-VERSION
18 18
 		export GOOS=${platform%/*}
19 19
 		export GOARCH=${platform##*/}
20
-		export LDFLAGS_STATIC="" # we just need a simple client for these platforms (TODO this might change someday)
20
+		export LDFLAGS_STATIC_DOCKER="" # we just need a simple client for these platforms (TODO this might change someday)
21 21
 		source "$(dirname "$BASH_SOURCE")/binary" "$DEST/$platform"
22 22
 	)
23 23
 done
... ...
@@ -3,7 +3,15 @@
3 3
 DEST=$1
4 4
 
5 5
 # dockerinit still needs to be a static binary, even if docker is dynamic
6
-CGO_ENABLED=0 go build -o $DEST/dockerinit-$VERSION -ldflags "$LDFLAGS -d" "${BUILDFLAGS[@]}" ./dockerinit
6
+go build \
7
+	-o $DEST/dockerinit-$VERSION \
8
+	"${BUILDFLAGS[@]}" \
9
+	-ldflags "
10
+		$LDFLAGS
11
+		$LDFLAGS_STATIC
12
+		-extldflags \"$EXTLDFLAGS_STATIC\"
13
+	" \
14
+	./dockerinit
7 15
 echo "Created binary: $DEST/dockerinit-$VERSION"
8 16
 ln -sf dockerinit-$VERSION $DEST/dockerinit
9 17
 
... ...
@@ -23,6 +31,6 @@ export DOCKER_INITSHA1="$($sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)"
23 23
 # exported so that "dyntest" can easily access it later without recalculating it
24 24
 
25 25
 (
26
-	export LDFLAGS_STATIC="-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X github.com/dotcloud/docker/dockerversion.INITPATH \"$DOCKER_INITPATH\""
26
+	export LDFLAGS_STATIC_DOCKER="-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X github.com/dotcloud/docker/dockerversion.INITPATH \"$DOCKER_INITPATH\""
27 27
 	source "$(dirname "$BASH_SOURCE")/binary"
28 28
 )
... ...
@@ -12,6 +12,8 @@ fi
12 12
 
13 13
 (
14 14
 	export TEST_DOCKERINIT_PATH="$INIT"
15
-	export LDFLAGS_STATIC="-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\""
15
+	export LDFLAGS_STATIC_DOCKER="
16
+		-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\"
17
+	"
16 18
 	source "$(dirname "$BASH_SOURCE")/test"
17 19
 )
... ...
@@ -12,6 +12,8 @@ fi
12 12
 
13 13
 (
14 14
 	export TEST_DOCKERINIT_PATH="$INIT"
15
-	export LDFLAGS_STATIC="-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\""
15
+	export LDFLAGS_STATIC_DOCKER="
16
+		-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\"
17
+	"
16 18
 	source "$(dirname "$BASH_SOURCE")/test-integration"
17 19
 )
... ...
@@ -4,9 +4,9 @@ DEST=$1
4 4
 
5 5
 set -e
6 6
 
7
-TEXTRESET=$'\033[0m' # reset the foreground colour
8 7
 RED=$'\033[31m'
9 8
 GREEN=$'\033[32m'
9
+TEXTRESET=$'\033[0m' # reset the foreground colour
10 10
 
11 11
 # Run Docker's test suite, including sub-packages, and store their output as a bundle
12 12
 # If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
... ...
@@ -22,7 +22,7 @@ bundle_test() {
22 22
 		for test_dir in $(find_dirs '*_test.go'); do
23 23
 			echo
24 24
 
25
-			if ! LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir "$test_dir"; then
25
+			if ! LDFLAGS="$LDFLAGS $LDFLAGS_STATIC_DOCKER" go_test_dir "$test_dir"; then
26 26
 				TESTS_FAILED+=("$test_dir")
27 27
 				echo
28 28
 				echo "${RED}Tests failed: $test_dir${TEXTRESET}"
... ...
@@ -5,7 +5,7 @@ DEST=$1
5 5
 set -e
6 6
 
7 7
 bundle_test_integration() {
8
-	LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir ./integration \
8
+	LDFLAGS="$LDFLAGS $LDFLAGS_STATIC_DOCKER" go_test_dir ./integration \
9 9
 		"-coverpkg $(find_dirs '*.go' | sed 's,^\.,github.com/dotcloud/docker,g' | paste -d, -s)"
10 10
 }
11 11