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