github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/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  # 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  
     7  # get OS/Arch of docker engine
     8  DOCKER_OSARCH := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKER_ENGINE_OSARCH}')
     9  DOCKERFILE := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKERFILE}')
    10  
    11  DOCKER_GITCOMMIT := $(shell git rev-parse --short HEAD || echo unsupported)
    12  export DOCKER_GITCOMMIT
    13  
    14  # allow overriding the repository and branch that validation scripts are running
    15  # against these are used in hack/validate/.validate to check what changed in the PR.
    16  export VALIDATE_REPO
    17  export VALIDATE_BRANCH
    18  export VALIDATE_ORIGIN_BRANCH
    19  
    20  # env vars passed through directly to Docker's build scripts
    21  # to allow things like `make KEEPBUNDLE=1 binary` easily
    22  # `project/PACKAGERS.md` have some limited documentation of some of these
    23  #
    24  # DOCKER_LDFLAGS can be used to pass additional parameters to -ldflags
    25  # option of "go build". For example, a built-in graphdriver priority list
    26  # can be changed during build time like this:
    27  #
    28  # make DOCKER_LDFLAGS="-X github.com/docker/docker/daemon/graphdriver.priority=overlay2,devicemapper" dynbinary
    29  #
    30  DOCKER_ENVS := \
    31  	-e DOCKER_CROSSPLATFORMS \
    32  	-e BUILD_APT_MIRROR \
    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 DOCKER_DEBUG \
    43  	-e DOCKER_EXPERIMENTAL \
    44  	-e DOCKER_GITCOMMIT \
    45  	-e DOCKER_GRAPHDRIVER \
    46  	-e DOCKER_LDFLAGS \
    47  	-e DOCKER_PORT \
    48  	-e DOCKER_REMAP_ROOT \
    49  	-e DOCKER_STORAGE_OPTS \
    50  	-e DOCKER_USERLANDPROXY \
    51  	-e DOCKERD_ARGS \
    52  	-e TEST_INTEGRATION_DIR \
    53  	-e TESTDIRS \
    54  	-e TESTFLAGS \
    55  	-e TIMEOUT \
    56  	-e VALIDATE_REPO \
    57  	-e VALIDATE_BRANCH \
    58  	-e VALIDATE_ORIGIN_BRANCH \
    59  	-e HTTP_PROXY \
    60  	-e HTTPS_PROXY \
    61  	-e NO_PROXY \
    62  	-e http_proxy \
    63  	-e https_proxy \
    64  	-e no_proxy \
    65  	-e VERSION \
    66  	-e PLATFORM \
    67  	-e DEFAULT_PRODUCT_LICENSE \
    68  	-e PRODUCT
    69  # 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
    70  
    71  # to allow `make BIND_DIR=. shell` or `make BIND_DIR= test`
    72  # (default to no bind mount if DOCKER_HOST is set)
    73  # note: BINDDIR is supported for backwards-compatibility here
    74  BIND_DIR := $(if $(BINDDIR),$(BINDDIR),$(if $(DOCKER_HOST),,bundles))
    75  
    76  # DOCKER_MOUNT can be overriden, but use at your own risk!
    77  ifndef DOCKER_MOUNT
    78  DOCKER_MOUNT := $(if $(BIND_DIR),-v "$(CURDIR)/$(BIND_DIR):/go/src/github.com/docker/docker/$(BIND_DIR)")
    79  
    80  # 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.
    81  # The volume will be cleaned up when the container is removed due to `--rm`.
    82  # 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.
    83  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"
    84  
    85  DOCKER_MOUNT_CACHE := -v docker-dev-cache:/root/.cache
    86  DOCKER_MOUNT_CLI := $(if $(DOCKER_CLI_PATH),-v $(shell dirname $(DOCKER_CLI_PATH)):/usr/local/cli,)
    87  DOCKER_MOUNT_BASH_COMPLETION := $(if $(DOCKER_BASH_COMPLETION_PATH),-v $(shell dirname $(DOCKER_BASH_COMPLETION_PATH)):/usr/local/completion/bash,)
    88  DOCKER_MOUNT := $(DOCKER_MOUNT) $(DOCKER_MOUNT_CACHE) $(DOCKER_MOUNT_CLI) $(DOCKER_MOUNT_BASH_COMPLETION)
    89  endif # ifndef DOCKER_MOUNT
    90  
    91  # This allows to set the docker-dev container name
    92  DOCKER_CONTAINER_NAME := $(if $(CONTAINER_NAME),--name $(CONTAINER_NAME),)
    93  
    94  GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
    95  GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g")
    96  DOCKER_IMAGE := docker-dev$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN))
    97  DOCKER_PORT_FORWARD := $(if $(DOCKER_PORT),-p "$(DOCKER_PORT)",)
    98  
    99  DOCKER_FLAGS := docker run --rm -i --privileged $(DOCKER_CONTAINER_NAME) $(DOCKER_ENVS) $(DOCKER_MOUNT) $(DOCKER_PORT_FORWARD)
   100  BUILD_APT_MIRROR := $(if $(DOCKER_BUILD_APT_MIRROR),--build-arg APT_MIRROR=$(DOCKER_BUILD_APT_MIRROR))
   101  export BUILD_APT_MIRROR
   102  
   103  SWAGGER_DOCS_PORT ?= 9000
   104  
   105  INTEGRATION_CLI_MASTER_IMAGE := $(if $(INTEGRATION_CLI_MASTER_IMAGE), $(INTEGRATION_CLI_MASTER_IMAGE), integration-cli-master)
   106  INTEGRATION_CLI_WORKER_IMAGE := $(if $(INTEGRATION_CLI_WORKER_IMAGE), $(INTEGRATION_CLI_WORKER_IMAGE), integration-cli-worker)
   107  
   108  define \n
   109  
   110  
   111  endef
   112  
   113  # if this session isn't interactive, then we don't want to allocate a
   114  # TTY, which would fail, but if it is interactive, we do want to attach
   115  # so that the user can send e.g. ^C through.
   116  INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0)
   117  ifeq ($(INTERACTIVE), 1)
   118  	DOCKER_FLAGS += -t
   119  endif
   120  ifeq ($(BIND_DIR), .)
   121  	DOCKER_BUILD_OPTS += --target=dev
   122  endif
   123  
   124  DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)"
   125  
   126  default: binary
   127  
   128  all: build ## validate all checks, build linux binaries, run all tests\ncross build non-linux binaries and generate archives
   129  	$(DOCKER_RUN_DOCKER) bash -c 'hack/validate/default && hack/make.sh'
   130  
   131  binary: build ## build the linux binaries
   132  	$(DOCKER_RUN_DOCKER) hack/make.sh binary
   133  
   134  dynbinary: build ## build the linux dynbinaries
   135  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary
   136  
   137  build: DOCKER_BUILDKIT ?= 1
   138  build: bundles
   139  	$(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})
   140  	DOCKER_BUILDKIT="${DOCKER_BUILDKIT}" docker build ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} -t "$(DOCKER_IMAGE)" -f "$(DOCKERFILE)" .
   141  
   142  bundles:
   143  	mkdir bundles
   144  
   145  .PHONY: clean
   146  clean: clean-cache
   147  
   148  .PHONY: clean-cache
   149  clean-cache:
   150  	docker volume rm -f docker-dev-cache
   151  
   152  cross: build ## cross build the binaries for darwin, freebsd and\nwindows
   153  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary binary cross
   154  
   155  help: ## this help
   156  	@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)
   157  
   158  install: ## install the linux binaries
   159  	KEEPBUNDLE=1 hack/make.sh install-binary
   160  
   161  run: build ## run the docker daemon in a container
   162  	$(DOCKER_RUN_DOCKER) sh -c "KEEPBUNDLE=1 hack/make.sh install-binary run"
   163  
   164  shell: build ## start a shell inside the build env
   165  	$(DOCKER_RUN_DOCKER) bash
   166  
   167  test: build test-unit ## run the unit, integration and docker-py tests
   168  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary cross test-integration test-docker-py
   169  
   170  test-docker-py: build ## run the docker-py tests
   171  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-docker-py
   172  
   173  test-integration-cli: test-integration ## (DEPRECATED) use test-integration
   174  
   175  test-integration: build ## run the integration tests
   176  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration
   177  
   178  test-integration-flaky: build ## run the stress test for all new integration tests
   179  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration-flaky
   180  
   181  test-unit: build ## run the unit tests
   182  	$(DOCKER_RUN_DOCKER) hack/test/unit
   183  
   184  validate: build ## validate DCO, Seccomp profile generation, gofmt,\n./pkg/ isolation, golint, tests, tomls, go vet and vendor
   185  	$(DOCKER_RUN_DOCKER) hack/validate/all
   186  
   187  win: build ## cross build the binary for windows
   188  	$(DOCKER_RUN_DOCKER) DOCKER_CROSSPLATFORMS=windows/amd64 hack/make.sh cross
   189  
   190  .PHONY: swagger-gen
   191  swagger-gen:
   192  	docker run --rm -v $(PWD):/go/src/github.com/docker/docker \
   193  		-w /go/src/github.com/docker/docker \
   194  		--entrypoint hack/generate-swagger-api.sh \
   195  		-e GOPATH=/go \
   196  		quay.io/goswagger/swagger:0.7.4
   197  
   198  .PHONY: swagger-docs
   199  swagger-docs: ## preview the API documentation
   200  	@echo "API docs preview will be running at http://localhost:$(SWAGGER_DOCS_PORT)"
   201  	@docker run --rm -v $(PWD)/api/swagger.yaml:/usr/share/nginx/html/swagger.yaml \
   202  		-e 'REDOC_OPTIONS=hide-hostname="true" lazy-rendering' \
   203  		-p $(SWAGGER_DOCS_PORT):80 \
   204  		bfirsh/redoc:1.6.2
   205  
   206  build-integration-cli-on-swarm: build ## build images and binary for running integration-cli on Swarm in parallel
   207  	@echo "Building hack/integration-cli-on-swarm (if build fails, please refer to hack/integration-cli-on-swarm/README.md)"
   208  	go build -buildmode=pie -o ./hack/integration-cli-on-swarm/integration-cli-on-swarm ./hack/integration-cli-on-swarm/host
   209  	@echo "Building $(INTEGRATION_CLI_MASTER_IMAGE)"
   210  	docker build -t $(INTEGRATION_CLI_MASTER_IMAGE) hack/integration-cli-on-swarm/agent
   211  	@echo "Building $(INTEGRATION_CLI_WORKER_IMAGE) from $(DOCKER_IMAGE)"
   212  	$(eval tmp := integration-cli-worker-tmp)
   213  # We mount pkgcache, but not bundle (bundle needs to be baked into the image)
   214  # For avoiding bakings DOCKER_GRAPHDRIVER and so on to image, we cannot use $(DOCKER_ENVS) here
   215  	docker run -t -d --name $(tmp) -e DOCKER_GITCOMMIT -e BUILDFLAGS --privileged $(DOCKER_IMAGE) top
   216  	docker exec $(tmp) hack/make.sh build-integration-test-binary dynbinary
   217  	docker exec $(tmp) go build -buildmode=pie -o /worker github.com/docker/docker/hack/integration-cli-on-swarm/agent/worker
   218  	docker commit -c 'ENTRYPOINT ["/worker"]' $(tmp) $(INTEGRATION_CLI_WORKER_IMAGE)
   219  	docker rm -f $(tmp)