github.com/afbjorklund/moby@v20.10.5+incompatible/Makefile (about) 1 .PHONY: all binary dynbinary build cross help install manpages run shell test test-docker-py test-integration test-unit validate win 2 3 ifdef USE_BUILDX 4 BUILDX ?= $(shell command -v buildx) 5 BUILDX ?= $(shell command -v docker-buildx) 6 DOCKER_BUILDX_CLI_PLUGIN_PATH ?= ~/.docker/cli-plugins/docker-buildx 7 BUILDX ?= $(shell if [ -x "$(DOCKER_BUILDX_CLI_PLUGIN_PATH)" ]; then echo $(DOCKER_BUILDX_CLI_PLUGIN_PATH); fi) 8 endif 9 10 ifndef USE_BUILDX 11 DOCKER_BUILDKIT := 1 12 export DOCKER_BUILDKIT 13 endif 14 15 BUILDX ?= bundles/buildx 16 DOCKER ?= docker 17 18 # set the graph driver as the current graphdriver if not set 19 DOCKER_GRAPHDRIVER := $(if $(DOCKER_GRAPHDRIVER),$(DOCKER_GRAPHDRIVER),$(shell docker info 2>&1 | grep "Storage Driver" | sed 's/.*: //')) 20 export DOCKER_GRAPHDRIVER 21 22 # get OS/Arch of docker engine 23 DOCKER_OSARCH := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKER_ENGINE_OSARCH}') 24 DOCKERFILE := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKERFILE}') 25 26 DOCKER_GITCOMMIT := $(shell git rev-parse --short HEAD || echo unsupported) 27 export DOCKER_GITCOMMIT 28 29 # allow overriding the repository and branch that validation scripts are running 30 # against these are used in hack/validate/.validate to check what changed in the PR. 31 export VALIDATE_REPO 32 export VALIDATE_BRANCH 33 export VALIDATE_ORIGIN_BRANCH 34 35 # env vars passed through directly to Docker's build scripts 36 # to allow things like `make KEEPBUNDLE=1 binary` easily 37 # `project/PACKAGERS.md` have some limited documentation of some of these 38 # 39 # DOCKER_LDFLAGS can be used to pass additional parameters to -ldflags 40 # option of "go build". For example, a built-in graphdriver priority list 41 # can be changed during build time like this: 42 # 43 # make DOCKER_LDFLAGS="-X github.com/docker/docker/daemon/graphdriver.priority=overlay2,devicemapper" dynbinary 44 # 45 DOCKER_ENVS := \ 46 -e DOCKER_CROSSPLATFORMS \ 47 -e BUILD_APT_MIRROR \ 48 -e BUILDFLAGS \ 49 -e KEEPBUNDLE \ 50 -e DOCKER_BUILD_ARGS \ 51 -e DOCKER_BUILD_GOGC \ 52 -e DOCKER_BUILD_OPTS \ 53 -e DOCKER_BUILD_PKGS \ 54 -e DOCKER_BUILDKIT \ 55 -e DOCKER_BASH_COMPLETION_PATH \ 56 -e DOCKER_CLI_PATH \ 57 -e DOCKER_DEBUG \ 58 -e DOCKER_EXPERIMENTAL \ 59 -e DOCKER_GITCOMMIT \ 60 -e DOCKER_GRAPHDRIVER \ 61 -e DOCKER_LDFLAGS \ 62 -e DOCKER_PORT \ 63 -e DOCKER_REMAP_ROOT \ 64 -e DOCKER_ROOTLESS \ 65 -e DOCKER_STORAGE_OPTS \ 66 -e DOCKER_TEST_HOST \ 67 -e DOCKER_USERLANDPROXY \ 68 -e DOCKERD_ARGS \ 69 -e TEST_FORCE_VALIDATE \ 70 -e TEST_INTEGRATION_DIR \ 71 -e TEST_SKIP_INTEGRATION \ 72 -e TEST_SKIP_INTEGRATION_CLI \ 73 -e TESTDEBUG \ 74 -e TESTDIRS \ 75 -e TESTFLAGS \ 76 -e TESTFLAGS_INTEGRATION \ 77 -e TESTFLAGS_INTEGRATION_CLI \ 78 -e TEST_FILTER \ 79 -e TIMEOUT \ 80 -e VALIDATE_REPO \ 81 -e VALIDATE_BRANCH \ 82 -e VALIDATE_ORIGIN_BRANCH \ 83 -e HTTP_PROXY \ 84 -e HTTPS_PROXY \ 85 -e NO_PROXY \ 86 -e http_proxy \ 87 -e https_proxy \ 88 -e no_proxy \ 89 -e VERSION \ 90 -e PLATFORM \ 91 -e DEFAULT_PRODUCT_LICENSE \ 92 -e PRODUCT 93 # 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 94 95 # to allow `make BIND_DIR=. shell` or `make BIND_DIR= test` 96 # (default to no bind mount if DOCKER_HOST is set) 97 # note: BINDDIR is supported for backwards-compatibility here 98 BIND_DIR := $(if $(BINDDIR),$(BINDDIR),$(if $(DOCKER_HOST),,bundles)) 99 100 # DOCKER_MOUNT can be overriden, but use at your own risk! 101 ifndef DOCKER_MOUNT 102 DOCKER_MOUNT := $(if $(BIND_DIR),-v "$(CURDIR)/$(BIND_DIR):/go/src/github.com/docker/docker/$(BIND_DIR)") 103 DOCKER_MOUNT := $(if $(DOCKER_BINDDIR_MOUNT_OPTS),$(DOCKER_MOUNT):$(DOCKER_BINDDIR_MOUNT_OPTS),$(DOCKER_MOUNT)) 104 105 # 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. 106 # The volume will be cleaned up when the container is removed due to `--rm`. 107 # 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. 108 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" 109 110 DOCKER_MOUNT_CACHE := -v docker-dev-cache:/root/.cache 111 DOCKER_MOUNT_CLI := $(if $(DOCKER_CLI_PATH),-v $(shell dirname $(DOCKER_CLI_PATH)):/usr/local/cli,) 112 DOCKER_MOUNT_BASH_COMPLETION := $(if $(DOCKER_BASH_COMPLETION_PATH),-v $(shell dirname $(DOCKER_BASH_COMPLETION_PATH)):/usr/local/completion/bash,) 113 DOCKER_MOUNT := $(DOCKER_MOUNT) $(DOCKER_MOUNT_CACHE) $(DOCKER_MOUNT_CLI) $(DOCKER_MOUNT_BASH_COMPLETION) 114 endif # ifndef DOCKER_MOUNT 115 116 # This allows to set the docker-dev container name 117 DOCKER_CONTAINER_NAME := $(if $(CONTAINER_NAME),--name $(CONTAINER_NAME),) 118 119 GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null) 120 GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g") 121 DOCKER_IMAGE := docker-dev$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN)) 122 DOCKER_PORT_FORWARD := $(if $(DOCKER_PORT),-p "$(DOCKER_PORT)",) 123 124 DOCKER_FLAGS := $(DOCKER) run --rm -i --privileged $(DOCKER_CONTAINER_NAME) $(DOCKER_ENVS) $(DOCKER_MOUNT) $(DOCKER_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 DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)" 144 145 DOCKER_BUILD_ARGS += --build-arg=GO_VERSION 146 ifdef DOCKER_SYSTEMD 147 DOCKER_BUILD_ARGS += --build-arg=SYSTEMD=true 148 endif 149 150 BUILD_OPTS := ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} -f "$(DOCKERFILE)" 151 ifdef USE_BUILDX 152 BUILD_OPTS += $(BUILDX_BUILD_EXTRA_OPTS) 153 BUILD_CMD := $(BUILDX) build 154 else 155 BUILD_CMD := $(DOCKER) build 156 endif 157 158 # This is used for the legacy "build" target and anything still depending on it 159 BUILD_CROSS = 160 ifdef DOCKER_CROSS 161 BUILD_CROSS = --build-arg CROSS=$(DOCKER_CROSS) 162 endif 163 ifdef DOCKER_CROSSPLATFORMS 164 BUILD_CROSS = --build-arg CROSS=true 165 endif 166 167 VERSION_AUTOGEN_ARGS = --build-arg VERSION --build-arg DOCKER_GITCOMMIT --build-arg PRODUCT --build-arg PLATFORM --build-arg DEFAULT_PRODUCT_LICENSE 168 169 default: binary 170 171 all: build ## validate all checks, build linux binaries, run all tests,\ncross build non-linux binaries, and generate archives 172 $(DOCKER_RUN_DOCKER) bash -c 'hack/validate/default && hack/make.sh' 173 174 # This is only used to work around read-only bind mounts of the source code into 175 # binary build targets. We end up mounting a tmpfs over autogen which allows us 176 # to write build-time generated assets even though the source is mounted read-only 177 # ...But in order to do so, this dir needs to already exist. 178 autogen: 179 mkdir -p autogen 180 181 binary: buildx autogen ## build statically linked linux binaries 182 $(BUILD_CMD) $(BUILD_OPTS) --output=bundles/ --target=$@ $(VERSION_AUTOGEN_ARGS) . 183 184 dynbinary: buildx autogen ## build dynamically linked linux binaries 185 $(BUILD_CMD) $(BUILD_OPTS) --output=bundles/ --target=$@ $(VERSION_AUTOGEN_ARGS) . 186 187 cross: BUILD_OPTS += --build-arg CROSS=true --build-arg DOCKER_CROSSPLATFORMS 188 cross: buildx autogen ## cross build the binaries for darwin, freebsd and\nwindows 189 $(BUILD_CMD) $(BUILD_OPTS) --output=bundles/ --target=$@ $(VERSION_AUTOGEN_ARGS) . 190 191 bundles: 192 mkdir bundles 193 194 .PHONY: clean 195 clean: clean-cache 196 197 .PHONY: clean-cache 198 clean-cache: 199 docker volume rm -f docker-dev-cache 200 201 help: ## this help 202 @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) 203 204 install: ## install the linux binaries 205 KEEPBUNDLE=1 hack/make.sh install-binary 206 207 run: build ## run the docker daemon in a container 208 $(DOCKER_RUN_DOCKER) sh -c "KEEPBUNDLE=1 hack/make.sh install-binary run" 209 210 .PHONY: build 211 ifeq ($(BIND_DIR), .) 212 build: shell_target := --target=dev 213 else 214 build: shell_target := --target=final 215 endif 216 ifdef USE_BUILDX 217 build: buildx_load := --load 218 endif 219 build: buildx 220 $(BUILD_CMD) $(BUILD_OPTS) $(shell_target) $(buildx_load) $(BUILD_CROSS) -t "$(DOCKER_IMAGE)" . 221 222 shell: build ## start a shell inside the build env 223 $(DOCKER_RUN_DOCKER) bash 224 225 test: build test-unit ## run the unit, integration and docker-py tests 226 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary cross test-integration test-docker-py 227 228 test-docker-py: build ## run the docker-py tests 229 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-docker-py 230 231 test-integration-cli: test-integration ## (DEPRECATED) use test-integration 232 233 ifneq ($(and $(TEST_SKIP_INTEGRATION),$(TEST_SKIP_INTEGRATION_CLI)),) 234 test-integration: 235 @echo Both integrations suites skipped per environment variables 236 else 237 test-integration: build ## run the integration tests 238 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration 239 endif 240 241 test-integration-flaky: build ## run the stress test for all new integration tests 242 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration-flaky 243 244 test-unit: build ## run the unit tests 245 $(DOCKER_RUN_DOCKER) hack/test/unit 246 247 validate: build ## validate DCO, Seccomp profile generation, gofmt,\n./pkg/ isolation, golint, tests, tomls, go vet and vendor 248 $(DOCKER_RUN_DOCKER) hack/validate/all 249 250 win: build ## cross build the binary for windows 251 $(DOCKER_RUN_DOCKER) DOCKER_CROSSPLATFORMS=windows/amd64 hack/make.sh cross 252 253 .PHONY: swagger-gen 254 swagger-gen: 255 docker run --rm -v $(PWD):/go/src/github.com/docker/docker \ 256 -w /go/src/github.com/docker/docker \ 257 --entrypoint hack/generate-swagger-api.sh \ 258 -e GOPATH=/go \ 259 quay.io/goswagger/swagger:0.7.4 260 261 .PHONY: swagger-docs 262 swagger-docs: ## preview the API documentation 263 @echo "API docs preview will be running at http://localhost:$(SWAGGER_DOCS_PORT)" 264 @docker run --rm -v $(PWD)/api/swagger.yaml:/usr/share/nginx/html/swagger.yaml \ 265 -e 'REDOC_OPTIONS=hide-hostname="true" lazy-rendering' \ 266 -p $(SWAGGER_DOCS_PORT):80 \ 267 bfirsh/redoc:1.6.2 268 269 .PHONY: buildx 270 ifdef USE_BUILDX 271 ifeq ($(BUILDX), bundles/buildx) 272 buildx: bundles/buildx ## build buildx cli tool 273 endif 274 endif 275 276 # This intentionally is not using the `--output` flag from the docker CLI, which 277 # is a buildkit option. The idea here being that if buildx is being used, it's 278 # because buildkit is not supported natively 279 bundles/buildx: bundles ## build buildx CLI tool 280 docker build -f $${BUILDX_DOCKERFILE:-Dockerfile.buildx} -t "moby-buildx:$${BUILDX_COMMIT:-latest}" \ 281 --build-arg BUILDX_COMMIT \ 282 --build-arg BUILDX_REPO \ 283 --build-arg GOOS=$$(if [ -n "$(GOOS)" ]; then echo $(GOOS); else go env GOHOSTOS || uname | awk '{print tolower($$0)}' || true; fi) \ 284 --build-arg GOARCH=$$(if [ -n "$(GOARCH)" ]; then echo $(GOARCH); else go env GOHOSTARCH || true; fi) \ 285 . 286 287 id=$$(docker create moby-buildx:$${BUILDX_COMMIT:-latest}); \ 288 if [ -n "$${id}" ]; then \ 289 docker cp $${id}:/usr/bin/buildx $@ \ 290 && touch $@; \ 291 docker rm -f $${id}; \ 292 fi 293 294 $@ version