Преглед на файлове

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 преди 11 години
родител
ревизия
be344cf0d8
променени са 8 файла, в които са добавени 44 реда и са изтрити 11 реда
  1. 16 2
      hack/make.sh
  2. 8 1
      hack/make/binary
  3. 1 1
      hack/make/cross
  4. 10 2
      hack/make/dynbinary
  5. 3 1
      hack/make/dyntest
  6. 3 1
      hack/make/dyntest-integration
  7. 2 2
      hack/make/test
  8. 1 1
      hack/make/test-integration

+ 16 - 2
hack/make.sh

@@ -82,10 +82,24 @@ if [ ! "$GOPATH" ]; then
 fi
 
 # Use these flags when compiling the tests and final binary
-LDFLAGS='-X github.com/dotcloud/docker/dockerversion.GITCOMMIT "'$GITCOMMIT'" -X github.com/dotcloud/docker/dockerversion.VERSION "'$VERSION'" -w'
-LDFLAGS_STATIC='-X github.com/dotcloud/docker/dockerversion.IAMSTATIC true -linkmode external -extldflags "-lpthread -static -Wl,--unresolved-symbols=ignore-in-object-files"'
+LDFLAGS='
+	-w
+	-X github.com/dotcloud/docker/dockerversion.GITCOMMIT "'$GITCOMMIT'"
+	-X github.com/dotcloud/docker/dockerversion.VERSION "'$VERSION'"
+'
+LDFLAGS_STATIC='-linkmode external'
+EXTLDFLAGS_STATIC='-static'
 BUILDFLAGS=( -a -tags "netgo $DOCKER_BUILDTAGS" )
 
+# A few more flags that are specific just to building a completely-static binary (see hack/make/binary)
+# PLEASE do not use these anywhere else.
+EXTLDFLAGS_STATIC_DOCKER="$EXTLDFLAGS_STATIC -lpthread -Wl,--unresolved-symbols=ignore-in-object-files"
+LDFLAGS_STATIC_DOCKER="
+	$LDFLAGS_STATIC
+	-X github.com/dotcloud/docker/dockerversion.IAMSTATIC true
+	-extldflags \"$EXTLDFLAGS_STATIC_DOCKER\"
+"
+
 HAVE_GO_TEST_COVER=
 if \
 	go help testflag | grep -- -cover > /dev/null \

+ 8 - 1
hack/make/binary

@@ -2,5 +2,12 @@
 
 DEST=$1
 
-go build -o $DEST/docker-$VERSION -ldflags "$LDFLAGS $LDFLAGS_STATIC" "${BUILDFLAGS[@]}" ./docker
+go build \
+	-o $DEST/docker-$VERSION \
+	"${BUILDFLAGS[@]}" \
+	-ldflags "
+		$LDFLAGS
+		$LDFLAGS_STATIC_DOCKER
+	" \
+	./docker
 echo "Created binary: $DEST/docker-$VERSION"

+ 1 - 1
hack/make/cross

@@ -17,7 +17,7 @@ for platform in $DOCKER_CROSSPLATFORMS; do
 		mkdir -p "$DEST/$platform" # bundles/VERSION/cross/GOOS/GOARCH/docker-VERSION
 		export GOOS=${platform%/*}
 		export GOARCH=${platform##*/}
-		export LDFLAGS_STATIC="" # we just need a simple client for these platforms (TODO this might change someday)
+		export LDFLAGS_STATIC_DOCKER="" # we just need a simple client for these platforms (TODO this might change someday)
 		source "$(dirname "$BASH_SOURCE")/binary" "$DEST/$platform"
 	)
 done

+ 10 - 2
hack/make/dynbinary

@@ -3,7 +3,15 @@
 DEST=$1
 
 # dockerinit still needs to be a static binary, even if docker is dynamic
-CGO_ENABLED=0 go build -o $DEST/dockerinit-$VERSION -ldflags "$LDFLAGS -d" "${BUILDFLAGS[@]}" ./dockerinit
+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
 
@@ -23,6 +31,6 @@ export DOCKER_INITSHA1="$($sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)"
 # exported so that "dyntest" can easily access it later without recalculating it
 
 (
-	export LDFLAGS_STATIC="-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X github.com/dotcloud/docker/dockerversion.INITPATH \"$DOCKER_INITPATH\""
+	export LDFLAGS_STATIC_DOCKER="-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X github.com/dotcloud/docker/dockerversion.INITPATH \"$DOCKER_INITPATH\""
 	source "$(dirname "$BASH_SOURCE")/binary"
 )

+ 3 - 1
hack/make/dyntest

@@ -12,6 +12,8 @@ fi
 
 (
 	export TEST_DOCKERINIT_PATH="$INIT"
-	export LDFLAGS_STATIC="-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\""
+	export LDFLAGS_STATIC_DOCKER="
+		-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\"
+	"
 	source "$(dirname "$BASH_SOURCE")/test"
 )

+ 3 - 1
hack/make/dyntest-integration

@@ -12,6 +12,8 @@ fi
 
 (
 	export TEST_DOCKERINIT_PATH="$INIT"
-	export LDFLAGS_STATIC="-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\""
+	export LDFLAGS_STATIC_DOCKER="
+		-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\"
+	"
 	source "$(dirname "$BASH_SOURCE")/test-integration"
 )

+ 2 - 2
hack/make/test

@@ -4,9 +4,9 @@ DEST=$1
 
 set -e
 
-TEXTRESET=$'\033[0m' # reset the foreground colour
 RED=$'\033[31m'
 GREEN=$'\033[32m'
+TEXTRESET=$'\033[0m' # reset the foreground colour
 
 # Run Docker's test suite, including sub-packages, and store their output as a bundle
 # If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
@@ -22,7 +22,7 @@ bundle_test() {
 		for test_dir in $(find_dirs '*_test.go'); do
 			echo
 
-			if ! LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir "$test_dir"; then
+			if ! LDFLAGS="$LDFLAGS $LDFLAGS_STATIC_DOCKER" go_test_dir "$test_dir"; then
 				TESTS_FAILED+=("$test_dir")
 				echo
 				echo "${RED}Tests failed: $test_dir${TEXTRESET}"

+ 1 - 1
hack/make/test-integration

@@ -5,7 +5,7 @@ DEST=$1
 set -e
 
 bundle_test_integration() {
-	LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir ./integration \
+	LDFLAGS="$LDFLAGS $LDFLAGS_STATIC_DOCKER" go_test_dir ./integration \
 		"-coverpkg $(find_dirs '*.go' | sed 's,^\.,github.com/dotcloud/docker,g' | paste -d, -s)"
 }