1.PHONY: all binary dynbinary build cross deb help init-go-pkg-cache install manpages rpm run shell test test-docker-py test-integration test-unit validate win 2 3# set the graph driver as the current graphdriver if not set 4DOCKER_GRAPHDRIVER := $(if $(DOCKER_GRAPHDRIVER),$(DOCKER_GRAPHDRIVER),$(shell docker info 2>&1 | grep "Storage Driver" | sed 's/.*: //')) 5export DOCKER_GRAPHDRIVER 6DOCKER_INCREMENTAL_BINARY := $(if $(DOCKER_INCREMENTAL_BINARY),$(DOCKER_INCREMENTAL_BINARY),1) 7export DOCKER_INCREMENTAL_BINARY 8 9# get OS/Arch of docker engine 10DOCKER_OSARCH := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKER_ENGINE_OSARCH}') 11DOCKERFILE := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKERFILE}') 12 13DOCKER_GITCOMMIT := $(shell git rev-parse --short HEAD || echo unsupported) 14export DOCKER_GITCOMMIT 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,devicemapper" dynbinary 25# 26DOCKER_ENVS := \ 27 -e DOCKER_CROSSPLATFORMS \ 28 -e BUILD_APT_MIRROR \ 29 -e BUILDFLAGS \ 30 -e KEEPBUNDLE \ 31 -e DOCKER_BUILD_ARGS \ 32 -e DOCKER_BUILD_GOGC \ 33 -e DOCKER_BUILD_PKGS \ 34 -e DOCKER_BASH_COMPLETION_PATH \ 35 -e DOCKER_CLI_PATH \ 36 -e DOCKER_DEBUG \ 37 -e DOCKER_EXPERIMENTAL \ 38 -e DOCKER_GITCOMMIT \ 39 -e DOCKER_GRAPHDRIVER \ 40 -e DOCKER_INCREMENTAL_BINARY \ 41 -e DOCKER_LDFLAGS \ 42 -e DOCKER_PORT \ 43 -e DOCKER_REMAP_ROOT \ 44 -e DOCKER_STORAGE_OPTS \ 45 -e DOCKER_USERLANDPROXY \ 46 -e TEST_INTEGRATION_DIR \ 47 -e TESTDIRS \ 48 -e TESTFLAGS \ 49 -e TIMEOUT \ 50 -e HTTP_PROXY \ 51 -e HTTPS_PROXY \ 52 -e NO_PROXY \ 53 -e http_proxy \ 54 -e https_proxy \ 55 -e no_proxy \ 56 -e VERSION 57# 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 58 59# to allow `make BIND_DIR=. shell` or `make BIND_DIR= test` 60# (default to no bind mount if DOCKER_HOST is set) 61# note: BINDDIR is supported for backwards-compatibility here 62BIND_DIR := $(if $(BINDDIR),$(BINDDIR),$(if $(DOCKER_HOST),,bundles)) 63DOCKER_MOUNT := $(if $(BIND_DIR),-v "$(CURDIR)/$(BIND_DIR):/go/src/github.com/docker/docker/$(BIND_DIR)") 64 65# 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. 66# The volume will be cleaned up when the container is removed due to `--rm`. 67# 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. 68DOCKER_MOUNT := $(if $(DOCKER_MOUNT),$(DOCKER_MOUNT),-v /go/src/github.com/docker/docker/bundles) -v $(CURDIR)/.git:/go/src/github.com/docker/docker/.git 69 70# This allows to set the docker-dev container name 71DOCKER_CONTAINER_NAME := $(if $(CONTAINER_NAME),--name $(CONTAINER_NAME),) 72 73# enable package cache if DOCKER_INCREMENTAL_BINARY and DOCKER_MOUNT (i.e.DOCKER_HOST) are set 74PKGCACHE_MAP := gopath:/go/pkg goroot-linux_amd64:/usr/local/go/pkg/linux_amd64 goroot-linux_amd64_netgo:/usr/local/go/pkg/linux_amd64_netgo 75PKGCACHE_VOLROOT := dockerdev-go-pkg-cache 76PKGCACHE_VOL := $(if $(PKGCACHE_DIR),$(CURDIR)/$(PKGCACHE_DIR)/,$(PKGCACHE_VOLROOT)-) 77DOCKER_MOUNT_PKGCACHE := $(if $(DOCKER_INCREMENTAL_BINARY),$(shell echo $(PKGCACHE_MAP) | sed -E 's@([^ ]*)@-v "$(PKGCACHE_VOL)\1"@g'),) 78DOCKER_MOUNT_CLI := $(if $(DOCKER_CLI_PATH),-v $(shell dirname $(DOCKER_CLI_PATH)):/usr/local/cli,) 79DOCKER_MOUNT_BASH_COMPLETION := $(if $(DOCKER_BASH_COMPLETION_PATH),-v $(shell dirname $(DOCKER_BASH_COMPLETION_PATH)):/usr/local/completion/bash,) 80DOCKER_MOUNT := $(DOCKER_MOUNT) $(DOCKER_MOUNT_PKGCACHE) $(DOCKER_MOUNT_CLI) $(DOCKER_MOUNT_BASH_COMPLETION) 81 82GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null) 83GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g") 84DOCKER_IMAGE := docker-dev$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN)) 85DOCKER_PORT_FORWARD := $(if $(DOCKER_PORT),-p "$(DOCKER_PORT)",) 86 87DOCKER_FLAGS := docker run --rm -i --privileged $(DOCKER_CONTAINER_NAME) $(DOCKER_ENVS) $(DOCKER_MOUNT) $(DOCKER_PORT_FORWARD) 88BUILD_APT_MIRROR := $(if $(DOCKER_BUILD_APT_MIRROR),--build-arg APT_MIRROR=$(DOCKER_BUILD_APT_MIRROR)) 89export BUILD_APT_MIRROR 90 91SWAGGER_DOCS_PORT ?= 9000 92 93INTEGRATION_CLI_MASTER_IMAGE := $(if $(INTEGRATION_CLI_MASTER_IMAGE), $(INTEGRATION_CLI_MASTER_IMAGE), integration-cli-master) 94INTEGRATION_CLI_WORKER_IMAGE := $(if $(INTEGRATION_CLI_WORKER_IMAGE), $(INTEGRATION_CLI_WORKER_IMAGE), integration-cli-worker) 95 96define \n 97 98 99endef 100 101# if this session isn't interactive, then we don't want to allocate a 102# TTY, which would fail, but if it is interactive, we do want to attach 103# so that the user can send e.g. ^C through. 104INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0) 105ifeq ($(INTERACTIVE), 1) 106 DOCKER_FLAGS += -t 107endif 108 109DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)" 110 111default: binary 112 113all: build ## validate all checks, build linux binaries, run all tests\ncross build non-linux binaries and generate archives 114 $(DOCKER_RUN_DOCKER) bash -c 'hack/validate/default && hack/make.sh' 115 116binary: build ## build the linux binaries 117 $(DOCKER_RUN_DOCKER) hack/make.sh binary 118 119dynbinary: build ## build the linux dynbinaries 120 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary 121 122build: bundles init-go-pkg-cache 123 $(warning The docker client CLI has moved to github.com/docker/cli. For a dev-test cycle involving the CLI, run:${\n} DOCKER_CLI_PATH=/host/path/to/cli/binary make shell ${\n} then change the cli and compile into a binary at the same location.${\n}) 124 docker build ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} -t "$(DOCKER_IMAGE)" -f "$(DOCKERFILE)" . 125 126bundles: 127 mkdir bundles 128 129clean: clean-pkg-cache-vol ## clean up cached resources 130 131clean-pkg-cache-vol: 132 @- $(foreach mapping,$(PKGCACHE_MAP), \ 133 $(shell docker volume rm $(PKGCACHE_VOLROOT)-$(shell echo $(mapping) | awk -F':/' '{ print $$1 }') > /dev/null 2>&1) \ 134 ) 135 136cross: build ## cross build the binaries for darwin, freebsd and\nwindows 137 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary binary cross 138 139deb: build ## build the deb packages 140 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary build-deb 141 142 143help: ## this help 144 @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) 145 146init-go-pkg-cache: 147 $(if $(PKGCACHE_DIR), mkdir -p $(shell echo $(PKGCACHE_MAP) | sed -E 's@([^: ]*):[^ ]*@$(PKGCACHE_DIR)/\1@g')) 148 149install: ## install the linux binaries 150 KEEPBUNDLE=1 hack/make.sh install-binary 151 152rpm: build ## build the rpm packages 153 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary build-rpm 154 155run: build ## run the docker daemon in a container 156 $(DOCKER_RUN_DOCKER) sh -c "KEEPBUNDLE=1 hack/make.sh install-binary run" 157 158shell: build ## start a shell inside the build env 159 $(DOCKER_RUN_DOCKER) bash 160 161test: build test-unit ## run the unit, integration and docker-py tests 162 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary cross test-integration test-docker-py 163 164test-docker-py: build ## run the docker-py tests 165 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-docker-py 166 167test-integration-cli: test-integration ## (DEPRECATED) use test-integration 168 169test-integration: build ## run the integration tests 170 $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration 171 172test-unit: build ## run the unit tests 173 $(DOCKER_RUN_DOCKER) hack/test/unit 174 175validate: build ## validate DCO, Seccomp profile generation, gofmt,\n./pkg/ isolation, golint, tests, tomls, go vet and vendor 176 $(DOCKER_RUN_DOCKER) hack/validate/all 177 178win: build ## cross build the binary for windows 179 $(DOCKER_RUN_DOCKER) hack/make.sh win 180 181.PHONY: swagger-gen 182swagger-gen: 183 docker run --rm -v $(PWD):/go/src/github.com/docker/docker \ 184 -w /go/src/github.com/docker/docker \ 185 --entrypoint hack/generate-swagger-api.sh \ 186 -e GOPATH=/go \ 187 quay.io/goswagger/swagger:0.7.4 188 189.PHONY: swagger-docs 190swagger-docs: ## preview the API documentation 191 @echo "API docs preview will be running at http://localhost:$(SWAGGER_DOCS_PORT)" 192 @docker run --rm -v $(PWD)/api/swagger.yaml:/usr/share/nginx/html/swagger.yaml \ 193 -e 'REDOC_OPTIONS=hide-hostname="true" lazy-rendering' \ 194 -p $(SWAGGER_DOCS_PORT):80 \ 195 bfirsh/redoc:1.6.2 196 197build-integration-cli-on-swarm: build ## build images and binary for running integration-cli on Swarm in parallel 198 @echo "Building hack/integration-cli-on-swarm (if build fails, please refer to hack/integration-cli-on-swarm/README.md)" 199 go build -o ./hack/integration-cli-on-swarm/integration-cli-on-swarm ./hack/integration-cli-on-swarm/host 200 @echo "Building $(INTEGRATION_CLI_MASTER_IMAGE)" 201 docker build -t $(INTEGRATION_CLI_MASTER_IMAGE) hack/integration-cli-on-swarm/agent 202# For worker, we don't use `docker build` so as to enable DOCKER_INCREMENTAL_BINARY and so on 203 @echo "Building $(INTEGRATION_CLI_WORKER_IMAGE) from $(DOCKER_IMAGE)" 204 $(eval tmp := integration-cli-worker-tmp) 205# We mount pkgcache, but not bundle (bundle needs to be baked into the image) 206# For avoiding bakings DOCKER_GRAPHDRIVER and so on to image, we cannot use $(DOCKER_ENVS) here 207 docker run -t -d --name $(tmp) -e DOCKER_GITCOMMIT -e BUILDFLAGS -e DOCKER_INCREMENTAL_BINARY --privileged $(DOCKER_MOUNT_PKGCACHE) $(DOCKER_IMAGE) top 208 docker exec $(tmp) hack/make.sh build-integration-test-binary dynbinary 209 docker exec $(tmp) go build -o /worker github.com/docker/docker/hack/integration-cli-on-swarm/agent/worker 210 docker commit -c 'ENTRYPOINT ["/worker"]' $(tmp) $(INTEGRATION_CLI_WORKER_IMAGE) 211 docker rm -f $(tmp) 212