github.com/docker/engine@v22.0.0-20211208180946-d456264580cf+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  BUILDX_VERSION ?= v0.6.0
     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 VERSION \
    86  	-e PLATFORM \
    87  	-e DEFAULT_PRODUCT_LICENSE \
    88  	-e PRODUCT
    89  # 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
    90  
    91  # to allow `make BIND_DIR=. shell` or `make BIND_DIR= test`
    92  # (default to no bind mount if DOCKER_HOST is set)
    93  # note: BINDDIR is supported for backwards-compatibility here
    94  BIND_DIR := $(if $(BINDDIR),$(BINDDIR),$(if $(DOCKER_HOST),,bundles))
    95  
    96  # DOCKER_MOUNT can be overriden, but use at your own risk!
    97  ifndef DOCKER_MOUNT
    98  DOCKER_MOUNT := $(if $(BIND_DIR),-v "$(CURDIR)/$(BIND_DIR):/go/src/github.com/docker/docker/$(BIND_DIR)")
    99  DOCKER_MOUNT := $(if $(DOCKER_BINDDIR_MOUNT_OPTS),$(DOCKER_MOUNT):$(DOCKER_BINDDIR_MOUNT_OPTS),$(DOCKER_MOUNT))
   100  
   101  # 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.
   102  # The volume will be cleaned up when the container is removed due to `--rm`.
   103  # 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.
   104  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"
   105  
   106  DOCKER_MOUNT_CACHE := -v docker-dev-cache:/root/.cache
   107  DOCKER_MOUNT_CLI := $(if $(DOCKER_CLI_PATH),-v $(shell dirname $(DOCKER_CLI_PATH)):/usr/local/cli,)
   108  DOCKER_MOUNT_BASH_COMPLETION := $(if $(DOCKER_BASH_COMPLETION_PATH),-v $(shell dirname $(DOCKER_BASH_COMPLETION_PATH)):/usr/local/completion/bash,)
   109  DOCKER_MOUNT := $(DOCKER_MOUNT) $(DOCKER_MOUNT_CACHE) $(DOCKER_MOUNT_CLI) $(DOCKER_MOUNT_BASH_COMPLETION)
   110  endif # ifndef DOCKER_MOUNT
   111  
   112  # This allows to set the docker-dev container name
   113  DOCKER_CONTAINER_NAME := $(if $(CONTAINER_NAME),--name $(CONTAINER_NAME),)
   114  
   115  DOCKER_IMAGE := docker-dev
   116  DOCKER_PORT_FORWARD := $(if $(DOCKER_PORT),-p "$(DOCKER_PORT)",)
   117  
   118  DOCKER_FLAGS := $(DOCKER) run --rm -i --privileged $(DOCKER_CONTAINER_NAME) $(DOCKER_ENVS) $(DOCKER_MOUNT) $(DOCKER_PORT_FORWARD)
   119  BUILD_APT_MIRROR := $(if $(DOCKER_BUILD_APT_MIRROR),--build-arg APT_MIRROR=$(DOCKER_BUILD_APT_MIRROR))
   120  export BUILD_APT_MIRROR
   121  
   122  SWAGGER_DOCS_PORT ?= 9000
   123  
   124  define \n
   125  
   126  
   127  endef
   128  
   129  # if this session isn't interactive, then we don't want to allocate a
   130  # TTY, which would fail, but if it is interactive, we do want to attach
   131  # so that the user can send e.g. ^C through.
   132  INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0)
   133  ifeq ($(INTERACTIVE), 1)
   134  	DOCKER_FLAGS += -t
   135  endif
   136  
   137  DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)"
   138  
   139  DOCKER_BUILD_ARGS += --build-arg=GO_VERSION
   140  ifdef DOCKER_SYSTEMD
   141  DOCKER_BUILD_ARGS += --build-arg=SYSTEMD=true
   142  endif
   143  
   144  BUILD_OPTS := ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} -f "$(DOCKERFILE)"
   145  ifdef USE_BUILDX
   146  BUILD_OPTS += $(BUILDX_BUILD_EXTRA_OPTS)
   147  BUILD_CMD := $(BUILDX) build
   148  else
   149  BUILD_CMD := $(DOCKER) build
   150  endif
   151  
   152  # This is used for the legacy "build" target and anything still depending on it
   153  BUILD_CROSS =
   154  ifdef DOCKER_CROSS
   155  BUILD_CROSS = --build-arg CROSS=$(DOCKER_CROSS)
   156  endif
   157  ifdef DOCKER_CROSSPLATFORMS
   158  BUILD_CROSS = --build-arg CROSS=true
   159  endif
   160  
   161  VERSION_AUTOGEN_ARGS = --build-arg VERSION --build-arg DOCKER_GITCOMMIT --build-arg PRODUCT --build-arg PLATFORM --build-arg DEFAULT_PRODUCT_LICENSE
   162  
   163  default: binary
   164  
   165  all: build ## validate all checks, build linux binaries, run all tests,\ncross build non-linux binaries, and generate archives
   166  	$(DOCKER_RUN_DOCKER) bash -c 'hack/validate/default && hack/make.sh'
   167  
   168  # This is only used to work around read-only bind mounts of the source code into
   169  # binary build targets. We end up mounting a tmpfs over autogen which allows us
   170  # to write build-time generated assets even though the source is mounted read-only
   171  # ...But in order to do so, this dir needs to already exist.
   172  autogen:
   173  	mkdir -p autogen
   174  
   175  binary: buildx autogen ## build statically linked linux binaries
   176  	$(BUILD_CMD) $(BUILD_OPTS) --output=bundles/ --target=$@ $(VERSION_AUTOGEN_ARGS) .
   177  
   178  dynbinary: buildx autogen ## build dynamically linked linux binaries
   179  	$(BUILD_CMD) $(BUILD_OPTS) --output=bundles/ --target=$@ $(VERSION_AUTOGEN_ARGS) .
   180  
   181  cross: BUILD_OPTS += --build-arg CROSS=true --build-arg DOCKER_CROSSPLATFORMS
   182  cross: buildx autogen ## cross build the binaries for darwin, freebsd and\nwindows
   183  	$(BUILD_CMD) $(BUILD_OPTS) --output=bundles/ --target=$@ $(VERSION_AUTOGEN_ARGS) .
   184  
   185  bundles:
   186  	mkdir bundles
   187  
   188  .PHONY: clean
   189  clean: clean-cache
   190  
   191  .PHONY: clean-cache
   192  clean-cache:
   193  	docker volume rm -f docker-dev-cache
   194  
   195  help: ## this help
   196  	@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)
   197  
   198  install: ## install the linux binaries
   199  	KEEPBUNDLE=1 hack/make.sh install-binary
   200  
   201  run: build ## run the docker daemon in a container
   202  	$(DOCKER_RUN_DOCKER) sh -c "KEEPBUNDLE=1 hack/make.sh install-binary run"
   203   
   204  .PHONY: build
   205  ifeq ($(BIND_DIR), .)
   206  build: shell_target := --target=dev
   207  else
   208  build: shell_target := --target=final
   209  endif
   210  ifdef USE_BUILDX
   211  build: buildx_load := --load
   212  endif
   213  build: buildx
   214  	$(BUILD_CMD) $(BUILD_OPTS) $(shell_target) $(buildx_load) $(BUILD_CROSS) -t "$(DOCKER_IMAGE)" .
   215  
   216  shell: build  ## start a shell inside the build env
   217  	$(DOCKER_RUN_DOCKER) bash
   218  
   219  test: build test-unit ## run the unit, integration and docker-py tests
   220  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary cross test-integration test-docker-py
   221  
   222  test-docker-py: build ## run the docker-py tests
   223  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-docker-py
   224  
   225  test-integration-cli: test-integration ## (DEPRECATED) use test-integration
   226  
   227  ifneq ($(and $(TEST_SKIP_INTEGRATION),$(TEST_SKIP_INTEGRATION_CLI)),)
   228  test-integration:
   229  	@echo Both integrations suites skipped per environment variables
   230  else
   231  test-integration: build ## run the integration tests
   232  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration
   233  endif
   234  
   235  test-integration-flaky: build ## run the stress test for all new integration tests
   236  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration-flaky
   237  
   238  test-unit: build ## run the unit tests
   239  	$(DOCKER_RUN_DOCKER) hack/test/unit
   240  
   241  validate: build ## validate DCO, Seccomp profile generation, gofmt,\n./pkg/ isolation, golint, tests, tomls, go vet and vendor
   242  	$(DOCKER_RUN_DOCKER) hack/validate/all
   243  
   244  win: build ## cross build the binary for windows
   245  	$(DOCKER_RUN_DOCKER) DOCKER_CROSSPLATFORMS=windows/amd64 hack/make.sh cross
   246  
   247  .PHONY: swagger-gen
   248  swagger-gen:
   249  	docker run --rm -v $(PWD):/go/src/github.com/docker/docker \
   250  		-w /go/src/github.com/docker/docker \
   251  		--entrypoint hack/generate-swagger-api.sh \
   252  		-e GOPATH=/go \
   253  		quay.io/goswagger/swagger:0.7.4
   254  
   255  .PHONY: swagger-docs
   256  swagger-docs: ## preview the API documentation
   257  	@echo "API docs preview will be running at http://localhost:$(SWAGGER_DOCS_PORT)"
   258  	@docker run --rm -v $(PWD)/api/swagger.yaml:/usr/share/nginx/html/swagger.yaml \
   259  		-e 'REDOC_OPTIONS=hide-hostname="true" lazy-rendering' \
   260  		-p $(SWAGGER_DOCS_PORT):80 \
   261  		bfirsh/redoc:1.14.0
   262  
   263  .PHONY: buildx
   264  ifdef USE_BUILDX
   265  ifeq ($(BUILDX), bundles/buildx)
   266  buildx: bundles/buildx ## build buildx cli tool
   267  endif
   268  endif
   269  
   270  bundles/buildx: bundles ## build buildx CLI tool
   271  	curl -fsSL https://raw.githubusercontent.com/moby/buildkit/70deac12b5857a1aa4da65e90b262368e2f71500/hack/install-buildx | VERSION="$(BUILDX_VERSION)" BINDIR="$(@D)" bash
   272  	$@ version