From eed2c0f36737316bb52b190ffd2aead7b4f0330c Mon Sep 17 00:00:00 2001 From: John Howard Date: Thu, 27 Oct 2016 12:41:33 -0700 Subject: [PATCH 1/4] Add .git to .dockerignore Signed-off-by: John Howard Signed-off-by: Vincent Demeester Upstream-commit: a3b3e61a6c7bb52740f1ef305d1e4304686d4ecc Component: engine --- components/engine/.dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/components/engine/.dockerignore b/components/engine/.dockerignore index 082cac9224..2ce8321a7e 100644 --- a/components/engine/.dockerignore +++ b/components/engine/.dockerignore @@ -2,3 +2,4 @@ bundles .gopath vendor/pkg .go-pkg-cache +.git From 7e467dc7f79d5b49b2af8c6b162f8a1f7f02e3f1 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Wed, 16 Nov 2016 11:49:32 +0100 Subject: [PATCH 2/4] Do not required `.git` in the build context - export DOCKER_GITCOMMIT in the Makefile - prioritize DOCKER_GITCOMMIT against the `git` command in `./hack/make.sh` - Also add `integration-cli/bundles` to gitignore (it's generated when using integration-cli shell) Signed-off-by: Vincent Demeester Upstream-commit: fae6ca2bb42d9c4146df413bcce701431298161c Component: engine --- components/engine/.dockerignore | 1 + components/engine/Makefile | 3 +++ components/engine/hack/make.sh | 7 ++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/components/engine/.dockerignore b/components/engine/.dockerignore index 2ce8321a7e..b605b08c61 100644 --- a/components/engine/.dockerignore +++ b/components/engine/.dockerignore @@ -1,4 +1,5 @@ bundles +integration-cli/bundles .gopath vendor/pkg .go-pkg-cache diff --git a/components/engine/Makefile b/components/engine/Makefile index 747340ffd4..7fe4872b04 100644 --- a/components/engine/Makefile +++ b/components/engine/Makefile @@ -10,6 +10,9 @@ export DOCKER_INCREMENTAL_BINARY DOCKER_OSARCH := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKER_ENGINE_OSARCH:-$$DOCKER_CLIENT_OSARCH}') DOCKERFILE := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKERFILE}') +DOCKER_GITCOMMIT := $(shell git rev-parse --short HEAD || echo unsupported) +export DOCKER_GITCOMMIT + # env vars passed through directly to Docker's build scripts # to allow things like `make KEEPBUNDLE=1 binary` easily # `project/PACKAGERS.md` have some limited documentation of some of these diff --git a/components/engine/hack/make.sh b/components/engine/hack/make.sh index 8b8c9aed73..8b2a4a975d 100755 --- a/components/engine/hack/make.sh +++ b/components/engine/hack/make.sh @@ -70,7 +70,9 @@ DEFAULT_BUNDLES=( VERSION=$(< ./VERSION) ! BUILDTIME=$(date --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/') -if command -v git &> /dev/null && [ -d .git ] && git rev-parse &> /dev/null; then +if [ "$DOCKER_GITCOMMIT" ]; then + GITCOMMIT="$DOCKER_GITCOMMIT" +elif command -v git &> /dev/null && [ -d .git ] && git rev-parse &> /dev/null; then GITCOMMIT=$(git rev-parse --short HEAD) if [ -n "$(git status --porcelain --untracked-files=no)" ]; then GITCOMMIT="$GITCOMMIT-unsupported" @@ -83,8 +85,7 @@ if command -v git &> /dev/null && [ -d .git ] && git rev-parse &> /dev/null; the git status --porcelain --untracked-files=no echo "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" fi -elif [ "$DOCKER_GITCOMMIT" ]; then - GITCOMMIT="$DOCKER_GITCOMMIT" + ! BUILDTIME=$(date --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/') &> /dev/null else echo >&2 'error: .git directory missing and DOCKER_GITCOMMIT not specified' echo >&2 ' Please either build with the .git directory accessible, or specify the' From 77aff38faeccedf201a6a29f3138db9ebb9e31cc Mon Sep 17 00:00:00 2001 From: John Howard Date: Fri, 20 Jan 2017 15:09:28 -0800 Subject: [PATCH 3/4] Windows updates for .git in .dockerignore Signed-off-by: John Howard jhoward@microsoft.com Signed-off-by: Vincent Demeester Upstream-commit: f32b267d1c09b0cc330bf42c8859a0eb00faf8b9 Component: engine --- components/engine/Dockerfile.windows | 22 +++++++++------------- components/engine/hack/make.ps1 | 15 ++++++++------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/components/engine/Dockerfile.windows b/components/engine/Dockerfile.windows index 26e62792bd..110c332712 100644 --- a/components/engine/Dockerfile.windows +++ b/components/engine/Dockerfile.windows @@ -71,8 +71,9 @@ # # 4. Build the docker executable binaries by running one of the following: # -# >> docker run --name binaries nativebuildimage hack\make.ps1 -Binary -# >> docker run --name binaries -m 2GB nativebuildimage hack\make.ps1 -Binary (if using Hyper-V containers) +# >> $DOCKER_GITCOMMIT=(git rev-parse --short HEAD) +# >> docker run --name binaries -e DOCKER_GITCOMMIT=$DOCKER_GITCOMMIT nativebuildimage hack\make.ps1 -Binary +# >> docker run --name binaries -e DOCKER_GITCOMMIT=$DOCKER_GITCOMMIT -m 2GB nativebuildimage hack\make.ps1 -Binary (if using Hyper-V containers) # # # 5. Copy the binaries out of the container, replacing HostPath with an appropriate destination @@ -98,19 +99,14 @@ # ----------------------------------------------------------------------------------------- -# The validation tests can either run in a container, or directly on the host. To run in a -# container, ensure you have created the nativebuildimage above. Then run one of the -# following from an (elevated) Windows PowerShell prompt: -# -# >> docker run --rm nativebuildimage hack\make.ps1 -DCO -PkgImports -GoFormat -# >> docker run --rm -m 2GB nativebuildimage hack\make.ps1 -DCO -PkgImports -GoFormat (if using Hyper-V containers) - -# To run the validation tests on the host, from the root of the repository, run the -# following from a Windows PowerShell prompt (elevation is not required): (Note Go -# must be installed to run these tests) +# The validation tests can only run directly on the host. This is because they calculate +# information from the git repo, but the .git directory is not passed into the image as +# it is excluded via .dockerignore. Run the following from a Windows PowerShell prompt +# (elevation is not required): (Note Go must be installed to run these tests) # # >> hack\make.ps1 -DCO -PkgImports -GoFormat + # ----------------------------------------------------------------------------------------- @@ -124,7 +120,7 @@ # ----------------------------------------------------------------------------------------- -# To run all tests and binary build, ensure you have created the nativebuildimage above. Then +# To run unit tests and binary build, ensure you have created the nativebuildimage above. Then # run one of the following from an (elevated) Windows PowerShell prompt: # # >> docker run nativebuildimage hack\make.ps1 -All diff --git a/components/engine/hack/make.ps1 b/components/engine/hack/make.ps1 index 224fbf18ce..54216d60f2 100644 --- a/components/engine/hack/make.ps1 +++ b/components/engine/hack/make.ps1 @@ -21,7 +21,7 @@ "hack\make.ps1 -Client" to build just the client 64-bit binary "hack\make.ps1 -TestUnit" to run unit tests "hack\make.ps1 -Binary -TestUnit" to build the binaries and run unit tests - "hack\make.ps1 -All" to run everything this script knows about + "hack\make.ps1 -All" to run everything this script knows about that can run in a container .PARAMETER Client Builds the client binaries. @@ -48,24 +48,23 @@ Adds a custom string to be appended to the commit ID (spaces are stripped). .PARAMETER DCO - Runs the DCO (Developer Certificate Of Origin) test. + Runs the DCO (Developer Certificate Of Origin) test (must be run outside a container). .PARAMETER PkgImports - Runs the pkg\ directory imports test. + Runs the pkg\ directory imports test (must be run outside a container). .PARAMETER GoFormat - Runs the Go formatting test. + Runs the Go formatting test (must be run outside a container). .PARAMETER TestUnit Runs unit tests. .PARAMETER All - Runs everything this script knows about. + Runs everything this script knows about that can run in a container. TODO - Unify the head commit -- Sort out the GITCOMMIT environment variable in the absence of a .git (longer term) - Add golint and other checks (swagger maybe?) #> @@ -314,7 +313,9 @@ Try { Push-Location $root # Handle the "-All" shortcut to turn on all things we can handle. - if ($All) { $Client=$True; $Daemon=$True; $DCO=$True; $PkgImports=$True; $GoFormat=$True; $TestUnit=$True } + # Note we expressly only include the items which can run in a container - the validations tests cannot + # as they require the .git directory which is excluded from the image by .dockerignore + if ($All) { $Client=$True; $Daemon=$True; $TestUnit=$True } # Handle the "-Binary" shortcut to build both client and daemon. if ($Binary) { $Client = $True; $Daemon = $True } From ba32ae9bba3baa6631e7e45731bb7b1b7b612bbd Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Mon, 30 Jan 2017 10:51:26 +0100 Subject: [PATCH 4/4] =?UTF-8?q?Bind=20mount=20`.git`=20=F0=9F=91=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Vincent Demeester Upstream-commit: 617be0ef2bbbce6f0e908734f8a5f2b6a7b93877 Component: engine --- components/engine/.dockerignore | 1 - components/engine/Makefile | 2 +- components/engine/hack/make.sh | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/components/engine/.dockerignore b/components/engine/.dockerignore index b605b08c61..2ce8321a7e 100644 --- a/components/engine/.dockerignore +++ b/components/engine/.dockerignore @@ -1,5 +1,4 @@ bundles -integration-cli/bundles .gopath vendor/pkg .go-pkg-cache diff --git a/components/engine/Makefile b/components/engine/Makefile index 7fe4872b04..65589227a8 100644 --- a/components/engine/Makefile +++ b/components/engine/Makefile @@ -52,7 +52,7 @@ DOCKER_MOUNT := $(if $(BIND_DIR),-v "$(CURDIR)/$(BIND_DIR):/go/src/github.com/do # This allows the test suite to be able to run without worrying about the underlying fs used by the container running the daemon (e.g. aufs-on-aufs), so long as the host running the container is running a supported fs. # The volume will be cleaned up when the container is removed due to `--rm`. # Note that `BIND_DIR` will already be set to `bundles` if `DOCKER_HOST` is not set (see above BIND_DIR line), in such case this will do nothing since `DOCKER_MOUNT` will already be set. -DOCKER_MOUNT := $(if $(DOCKER_MOUNT),$(DOCKER_MOUNT),-v /go/src/github.com/docker/docker/bundles) +DOCKER_MOUNT := $(if $(DOCKER_MOUNT),$(DOCKER_MOUNT),-v /go/src/github.com/docker/docker/bundles) -v $(CURDIR)/.git:/go/src/github.com/docker/docker/.git # This allows to set the docker-dev container name DOCKER_CONTAINER_NAME := $(if $(CONTAINER_NAME),--name $(CONTAINER_NAME),) diff --git a/components/engine/hack/make.sh b/components/engine/hack/make.sh index 8b2a4a975d..7dd86639da 100755 --- a/components/engine/hack/make.sh +++ b/components/engine/hack/make.sh @@ -85,7 +85,6 @@ elif command -v git &> /dev/null && [ -d .git ] && git rev-parse &> /dev/null; t git status --porcelain --untracked-files=no echo "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" fi - ! BUILDTIME=$(date --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/') &> /dev/null else echo >&2 'error: .git directory missing and DOCKER_GITCOMMIT not specified' echo >&2 ' Please either build with the .git directory accessible, or specify the'