github.com/rish1988/moby@v25.0.2+incompatible/Makefile (about)

     1  .PHONY: all binary dynbinary build cross help install manpages run shell test test-docker-py test-integration test-unit validate validate-% win
     2  
     3  DOCKER ?= docker
     4  BUILDX ?= $(DOCKER) buildx
     5  
     6  # set the graph driver as the current graphdriver if not set
     7  DOCKER_GRAPHDRIVER := $(if $(DOCKER_GRAPHDRIVER),$(DOCKER_GRAPHDRIVER),$(shell docker info -f '{{ .Driver }}' 2>&1))
     8  export DOCKER_GRAPHDRIVER
     9  
    10  DOCKER_GITCOMMIT := $(shell git rev-parse HEAD)
    11  export DOCKER_GITCOMMIT
    12  
    13  # allow overriding the repository and branch that validation scripts are running
    14  # against these are used in hack/validate/.validate to check what changed in the PR.
    15  export VALIDATE_REPO
    16  export VALIDATE_BRANCH
    17  export VALIDATE_ORIGIN_BRANCH
    18  
    19  # env vars passed through directly to Docker's build scripts
    20  # to allow things like `make KEEPBUNDLE=1 binary` easily
    21  # `project/PACKAGERS.md` have some limited documentation of some of these
    22  #
    23  # DOCKER_LDFLAGS can be used to pass additional parameters to -ldflags
    24  # option of "go build". For example, a built-in graphdriver priority list
    25  # can be changed during build time like this:
    26  #
    27  # make DOCKER_LDFLAGS="-X github.com/docker/docker/daemon/graphdriver.priority=overlay2,zfs" dynbinary
    28  #
    29  DOCKER_ENVS := \
    30  	-e BUILDFLAGS \
    31  	-e KEEPBUNDLE \
    32  	-e DOCKER_BUILD_ARGS \
    33  	-e DOCKER_BUILD_GOGC \
    34  	-e DOCKER_BUILD_OPTS \
    35  	-e DOCKER_BUILD_PKGS \
    36  	-e DOCKER_BUILDKIT \
    37  	-e DOCKER_BASH_COMPLETION_PATH \
    38  	-e DOCKER_CLI_PATH \
    39  	-e DOCKERCLI_VERSION \
    40  	-e DOCKERCLI_REPOSITORY \
    41  	-e DOCKERCLI_INTEGRATION_VERSION \
    42  	-e DOCKERCLI_INTEGRATION_REPOSITORY \
    43  	-e DOCKER_DEBUG \
    44  	-e DOCKER_EXPERIMENTAL \
    45  	-e DOCKER_GITCOMMIT \
    46  	-e DOCKER_GRAPHDRIVER \
    47  	-e DOCKER_LDFLAGS \
    48  	-e DOCKER_PORT \
    49  	-e DOCKER_REMAP_ROOT \
    50  	-e DOCKER_ROOTLESS \
    51  	-e DOCKER_STORAGE_OPTS \
    52  	-e DOCKER_TEST_HOST \
    53  	-e DOCKER_USERLANDPROXY \
    54  	-e DOCKERD_ARGS \
    55  	-e DELVE_PORT \
    56  	-e GITHUB_ACTIONS \
    57  	-e TEST_FORCE_VALIDATE \
    58  	-e TEST_INTEGRATION_DIR \
    59  	-e TEST_INTEGRATION_USE_SNAPSHOTTER \
    60  	-e TEST_INTEGRATION_FAIL_FAST \
    61  	-e TEST_SKIP_INTEGRATION \
    62  	-e TEST_SKIP_INTEGRATION_CLI \
    63  	-e TEST_IGNORE_CGROUP_CHECK \
    64  	-e TESTCOVERAGE \
    65  	-e TESTDEBUG \
    66  	-e TESTDIRS \
    67  	-e TESTFLAGS \
    68  	-e TESTFLAGS_INTEGRATION \
    69  	-e TESTFLAGS_INTEGRATION_CLI \
    70  	-e TEST_FILTER \
    71  	-e TIMEOUT \
    72  	-e VALIDATE_REPO \
    73  	-e VALIDATE_BRANCH \
    74  	-e VALIDATE_ORIGIN_BRANCH \
    75  	-e VERSION \
    76  	-e PLATFORM \
    77  	-e DEFAULT_PRODUCT_LICENSE \
    78  	-e PRODUCT \
    79  	-e PACKAGER_NAME \
    80  	-e OTEL_EXPORTER_OTLP_ENDPOINT \
    81  	-e OTEL_EXPORTER_OTLP_PROTOCOL \
    82  	-e OTEL_SERVICE_NAME
    83  # 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
    84  
    85  # to allow `make BIND_DIR=. shell` or `make BIND_DIR= test`
    86  # (default to no bind mount if DOCKER_HOST is set)
    87  # note: BINDDIR is supported for backwards-compatibility here
    88  BIND_DIR := $(if $(BINDDIR),$(BINDDIR),$(if $(DOCKER_HOST),,bundles))
    89  
    90  # DOCKER_MOUNT can be overriden, but use at your own risk!
    91  ifndef DOCKER_MOUNT
    92  DOCKER_MOUNT := $(if $(BIND_DIR),-v "$(CURDIR)/$(BIND_DIR):/go/src/github.com/docker/docker/$(BIND_DIR)")
    93  DOCKER_MOUNT := $(if $(DOCKER_BINDDIR_MOUNT_OPTS),$(DOCKER_MOUNT):$(DOCKER_BINDDIR_MOUNT_OPTS),$(DOCKER_MOUNT))
    94  
    95  # 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.
    96  # The volume will be cleaned up when the container is removed due to `--rm`.
    97  # 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.
    98  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"
    99  
   100  DOCKER_MOUNT_CACHE := -v docker-dev-cache:/root/.cache -v docker-mod-cache:/go/pkg/mod/
   101  DOCKER_MOUNT_CLI := $(if $(DOCKER_CLI_PATH),-v $(shell dirname $(DOCKER_CLI_PATH)):/usr/local/cli,)
   102  DOCKER_MOUNT_BASH_COMPLETION := $(if $(DOCKER_BASH_COMPLETION_PATH),-v $(shell dirname $(DOCKER_BASH_COMPLETION_PATH)):/usr/local/completion/bash,)
   103  DOCKER_MOUNT := $(DOCKER_MOUNT) $(DOCKER_MOUNT_CACHE) $(DOCKER_MOUNT_CLI) $(DOCKER_MOUNT_BASH_COMPLETION)
   104  endif # ifndef DOCKER_MOUNT
   105  
   106  # This allows to set the docker-dev container name
   107  DOCKER_CONTAINER_NAME := $(if $(CONTAINER_NAME),--name $(CONTAINER_NAME),)
   108  
   109  DOCKER_IMAGE := docker-dev
   110  DOCKER_PORT_FORWARD := $(if $(DOCKER_PORT),-p "$(DOCKER_PORT)",)
   111  DELVE_PORT_FORWARD := $(if $(DELVE_PORT),-p "$(DELVE_PORT)",)
   112  
   113  DOCKER_FLAGS := $(DOCKER) run --rm --privileged $(DOCKER_CONTAINER_NAME) $(DOCKER_ENVS) $(DOCKER_MOUNT) $(DOCKER_PORT_FORWARD) $(DELVE_PORT_FORWARD)
   114  
   115  SWAGGER_DOCS_PORT ?= 9000
   116  
   117  define \n
   118  
   119  
   120  endef
   121  
   122  # if this session isn't interactive, then we don't want to allocate a
   123  # TTY, which would fail, but if it is interactive, we do want to attach
   124  # so that the user can send e.g. ^C through.
   125  INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0)
   126  ifeq ($(INTERACTIVE), 1)
   127  	DOCKER_FLAGS += -t
   128  endif
   129  
   130  # on GitHub Runners input device is not a TTY but we allocate a pseudo-one,
   131  # otherwise keep STDIN open even if not attached if not a GitHub Runner.
   132  ifeq ($(GITHUB_ACTIONS),true)
   133  	DOCKER_FLAGS += -t
   134  else
   135  	DOCKER_FLAGS += -i
   136  endif
   137  
   138  DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)"
   139  
   140  DOCKER_BUILD_ARGS += --build-arg=GO_VERSION
   141  DOCKER_BUILD_ARGS += --build-arg=DOCKERCLI_VERSION
   142  DOCKER_BUILD_ARGS += --build-arg=DOCKERCLI_REPOSITORY
   143  DOCKER_BUILD_ARGS += --build-arg=DOCKERCLI_INTEGRATION_VERSION
   144  DOCKER_BUILD_ARGS += --build-arg=DOCKERCLI_INTEGRATION_REPOSITORY
   145  ifdef DOCKER_SYSTEMD
   146  DOCKER_BUILD_ARGS += --build-arg=SYSTEMD=true
   147  endif
   148  
   149  BUILD_OPTS := ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS}
   150  BUILD_CMD := $(BUILDX) build
   151  BAKE_CMD := $(BUILDX) bake
   152  
   153  default: binary
   154  
   155  all: build ## validate all checks, build linux binaries, run all tests,\ncross build non-linux binaries, and generate archives
   156  	$(DOCKER_RUN_DOCKER) bash -c 'hack/validate/default && hack/make.sh'
   157  
   158  binary: bundles ## build statically linked linux binaries
   159  	$(BAKE_CMD) binary
   160  
   161  dynbinary: bundles ## build dynamically linked linux binaries
   162  	$(BAKE_CMD) dynbinary
   163  
   164  cross: bundles ## cross build the binaries
   165  	$(BAKE_CMD) binary-cross
   166  
   167  bundles:
   168  	mkdir bundles
   169  
   170  .PHONY: clean
   171  clean: clean-cache
   172  
   173  .PHONY: clean-cache
   174  clean-cache: ## remove the docker volumes that are used for caching in the dev-container
   175  	docker volume rm -f docker-dev-cache docker-mod-cache
   176  
   177  help: ## this help
   178  	@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)
   179  
   180  install: ## install the linux binaries
   181  	KEEPBUNDLE=1 hack/make.sh install-binary
   182  
   183  run: build ## run the docker daemon in a container
   184  	$(DOCKER_RUN_DOCKER) sh -c "KEEPBUNDLE=1 hack/make.sh install-binary run"
   185   
   186  .PHONY: build
   187  ifeq ($(BIND_DIR), .)
   188  build: shell_target := --target=dev-base
   189  else
   190  build: shell_target := --target=dev
   191  endif
   192  build: bundles
   193  	$(BUILD_CMD) $(BUILD_OPTS) $(shell_target) --load -t "$(DOCKER_IMAGE)" .
   194  
   195  shell: build  ## start a shell inside the build env
   196  	$(DOCKER_RUN_DOCKER) bash
   197  
   198  test: build test-unit ## run the unit, integration and docker-py tests
   199  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration test-docker-py
   200  
   201  test-docker-py: build ## run the docker-py tests
   202  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-docker-py
   203  
   204  test-integration-cli: test-integration ## (DEPRECATED) use test-integration
   205  
   206  ifneq ($(and $(TEST_SKIP_INTEGRATION),$(TEST_SKIP_INTEGRATION_CLI)),)
   207  test-integration:
   208  	@echo Both integrations suites skipped per environment variables
   209  else
   210  test-integration: build ## run the integration tests
   211  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration
   212  endif
   213  
   214  test-integration-flaky: build ## run the stress test for all new integration tests
   215  	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration-flaky
   216  
   217  test-unit: build ## run the unit tests
   218  	$(DOCKER_RUN_DOCKER) hack/test/unit
   219  
   220  validate: build ## validate DCO, Seccomp profile generation, gofmt,\n./pkg/ isolation, golint, tests, tomls, go vet and vendor
   221  	$(DOCKER_RUN_DOCKER) hack/validate/all
   222  
   223  validate-generate-files:
   224  	$(BUILD_CMD) --target "validate" \
   225  		--output "type=cacheonly" \
   226  		--file "./hack/dockerfiles/generate-files.Dockerfile" .
   227  
   228  validate-%: build ## validate specific check
   229  	$(DOCKER_RUN_DOCKER) hack/validate/$*
   230  
   231  win: bundles ## cross build the binary for windows
   232  	$(BAKE_CMD) --set *.platform=windows/amd64 binary
   233  
   234  .PHONY: swagger-gen
   235  swagger-gen:
   236  	docker run --rm -v $(PWD):/go/src/github.com/docker/docker \
   237  		-w /go/src/github.com/docker/docker \
   238  		--entrypoint hack/generate-swagger-api.sh \
   239  		-e GOPATH=/go \
   240  		quay.io/goswagger/swagger:0.7.4
   241  
   242  .PHONY: swagger-docs
   243  swagger-docs: ## preview the API documentation
   244  	@echo "API docs preview will be running at http://localhost:$(SWAGGER_DOCS_PORT)"
   245  	@docker run --rm -v $(PWD)/api/swagger.yaml:/usr/share/nginx/html/swagger.yaml \
   246  		-e 'REDOC_OPTIONS=hide-hostname="true" lazy-rendering' \
   247  		-p $(SWAGGER_DOCS_PORT):80 \
   248  		bfirsh/redoc:1.14.0
   249  
   250  .PHONY: generate-files
   251  generate-files:
   252  	$(eval $@_TMP_OUT := $(shell mktemp -d -t moby-output.XXXXXXXXXX))
   253  	ifeq ($($@_TMP_OUT),)
   254  		$(error Could not create temp directory.)
   255  	endif
   256  	$(BUILD_CMD) --target "update" \
   257  		--output "type=local,dest=$($@_TMP_OUT)" \
   258  		--file "./hack/dockerfiles/generate-files.Dockerfile" .
   259  	cp -R "$($@_TMP_OUT)"/. .
   260  	rm -rf "$($@_TMP_OUT)"/*