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