Merge pull request #4516 from tianon/fix-static-dockerinit

Fix dynbinary so that dockerinit can still be properly static even if it has to link against libapparmor for Ubuntu
This commit is contained in:
Guillaume J. Charmes 2014-03-07 10:15:49 -08:00
commit f27ad07139
9 changed files with 70 additions and 26 deletions

View file

@ -181,6 +181,12 @@ the file "./VERSION". This binary is usually installed somewhere like
### Dynamic Daemon / Client-only Binary
If you are only interested in a Docker client binary, set `DOCKER_CLIENTONLY` to a non-empty value using something similar to the following: (which will prevent the extra step of compiling dockerinit)
```bash
export DOCKER_CLIENTONLY=1
```
If you need to (due to distro policy, distro library availability, or for other
reasons) create a dynamically compiled daemon binary, or if you are only
interested in creating a client binary for Docker, use something similar to the

View file

@ -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 \

View file

@ -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"

View file

@ -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

View file

@ -2,27 +2,40 @@
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
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
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
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
echo >&2 'error: cannot find sha1sum command or equivalent'
exit 1
# DOCKER_CLIENTONLY must be truthy, so we don't need to bother with dockerinit :)
export DOCKER_INITSHA1=""
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)"
# 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"
)

View file

@ -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"
)

View file

@ -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"
)

View file

@ -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}"

View file

@ -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)"
}