Makefile 9.2 KB

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