From 0b23393ba1901df3d08916fa977707db58699eca Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Thu, 6 Mar 2014 13:39:17 -0700 Subject: [PATCH] Update build tags such that we can properly compile on all platforms (especially for packagers), and updated hack/PACKAGERS.md to mention the DOCKER_BUILDTAGS variable that will need to be set for binaries that might be used on AppArmor (such as Debian and especially Ubuntu) Docker-DCO-1.1-Signed-off-by: Andrew Page (github: tianon) --- Dockerfile | 1 + hack/PACKAGERS.md | 9 +++++++++ hack/make.sh | 5 ++--- hack/make/binary | 2 +- hack/make/cross | 1 - hack/make/dynbinary | 2 +- pkg/libcontainer/apparmor/apparmor.go | 2 +- pkg/libcontainer/apparmor/apparmor_disabled.go | 2 +- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9271aa0d02..9929a10f3c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -87,6 +87,7 @@ RUN git config --global user.email 'docker-dummy@example.com' VOLUME /var/lib/docker WORKDIR /go/src/github.com/dotcloud/docker +ENV DOCKER_BUILDTAGS apparmor # Wrap all commands in the "docker-in-docker" script to allow nested containers ENTRYPOINT ["hack/dind"] diff --git a/hack/PACKAGERS.md b/hack/PACKAGERS.md index 8d9749b4f8..3948f001b5 100644 --- a/hack/PACKAGERS.md +++ b/hack/PACKAGERS.md @@ -148,6 +148,15 @@ This will cause the build scripts to set up a reasonable `GOPATH` that automatically and properly includes both dotcloud/docker from the local directory, and the local "./vendor" directory as necessary. +### `DOCKER_BUILDTAGS` + +If you're building a binary that may need to be used on platforms that include +AppArmor, you will need to set `DOCKER_BUILDTAGS` as follows: + +```bash +export DOCKER_BUILDTAGS='apparmor' +``` + ### Static Daemon If it is feasible within the constraints of your distribution, you should diff --git a/hack/make.sh b/hack/make.sh index 7f143dd464..73c53c850a 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -84,8 +84,7 @@ 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"' -BUILDFLAGS='-a' -BUILDTAGS="apparmor netgo" +BUILDFLAGS=( -a -tags "netgo $DOCKER_BUILDTAGS" ) HAVE_GO_TEST_COVER= if \ @@ -114,7 +113,7 @@ go_test_dir() { ( set -x cd "$dir" - go test ${testcover[@]} -ldflags "$LDFLAGS" $BUILDFLAGS $TESTFLAGS + go test ${testcover[@]} -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS ) } diff --git a/hack/make/binary b/hack/make/binary index 344be25a73..b7c318e6cb 100644 --- a/hack/make/binary +++ b/hack/make/binary @@ -2,5 +2,5 @@ DEST=$1 -go build -o $DEST/docker-$VERSION -ldflags "$LDFLAGS $LDFLAGS_STATIC" $BUILDFLAGS -tags "$BUILDTAGS" ./docker +go build -o $DEST/docker-$VERSION -ldflags "$LDFLAGS $LDFLAGS_STATIC" "${BUILDFLAGS[@]}" ./docker echo "Created binary: $DEST/docker-$VERSION" diff --git a/hack/make/cross b/hack/make/cross index 28424c432e..a67ab6c28a 100644 --- a/hack/make/cross +++ b/hack/make/cross @@ -18,7 +18,6 @@ for platform in $DOCKER_CROSSPLATFORMS; do export GOOS=${platform%/*} export GOARCH=${platform##*/} export LDFLAGS_STATIC="" # we just need a simple client for these platforms (TODO this might change someday) - export BUILDTAGS="netgo" source "$(dirname "$BASH_SOURCE")/binary" "$DEST/$platform" ) done diff --git a/hack/make/dynbinary b/hack/make/dynbinary index d5ea6ebe54..e7a767e102 100644 --- a/hack/make/dynbinary +++ b/hack/make/dynbinary @@ -3,7 +3,7 @@ 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 +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 diff --git a/pkg/libcontainer/apparmor/apparmor.go b/pkg/libcontainer/apparmor/apparmor.go index d07c710dbe..a6d57d4f09 100644 --- a/pkg/libcontainer/apparmor/apparmor.go +++ b/pkg/libcontainer/apparmor/apparmor.go @@ -1,4 +1,4 @@ -// +build apparmor +// +build apparmor,linux,amd64 package apparmor diff --git a/pkg/libcontainer/apparmor/apparmor_disabled.go b/pkg/libcontainer/apparmor/apparmor_disabled.go index 489484fcc6..77543e4a87 100644 --- a/pkg/libcontainer/apparmor/apparmor_disabled.go +++ b/pkg/libcontainer/apparmor/apparmor_disabled.go @@ -1,4 +1,4 @@ -// +build !apparmor +// +build !apparmor !linux !amd64 package apparmor