Carry #27834 — Do not require `.git` in the build context
Sebastiaan van Stijn authored on 2017/02/05 12:19:16... | ... |
@@ -71,8 +71,9 @@ |
71 | 71 |
# |
72 | 72 |
# 4. Build the docker executable binaries by running one of the following: |
73 | 73 |
# |
74 |
-# >> docker run --name binaries nativebuildimage hack\make.ps1 -Binary |
|
75 |
-# >> docker run --name binaries -m 2GB nativebuildimage hack\make.ps1 -Binary (if using Hyper-V containers) |
|
74 |
+# >> $DOCKER_GITCOMMIT=(git rev-parse --short HEAD) |
|
75 |
+# >> docker run --name binaries -e DOCKER_GITCOMMIT=$DOCKER_GITCOMMIT nativebuildimage hack\make.ps1 -Binary |
|
76 |
+# >> docker run --name binaries -e DOCKER_GITCOMMIT=$DOCKER_GITCOMMIT -m 2GB nativebuildimage hack\make.ps1 -Binary (if using Hyper-V containers) |
|
76 | 77 |
# |
77 | 78 |
# |
78 | 79 |
# 5. Copy the binaries out of the container, replacing HostPath with an appropriate destination |
... | ... |
@@ -98,19 +99,14 @@ |
98 | 98 |
# ----------------------------------------------------------------------------------------- |
99 | 99 |
|
100 | 100 |
|
101 |
-# The validation tests can either run in a container, or directly on the host. To run in a |
|
102 |
-# container, ensure you have created the nativebuildimage above. Then run one of the |
|
103 |
-# following from an (elevated) Windows PowerShell prompt: |
|
104 |
-# |
|
105 |
-# >> docker run --rm nativebuildimage hack\make.ps1 -DCO -PkgImports -GoFormat |
|
106 |
-# >> docker run --rm -m 2GB nativebuildimage hack\make.ps1 -DCO -PkgImports -GoFormat (if using Hyper-V containers) |
|
107 |
- |
|
108 |
-# To run the validation tests on the host, from the root of the repository, run the |
|
109 |
-# following from a Windows PowerShell prompt (elevation is not required): (Note Go |
|
110 |
-# must be installed to run these tests) |
|
101 |
+# The validation tests can only run directly on the host. This is because they calculate |
|
102 |
+# information from the git repo, but the .git directory is not passed into the image as |
|
103 |
+# it is excluded via .dockerignore. Run the following from a Windows PowerShell prompt |
|
104 |
+# (elevation is not required): (Note Go must be installed to run these tests) |
|
111 | 105 |
# |
112 | 106 |
# >> hack\make.ps1 -DCO -PkgImports -GoFormat |
113 | 107 |
|
108 |
+ |
|
114 | 109 |
# ----------------------------------------------------------------------------------------- |
115 | 110 |
|
116 | 111 |
|
... | ... |
@@ -124,7 +120,7 @@ |
124 | 124 |
# ----------------------------------------------------------------------------------------- |
125 | 125 |
|
126 | 126 |
|
127 |
-# To run all tests and binary build, ensure you have created the nativebuildimage above. Then |
|
127 |
+# To run unit tests and binary build, ensure you have created the nativebuildimage above. Then |
|
128 | 128 |
# run one of the following from an (elevated) Windows PowerShell prompt: |
129 | 129 |
# |
130 | 130 |
# >> docker run nativebuildimage hack\make.ps1 -All |
... | ... |
@@ -10,6 +10,9 @@ export DOCKER_INCREMENTAL_BINARY |
10 | 10 |
DOCKER_OSARCH := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKER_ENGINE_OSARCH:-$$DOCKER_CLIENT_OSARCH}') |
11 | 11 |
DOCKERFILE := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKERFILE}') |
12 | 12 |
|
13 |
+DOCKER_GITCOMMIT := $(shell git rev-parse --short HEAD || echo unsupported) |
|
14 |
+export DOCKER_GITCOMMIT |
|
15 |
+ |
|
13 | 16 |
# env vars passed through directly to Docker's build scripts |
14 | 17 |
# to allow things like `make KEEPBUNDLE=1 binary` easily |
15 | 18 |
# `project/PACKAGERS.md` have some limited documentation of some of these |
... | ... |
@@ -49,7 +52,7 @@ DOCKER_MOUNT := $(if $(BIND_DIR),-v "$(CURDIR)/$(BIND_DIR):/go/src/github.com/do |
49 | 49 |
# 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. |
50 | 50 |
# The volume will be cleaned up when the container is removed due to `--rm`. |
51 | 51 |
# 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. |
52 |
-DOCKER_MOUNT := $(if $(DOCKER_MOUNT),$(DOCKER_MOUNT),-v /go/src/github.com/docker/docker/bundles) |
|
52 |
+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 |
|
53 | 53 |
|
54 | 54 |
# This allows to set the docker-dev container name |
55 | 55 |
DOCKER_CONTAINER_NAME := $(if $(CONTAINER_NAME),--name $(CONTAINER_NAME),) |
... | ... |
@@ -21,7 +21,7 @@ |
21 | 21 |
"hack\make.ps1 -Client" to build just the client 64-bit binary |
22 | 22 |
"hack\make.ps1 -TestUnit" to run unit tests |
23 | 23 |
"hack\make.ps1 -Binary -TestUnit" to build the binaries and run unit tests |
24 |
- "hack\make.ps1 -All" to run everything this script knows about |
|
24 |
+ "hack\make.ps1 -All" to run everything this script knows about that can run in a container |
|
25 | 25 |
|
26 | 26 |
.PARAMETER Client |
27 | 27 |
Builds the client binaries. |
... | ... |
@@ -48,24 +48,23 @@ |
48 | 48 |
Adds a custom string to be appended to the commit ID (spaces are stripped). |
49 | 49 |
|
50 | 50 |
.PARAMETER DCO |
51 |
- Runs the DCO (Developer Certificate Of Origin) test. |
|
51 |
+ Runs the DCO (Developer Certificate Of Origin) test (must be run outside a container). |
|
52 | 52 |
|
53 | 53 |
.PARAMETER PkgImports |
54 |
- Runs the pkg\ directory imports test. |
|
54 |
+ Runs the pkg\ directory imports test (must be run outside a container). |
|
55 | 55 |
|
56 | 56 |
.PARAMETER GoFormat |
57 |
- Runs the Go formatting test. |
|
57 |
+ Runs the Go formatting test (must be run outside a container). |
|
58 | 58 |
|
59 | 59 |
.PARAMETER TestUnit |
60 | 60 |
Runs unit tests. |
61 | 61 |
|
62 | 62 |
.PARAMETER All |
63 |
- Runs everything this script knows about. |
|
63 |
+ Runs everything this script knows about that can run in a container. |
|
64 | 64 |
|
65 | 65 |
|
66 | 66 |
TODO |
67 | 67 |
- Unify the head commit |
68 |
-- Sort out the GITCOMMIT environment variable in the absence of a .git (longer term) |
|
69 | 68 |
- Add golint and other checks (swagger maybe?) |
70 | 69 |
|
71 | 70 |
#> |
... | ... |
@@ -334,7 +333,9 @@ Try { |
334 | 334 |
Push-Location $root |
335 | 335 |
|
336 | 336 |
# Handle the "-All" shortcut to turn on all things we can handle. |
337 |
- if ($All) { $Client=$True; $Daemon=$True; $DCO=$True; $PkgImports=$True; $GoFormat=$True; $TestUnit=$True } |
|
337 |
+ # Note we expressly only include the items which can run in a container - the validations tests cannot |
|
338 |
+ # as they require the .git directory which is excluded from the image by .dockerignore |
|
339 |
+ if ($All) { $Client=$True; $Daemon=$True; $TestUnit=$True } |
|
338 | 340 |
|
339 | 341 |
# Handle the "-Binary" shortcut to build both client and daemon. |
340 | 342 |
if ($Binary) { $Client = $True; $Daemon = $True } |
... | ... |
@@ -70,7 +70,9 @@ DEFAULT_BUNDLES=( |
70 | 70 |
|
71 | 71 |
VERSION=$(< ./VERSION) |
72 | 72 |
! BUILDTIME=$(date --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/') |
73 |
-if command -v git &> /dev/null && [ -d .git ] && git rev-parse &> /dev/null; then |
|
73 |
+if [ "$DOCKER_GITCOMMIT" ]; then |
|
74 |
+ GITCOMMIT="$DOCKER_GITCOMMIT" |
|
75 |
+elif command -v git &> /dev/null && [ -d .git ] && git rev-parse &> /dev/null; then |
|
74 | 76 |
GITCOMMIT=$(git rev-parse --short HEAD) |
75 | 77 |
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then |
76 | 78 |
GITCOMMIT="$GITCOMMIT-unsupported" |
... | ... |
@@ -83,8 +85,6 @@ if command -v git &> /dev/null && [ -d .git ] && git rev-parse &> /dev/null; the |
83 | 83 |
git status --porcelain --untracked-files=no |
84 | 84 |
echo "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" |
85 | 85 |
fi |
86 |
-elif [ "$DOCKER_GITCOMMIT" ]; then |
|
87 |
- GITCOMMIT="$DOCKER_GITCOMMIT" |
|
88 | 86 |
else |
89 | 87 |
echo >&2 'error: .git directory missing and DOCKER_GITCOMMIT not specified' |
90 | 88 |
echo >&2 ' Please either build with the .git directory accessible, or specify the' |