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