Debian Codegraph @

engine/Makefile

raw symbols SCIP
1 DOCKER ?= docker
2 BUILDX ?= $(DOCKER) buildx
3
4 DOCKER_GITCOMMIT := $(shell git rev-parse HEAD)
5 export DOCKER_GITCOMMIT
6
7 # allow overriding the repository and branch that validation scripts are running
8 # against these are used in hack/validate/.validate to check what changed in the PR.
9 export VALIDATE_REPO
10 export VALIDATE_BRANCH
11 export VALIDATE_ORIGIN_BRANCH
12
13 export PAGER
14 export GIT_PAGER
15
16 # env vars passed through directly to Docker's build scripts
17 # to allow things like `make KEEPBUNDLE=1 binary` easily
18 # `project/PACKAGERS.md` have some limited documentation of some of these
19 #
20 # DOCKER_LDFLAGS can be used to pass additional parameters to -ldflags
21 # option of "go build". For example, a built-in graphdriver priority list
22 # can be changed during build time like this:
23 #
24 # make DOCKER_LDFLAGS="-X github.com/docker/docker/daemon/graphdriver.priority=overlay2,zfs" dynbinary
25 #
26 DOCKER_ENVS := \
27 -e BUILDFLAGS \
28 -e KEEPBUNDLE \
29 -e DOCKER_BUILD_ARGS \
30 -e DOCKER_BUILD_GOGC \
31 -e DOCKER_BUILD_OPTS \
32 -e DOCKER_BUILD_PKGS \
33 -e DOCKER_BUILDKIT \
34 -e DOCKER_CLI_PATH \
35 -e DOCKERCLI_VERSION \
36 -e DOCKERCLI_REPOSITORY \
37 -e DOCKERCLI_INTEGRATION_VERSION \
38 -e DOCKERCLI_INTEGRATION_REPOSITORY \
39 -e DOCKER_DEBUG \
40 -e DOCKER_EXPERIMENTAL \
41 -e DOCKER_GITCOMMIT \
42 -e DOCKER_GRAPHDRIVER \
43 -e DOCKER_LDFLAGS \
44 -e DOCKER_PORT \
45 -e DOCKER_REMAP_ROOT \
46 -e DOCKER_ROOTLESS \
47 -e DOCKER_STORAGE_OPTS \
48 -e DOCKER_TEST_HOST \
49 -e DOCKER_USERLANDPROXY \
50 -e DOCKERD_ARGS \
51 -e DELVE_PORT \
52 -e FIREWALLD \
53 -e GITHUB_ACTIONS \
54 -e TEST_FORCE_VALIDATE \
55 -e TEST_INTEGRATION_DIR \
56 -e TEST_INTEGRATION_USE_SNAPSHOTTER \
57 -e TEST_INTEGRATION_FAIL_FAST \
58 -e TEST_SKIP_INTEGRATION \
59 -e TEST_SKIP_INTEGRATION_CLI \
60 -e TESTCOVERAGE \
61 -e TESTDEBUG \
62 -e TESTDIRS \
63 -e TESTFLAGS \
64 -e TESTFLAGS_INTEGRATION \
65 -e TESTFLAGS_INTEGRATION_CLI \
66 -e TEST_FILTER \
67 -e TIMEOUT \
68 -e VALIDATE_REPO \
69 -e VALIDATE_BRANCH \
70 -e VALIDATE_ORIGIN_BRANCH \
71 -e VERSION \
72 -e PLATFORM \
73 -e DEFAULT_PRODUCT_LICENSE \
74 -e PRODUCT \
75 -e PACKAGER_NAME \
76 -e PAGER \
77 -e GIT_PAGER \
78 -e OTEL_EXPORTER_OTLP_ENDPOINT \
79 -e OTEL_EXPORTER_OTLP_PROTOCOL \
80 -e OTEL_SERVICE_NAME
81 # note: we _cannot_ add "-e DOCKER_BUILDTAGS" here because even if it's unset in the shell, that would shadow the "ENV DOCKER_BUILDTAGS" set in our Dockerfile, which is very important for our official builds
82
83 # to allow `make BIND_DIR=. shell` or `make BIND_DIR= test`
84 # (default to no bind mount if DOCKER_HOST is set)
85 # note: BINDDIR is supported for backwards-compatibility here
86 BIND_DIR := $(if $(BINDDIR),$(BINDDIR),$(if $(DOCKER_HOST),,.))
87
88 # DOCKER_MOUNT can be overridden, but use at your own risk!
89 ifndef DOCKER_MOUNT
90 DOCKER_MOUNT := $(if $(BIND_DIR),-v "$(BIND_DIR):/go/src/github.com/docker/docker/$(BIND_DIR)")
91 DOCKER_MOUNT := $(if $(DOCKER_BINDDIR_MOUNT_OPTS),$(DOCKER_MOUNT):$(DOCKER_BINDDIR_MOUNT_OPTS),$(DOCKER_MOUNT))
92
93 # 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.
94 # The volume will be cleaned up when the container is removed due to `--rm`.
95 # 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.
96 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"
97
98 DOCKER_MOUNT_CACHE := -v docker-dev-cache:/root/.cache -v docker-mod-cache:/go/pkg/mod/
99 DOCKER_MOUNT_CLI := $(if $(DOCKER_CLI_PATH),-v $(shell dirname $(DOCKER_CLI_PATH)):/usr/local/cli,)
100
101 ifdef BIND_GIT
102 # Gets the common .git directory (even from inside a git worktree)
103 GITDIR := $(shell realpath $(shell git rev-parse --git-common-dir))
104 MOUNT_GITDIR := $(if $(GITDIR),-v "$(GITDIR):$(GITDIR)")
105 endif
106
107 DOCKER_MOUNT := $(DOCKER_MOUNT) $(DOCKER_MOUNT_CACHE) $(DOCKER_MOUNT_CLI) $(DOCKER_MOUNT_BASH_COMPLETION) $(MOUNT_GITDIR)
108 endif # ifndef DOCKER_MOUNT
109
110 # This allows to set the docker-dev container name
111 DOCKER_CONTAINER_NAME := $(if $(CONTAINER_NAME),--name $(CONTAINER_NAME),)
112
113 DOCKER_IMAGE := docker-dev
114 DOCKER_PORT_FORWARD := $(if $(DOCKER_PORT),-p "$(DOCKER_PORT)",)
115 DELVE_PORT_FORWARD := $(if $(DELVE_PORT),-p "$(DELVE_PORT)",)
116
117 DOCKER_FLAGS := $(DOCKER) run --rm --privileged $(DOCKER_CONTAINER_NAME) $(DOCKER_ENVS) $(DOCKER_MOUNT) $(DOCKER_PORT_FORWARD) $(DELVE_PORT_FORWARD)
118
119 SWAGGER_DOCS_PORT ?= 9000
120
121 define \n
122
123
124 endef
125
126 # if this session isn't interactive, then we don't want to allocate a
127 # TTY, which would fail, but if it is interactive, we do want to attach
128 # so that the user can send e.g. ^C through.
129 INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0)
130 ifeq ($(INTERACTIVE), 1)
131 DOCKER_FLAGS += -t
132 endif
133
134 # on GitHub Runners input device is not a TTY but we allocate a pseudo-one,
135 # otherwise keep STDIN open even if not attached if not a GitHub Runner.
136 ifeq ($(GITHUB_ACTIONS),true)
137 DOCKER_FLAGS += -t
138 else
139 DOCKER_FLAGS += -i
140 endif
141
142 DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)"
143
144 DOCKER_BUILD_ARGS += --build-arg=GO_VERSION
145 DOCKER_BUILD_ARGS += --build-arg=DOCKERCLI_VERSION
146 DOCKER_BUILD_ARGS += --build-arg=DOCKERCLI_REPOSITORY
147 DOCKER_BUILD_ARGS += --build-arg=DOCKERCLI_INTEGRATION_VERSION
148 DOCKER_BUILD_ARGS += --build-arg=DOCKERCLI_INTEGRATION_REPOSITORY
149 ifdef DOCKER_SYSTEMD
150 DOCKER_BUILD_ARGS += --build-arg=SYSTEMD=true
151 endif
152 ifdef FIREWALLD
153 DOCKER_BUILD_ARGS += --build-arg=FIREWALLD=true
154 endif
155
156 BUILD_OPTS := ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS}
157 BUILD_CMD := $(BUILDX) build
158 BAKE_CMD := $(BUILDX) bake
159
160 default: binary
161
162 .PHONY: all
163 all: build ## validate all checks, build linux binaries, run all tests,\ncross build non-linux binaries, and generate archives
164 $(DOCKER_RUN_DOCKER) bash -c 'hack/validate/default && hack/make.sh'
165
166 .PHONY: binary
167 binary: bundles ## build statically linked linux binaries
168 $(BAKE_CMD) binary
169
170 .PHONY: dynbinary
171 dynbinary: bundles ## build dynamically linked linux binaries
172 $(BAKE_CMD) dynbinary
173
174 .PHONY: cross
175 cross: bundles ## cross build the binaries
176 $(BAKE_CMD) binary-cross
177
178 bundles:
179 mkdir bundles
180
181 .PHONY: clean
182 clean: clean-cache
183
184 .PHONY: clean-cache
185 clean-cache: ## remove the docker volumes that are used for caching in the dev-container
186 docker volume rm -f docker-dev-cache docker-mod-cache
187
188 .PHONY: help
189 help: ## this help
190 @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {gsub("\\\\n",sprintf("\n%22c",""), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
191
192 .PHONY: install
193 install: ## install the linux binaries
194 KEEPBUNDLE=1 hack/make.sh install-binary
195
196 .PHONY: run
197 run: build ## run the docker daemon in a container
198 $(DOCKER_RUN_DOCKER) sh -c "KEEPBUNDLE=1 hack/make.sh install-binary run"
199
200 .PHONY: build
201 ifeq ($(BIND_DIR), .)
202 build: shell_target := --target=dev-base
203 else
204 build: shell_target := --target=dev
205 endif
206 build: validate-bind-dir bundles
207 $(BUILD_CMD) $(BUILD_OPTS) $(shell_target) --load -t "$(DOCKER_IMAGE)" .
208
209 .PHONY: shell
210 shell: build ## start a shell inside the build env
211 $(DOCKER_RUN_DOCKER) bash
212
213 .PHONY: test
214 test: build test-unit ## run the unit, integration and docker-py tests
215 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration test-docker-py
216
217 .PHONY: test-docker-py
218 test-docker-py: build ## run the docker-py tests
219 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-docker-py
220
221 .PHONY: test-integration-cli
222 test-integration-cli: test-integration ## (DEPRECATED) use test-integration
223
224 .PHONY: test-integration
225 ifneq ($(and $(TEST_SKIP_INTEGRATION),$(TEST_SKIP_INTEGRATION_CLI)),)
226 test-integration:
227 @echo Both integrations suites skipped per environment variables
228 else
229 test-integration: build ## run the integration tests
230 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration
231 endif
232
233 .PHONY: test-integration-flaky
234 test-integration-flaky: build ## run the stress test for all new integration tests
235 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration-flaky
236
237 .PHONY: test-unit
238 test-unit: build ## run the unit tests
239 $(DOCKER_RUN_DOCKER) hack/test/unit
240
241 .PHONY: validate
242 validate: build ## validate DCO, Seccomp profile generation, gofmt,\n./pkg/ isolation, golint, tests, tomls, go vet and vendor
243 $(DOCKER_RUN_DOCKER) hack/validate/all
244
245 .PHONY: validate-generate-files
246 validate-generate-files:
247 $(BUILD_CMD) --target "validate" \
248 --output "type=cacheonly" \
249 --file "./hack/dockerfiles/generate-files.Dockerfile" .
250
251 .PHONY: validate-%
252 validate-%: build ## validate specific check
253 $(DOCKER_RUN_DOCKER) hack/validate/$*
254
255 .PHONY: win
256 win: bundles ## cross build the binary for windows
257 $(BAKE_CMD) --set *.platform=windows/amd64 binary
258
259 .PHONY: swagger-gen
260 swagger-gen:
261 docker run --rm -v $(PWD):/go/src/github.com/docker/docker \
262 -w /go/src/github.com/docker/docker \
263 --entrypoint hack/generate-swagger-api.sh \
264 -e GOPATH=/go \
265 quay.io/goswagger/swagger:0.7.4
266
267 .PHONY: swagger-docs
268 swagger-docs: ## preview the API documentation
269 @echo "API docs preview will be running at http://localhost:$(SWAGGER_DOCS_PORT)"
270 @docker run --rm -v $(PWD)/api/swagger.yaml:/usr/share/nginx/html/swagger.yaml \
271 -e 'REDOC_OPTIONS=hide-hostname="true" lazy-rendering' \
272 -p $(SWAGGER_DOCS_PORT):80 \
273 bfirsh/redoc:1.14.0
274
275 .PHONY: generate-files
276 generate-files:
277 $(eval $@_TMP_OUT := $(shell mktemp -d -t moby-output.XXXXXXXXXX))
278 @if [ -z "$($@_TMP_OUT)" ]; then \
279 echo "Temp dir is not set"; \
280 exit 1; \
281 fi
282 $(BUILD_CMD) --target "update" \
283 --output "type=local,dest=$($@_TMP_OUT)" \
284 --file "./hack/dockerfiles/generate-files.Dockerfile" .
285 cp -R "$($@_TMP_OUT)"/. .
286 rm -rf "$($@_TMP_OUT)"/*
287
288 .PHONY: validate-bind-dir
289 validate-bind-dir:
290 @case "$(BIND_DIR)" in \
291 ".."*|"/"*) echo "Make needs to be run from the project-root directory, with BIND_DIR set to \".\" or a subdir"; \
292 exit 1 ;; \
293 esac