From be344cf0d8e4f9881724f49398603a6e3109bc89 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Thu, 6 Mar 2014 19:55:22 -0700 Subject: [PATCH] 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 (github: tianon) --- hack/make.sh | 18 ++++++++++++++++-- hack/make/binary | 9 ++++++++- hack/make/cross | 2 +- hack/make/dynbinary | 12 ++++++++++-- hack/make/dyntest | 4 +++- hack/make/dyntest-integration | 4 +++- hack/make/test | 4 ++-- hack/make/test-integration | 2 +- 8 files changed, 44 insertions(+), 11 deletions(-) diff --git a/hack/make.sh b/hack/make.sh index 73c53c850a..63edca4d4c 100755 --- a/hack/make.sh +++ b/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 \ diff --git a/hack/make/binary b/hack/make/binary index b7c318e6cb..7272b1ede0 100644 --- a/hack/make/binary +++ b/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" diff --git a/hack/make/cross b/hack/make/cross index a67ab6c28a..e8f90e29b7 100644 --- a/hack/make/cross +++ b/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 diff --git a/hack/make/dynbinary b/hack/make/dynbinary index e7a767e102..b418fc409c 100644 --- a/hack/make/dynbinary +++ b/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" ) diff --git a/hack/make/dyntest b/hack/make/dyntest index 555517fd05..744db3e999 100644 --- a/hack/make/dyntest +++ b/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" ) diff --git a/hack/make/dyntest-integration b/hack/make/dyntest-integration index b3a2d7be63..ef7e6a5a41 100644 --- a/hack/make/dyntest-integration +++ b/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" ) diff --git a/hack/make/test b/hack/make/test index 68b4c52202..39ba5cd3a5 100644 --- a/hack/make/test +++ b/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}" diff --git a/hack/make/test-integration b/hack/make/test-integration index a60efebfc3..0af4c23c48 100644 --- a/hack/make/test-integration +++ b/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)" }