Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be344cf

Browse files
committed
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 <[email protected]> (github: tianon)
1 parent 78dc1ed commit be344cf

8 files changed

Lines changed: 44 additions & 11 deletions

File tree

hack/make.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,24 @@ if [ ! "$GOPATH" ]; then
8282
fi
8383

8484
# 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'
8792
BUILDFLAGS=( -a -tags "netgo $DOCKER_BUILDTAGS" )
8893

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+
89103
HAVE_GO_TEST_COVER=
90104
if \
91105
go help testflag | grep -- -cover > /dev/null \

hack/make/binary

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@
22

33
DEST=$1
44

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
613
echo "Created binary: $DEST/docker-$VERSION"

hack/make/cross

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ for platform in $DOCKER_CROSSPLATFORMS; do
1717
mkdir -p "$DEST/$platform" # bundles/VERSION/cross/GOOS/GOARCH/docker-VERSION
1818
export GOOS=${platform%/*}
1919
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)
2121
source "$(dirname "$BASH_SOURCE")/binary" "$DEST/$platform"
2222
)
2323
done

hack/make/dynbinary

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
DEST=$1
44

55
# 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
715
echo "Created binary: $DEST/dockerinit-$VERSION"
816
ln -sf dockerinit-$VERSION $DEST/dockerinit
917

@@ -23,6 +31,6 @@ export DOCKER_INITSHA1="$($sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)"
2331
# exported so that "dyntest" can easily access it later without recalculating it
2432

2533
(
26-
export LDFLAGS_STATIC="-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X github.com/dotcloud/docker/dockerversion.INITPATH \"$DOCKER_INITPATH\""
34+
export LDFLAGS_STATIC_DOCKER="-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X github.com/dotcloud/docker/dockerversion.INITPATH \"$DOCKER_INITPATH\""
2735
source "$(dirname "$BASH_SOURCE")/binary"
2836
)

hack/make/dyntest

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ fi
1212

1313
(
1414
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+
"
1618
source "$(dirname "$BASH_SOURCE")/test"
1719
)

hack/make/dyntest-integration

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ fi
1212

1313
(
1414
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+
"
1618
source "$(dirname "$BASH_SOURCE")/test-integration"
1719
)

hack/make/test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ DEST=$1
44

55
set -e
66

7-
TEXTRESET=$'\033[0m' # reset the foreground colour
87
RED=$'\033[31m'
98
GREEN=$'\033[32m'
9+
TEXTRESET=$'\033[0m' # reset the foreground colour
1010

1111
# Run Docker's test suite, including sub-packages, and store their output as a bundle
1212
# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
@@ -22,7 +22,7 @@ bundle_test() {
2222
for test_dir in $(find_dirs '*_test.go'); do
2323
echo
2424

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
2626
TESTS_FAILED+=("$test_dir")
2727
echo
2828
echo "${RED}Tests failed: $test_dir${TEXTRESET}"

hack/make/test-integration

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ DEST=$1
55
set -e
66

77
bundle_test_integration() {
8-
LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir ./integration \
8+
LDFLAGS="$LDFLAGS $LDFLAGS_STATIC_DOCKER" go_test_dir ./integration \
99
"-coverpkg $(find_dirs '*.go' | sed 's,^\.,github.com/dotcloud/docker,g' | paste -d, -s)"
1010
}
1111

0 commit comments

Comments
 (0)