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