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