| 1 |
DOCKER ?= docker |
| 2 |
BUILDX ?= $(DOCKER) buildx |
| 3 |
|
| 4 |
DOCKER_GITCOMMIT := $(shell git rev-parse HEAD) |
| 5 |
export DOCKER_GITCOMMIT |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
export VALIDATE_REPO |
| 10 |
export VALIDATE_BRANCH |
| 11 |
export VALIDATE_ORIGIN_BRANCH |
| 12 |
|
| 13 |
export PAGER |
| 14 |
export GIT_PAGER |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
DOCKER_ENVS := \ |
| 27 |
-e BUILDFLAGS \ |
| 28 |
-e KEEPBUNDLE \ |
| 29 |
-e DOCKER_BUILD_ARGS \ |
| 30 |
-e DOCKER_BUILD_GOGC \ |
| 31 |
-e DOCKER_BUILD_OPTS \ |
| 32 |
-e DOCKER_BUILD_PKGS \ |
| 33 |
-e DOCKER_BUILDKIT \ |
| 34 |
-e DOCKER_CLI_PATH \ |
| 35 |
-e DOCKERCLI_VERSION \ |
| 36 |
-e DOCKERCLI_REPOSITORY \ |
| 37 |
-e DOCKERCLI_INTEGRATION_VERSION \ |
| 38 |
-e DOCKERCLI_INTEGRATION_REPOSITORY \ |
| 39 |
-e DOCKER_DEBUG \ |
| 40 |
-e DOCKER_EXPERIMENTAL \ |
| 41 |
-e DOCKER_GITCOMMIT \ |
| 42 |
-e DOCKER_GRAPHDRIVER \ |
| 43 |
-e DOCKER_LDFLAGS \ |
| 44 |
-e DOCKER_PORT \ |
| 45 |
-e DOCKER_REMAP_ROOT \ |
| 46 |
-e DOCKER_ROOTLESS \ |
| 47 |
-e DOCKER_STORAGE_OPTS \ |
| 48 |
-e DOCKER_TEST_HOST \ |
| 49 |
-e DOCKER_USERLANDPROXY \ |
| 50 |
-e DOCKERD_ARGS \ |
| 51 |
-e DELVE_PORT \ |
| 52 |
-e FIREWALLD \ |
| 53 |
-e GITHUB_ACTIONS \ |
| 54 |
-e TEST_FORCE_VALIDATE \ |
| 55 |
-e TEST_INTEGRATION_DIR \ |
| 56 |
-e TEST_INTEGRATION_USE_SNAPSHOTTER \ |
| 57 |
-e TEST_INTEGRATION_FAIL_FAST \ |
| 58 |
-e TEST_SKIP_INTEGRATION \ |
| 59 |
-e TEST_SKIP_INTEGRATION_CLI \ |
| 60 |
-e TESTCOVERAGE \ |
| 61 |
-e TESTDEBUG \ |
| 62 |
-e TESTDIRS \ |
| 63 |
-e TESTFLAGS \ |
| 64 |
-e TESTFLAGS_INTEGRATION \ |
| 65 |
-e TESTFLAGS_INTEGRATION_CLI \ |
| 66 |
-e TEST_FILTER \ |
| 67 |
-e TIMEOUT \ |
| 68 |
-e VALIDATE_REPO \ |
| 69 |
-e VALIDATE_BRANCH \ |
| 70 |
-e VALIDATE_ORIGIN_BRANCH \ |
| 71 |
-e VERSION \ |
| 72 |
-e PLATFORM \ |
| 73 |
-e DEFAULT_PRODUCT_LICENSE \ |
| 74 |
-e PRODUCT \ |
| 75 |
-e PACKAGER_NAME \ |
| 76 |
-e PAGER \ |
| 77 |
-e GIT_PAGER \ |
| 78 |
-e OTEL_EXPORTER_OTLP_ENDPOINT \ |
| 79 |
-e OTEL_EXPORTER_OTLP_PROTOCOL \ |
| 80 |
-e OTEL_SERVICE_NAME |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
BIND_DIR := $(if $(BINDDIR),$(BINDDIR),$(if $(DOCKER_HOST),,.)) |
| 87 |
|
| 88 |
|
| 89 |
ifndef DOCKER_MOUNT |
| 90 |
DOCKER_MOUNT := $(if $(BIND_DIR),-v "$(BIND_DIR):/go/src/github.com/docker/docker/$(BIND_DIR)") |
| 91 |
DOCKER_MOUNT := $(if $(DOCKER_BINDDIR_MOUNT_OPTS),$(DOCKER_MOUNT):$(DOCKER_BINDDIR_MOUNT_OPTS),$(DOCKER_MOUNT)) |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
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" |
| 97 |
|
| 98 |
DOCKER_MOUNT_CACHE := -v docker-dev-cache:/root/.cache -v docker-mod-cache:/go/pkg/mod/ |
| 99 |
DOCKER_MOUNT_CLI := $(if $(DOCKER_CLI_PATH),-v $(shell dirname $(DOCKER_CLI_PATH)):/usr/local/cli,) |
| 100 |
|
| 101 |
ifdef BIND_GIT |
| 102 |
# Gets the common .git directory (even from inside a git worktree) |
| 103 |
GITDIR := $(shell realpath $(shell git rev-parse --git-common-dir)) |
| 104 |
MOUNT_GITDIR := $(if $(GITDIR),-v "$(GITDIR):$(GITDIR)") |
| 105 |
endif |
| 106 |
|
| 107 |
DOCKER_MOUNT := $(DOCKER_MOUNT) $(DOCKER_MOUNT_CACHE) $(DOCKER_MOUNT_CLI) $(DOCKER_MOUNT_BASH_COMPLETION) $(MOUNT_GITDIR) |
| 108 |
endif |
| 109 |
|
| 110 |
|
| 111 |
DOCKER_CONTAINER_NAME := $(if $(CONTAINER_NAME),--name $(CONTAINER_NAME),) |
| 112 |
|
| 113 |
DOCKER_IMAGE := docker-dev |
| 114 |
DOCKER_PORT_FORWARD := $(if $(DOCKER_PORT),-p "$(DOCKER_PORT)",) |
| 115 |
DELVE_PORT_FORWARD := $(if $(DELVE_PORT),-p "$(DELVE_PORT)",) |
| 116 |
|
| 117 |
DOCKER_FLAGS := $(DOCKER) run --rm --privileged $(DOCKER_CONTAINER_NAME) $(DOCKER_ENVS) $(DOCKER_MOUNT) $(DOCKER_PORT_FORWARD) $(DELVE_PORT_FORWARD) |
| 118 |
|
| 119 |
SWAGGER_DOCS_PORT ?= 9000 |
| 120 |
|
| 121 |
define \n |
| 122 |
|
| 123 |
|
| 124 |
endef |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0) |
| 130 |
ifeq ($(INTERACTIVE), 1) |
| 131 |
DOCKER_FLAGS += -t |
| 132 |
endif |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
ifeq ($(GITHUB_ACTIONS),true) |
| 137 |
DOCKER_FLAGS += -t |
| 138 |
else |
| 139 |
DOCKER_FLAGS += -i |
| 140 |
endif |
| 141 |
|
| 142 |
DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)" |
| 143 |
|
| 144 |
DOCKER_BUILD_ARGS += --build-arg=GO_VERSION |
| 145 |
DOCKER_BUILD_ARGS += --build-arg=DOCKERCLI_VERSION |
| 146 |
DOCKER_BUILD_ARGS += --build-arg=DOCKERCLI_REPOSITORY |
| 147 |
DOCKER_BUILD_ARGS += --build-arg=DOCKERCLI_INTEGRATION_VERSION |
| 148 |
DOCKER_BUILD_ARGS += --build-arg=DOCKERCLI_INTEGRATION_REPOSITORY |
| 149 |
ifdef DOCKER_SYSTEMD |
| 150 |
DOCKER_BUILD_ARGS += --build-arg=SYSTEMD=true |
| 151 |
endif |
| 152 |
ifdef FIREWALLD |
| 153 |
DOCKER_BUILD_ARGS += --build-arg=FIREWALLD=true |
| 154 |
endif |
| 155 |
|
| 156 |
BUILD_OPTS := ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} |
| 157 |
BUILD_CMD := $(BUILDX) build |
| 158 |
BAKE_CMD := $(BUILDX) bake |
| 159 |
|
| 160 |
default: binary |
| 161 |
|
| 162 |
.PHONY: all |
| 163 |
all: build |
| 164 |
$(DOCKER_RUN_DOCKER) bash -c 'hack/validate/default && hack/make.sh' |
| 165 |
|
| 166 |
.PHONY: binary |
| 167 |
binary: bundles |
| 168 |
$(BAKE_CMD) binary |
| 169 |
|
| 170 |
.PHONY: dynbinary |
| 171 |
dynbinary: bundles |
| 172 |
$(BAKE_CMD) dynbinary |
| 173 |
|
| 174 |
.PHONY: cross |
| 175 |
cross: bundles |
| 176 |
$(BAKE_CMD) binary-cross |
| 177 |
|
| 178 |
bundles: |
| 179 |
mkdir bundles |
| 180 |
|
| 181 |
.PHONY: clean |
| 182 |
clean: clean-cache |
| 183 |
|
| 184 |
.PHONY: clean-cache |
| 185 |
clean-cache: |
| 186 |
docker volume rm -f docker-dev-cache docker-mod-cache |
| 187 |
|
| 188 |
.PHONY: help |
| 189 |
help: |
| 190 |
@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) |
| 191 |
|
| 192 |
.PHONY: install |
| 193 |
install: |
| 194 |
KEEPBUNDLE=1 hack/make.sh install-binary |
| 195 |
|
| 196 |
.PHONY: run |
| 197 |
run: build |
| 198 |
$(DOCKER_RUN_DOCKER) sh -c "KEEPBUNDLE=1 hack/make.sh install-binary run" |
| 199 |
|
| 200 |
.PHONY: build |
| 201 |
ifeq ($(BIND_DIR), .) |
| 202 |
build: shell_target := --target=dev-base |
| 203 |
else |
| 204 |
build: shell_target := --target=dev |
| 205 |
endif |
| 206 |
build: validate-bind-dir bundles |
| 207 |
$(BUILD_CMD) $(BUILD_OPTS) $(shell_target) --load -t "$(DOCKER_IMAGE)" . |
| 208 |
|
| 209 |
.PHONY: shell |
| 210 |
shell: build |
| 211 |
$(DOCKER_RUN_DOCKER) bash |
| 212 |
|
| 213 |
.PHONY: test |
| 214 |
test: build test-unit |
| 215 |
$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration test-docker-py |
| 216 |
|
| 217 |
.PHONY: test-docker-py |
| 218 |
test-docker-py: build |
| 219 |
$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-docker-py |
| 220 |
|
| 221 |
.PHONY: test-integration-cli |
| 222 |
test-integration-cli: test-integration |
| 223 |
|
| 224 |
.PHONY: test-integration |
| 225 |
ifneq ($(and $(TEST_SKIP_INTEGRATION),$(TEST_SKIP_INTEGRATION_CLI)),) |
| 226 |
test-integration: |
| 227 |
@echo Both integrations suites skipped per environment variables |
| 228 |
else |
| 229 |
test-integration: build |
| 230 |
$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration |
| 231 |
endif |
| 232 |
|
| 233 |
.PHONY: test-integration-flaky |
| 234 |
test-integration-flaky: build |
| 235 |
$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration-flaky |
| 236 |
|
| 237 |
.PHONY: test-unit |
| 238 |
test-unit: build |
| 239 |
$(DOCKER_RUN_DOCKER) hack/test/unit |
| 240 |
|
| 241 |
.PHONY: validate |
| 242 |
validate: build |
| 243 |
$(DOCKER_RUN_DOCKER) hack/validate/all |
| 244 |
|
| 245 |
.PHONY: validate-generate-files |
| 246 |
validate-generate-files: |
| 247 |
$(BUILD_CMD) --target "validate" \ |
| 248 |
--output "type=cacheonly" \ |
| 249 |
--file "./hack/dockerfiles/generate-files.Dockerfile" . |
| 250 |
|
| 251 |
.PHONY: validate-% |
| 252 |
validate-%: build |
| 253 |
$(DOCKER_RUN_DOCKER) hack/validate/$* |
| 254 |
|
| 255 |
.PHONY: win |
| 256 |
win: bundles |
| 257 |
$(BAKE_CMD) --set *.platform=windows/amd64 binary |
| 258 |
|
| 259 |
.PHONY: swagger-gen |
| 260 |
swagger-gen: |
| 261 |
docker run --rm -v $(PWD):/go/src/github.com/docker/docker \ |
| 262 |
-w /go/src/github.com/docker/docker \ |
| 263 |
--entrypoint hack/generate-swagger-api.sh \ |
| 264 |
-e GOPATH=/go \ |
| 265 |
quay.io/goswagger/swagger:0.7.4 |
| 266 |
|
| 267 |
.PHONY: swagger-docs |
| 268 |
swagger-docs: |
| 269 |
@echo "API docs preview will be running at http://localhost:$(SWAGGER_DOCS_PORT)" |
| 270 |
@docker run --rm -v $(PWD)/api/swagger.yaml:/usr/share/nginx/html/swagger.yaml \ |
| 271 |
-e 'REDOC_OPTIONS=hide-hostname="true" lazy-rendering' \ |
| 272 |
-p $(SWAGGER_DOCS_PORT):80 \ |
| 273 |
bfirsh/redoc:1.14.0 |
| 274 |
|
| 275 |
.PHONY: generate-files |
| 276 |
generate-files: |
| 277 |
$(eval $@_TMP_OUT := $(shell mktemp -d -t moby-output.XXXXXXXXXX)) |
| 278 |
@if [ -z "$($@_TMP_OUT)" ]; then \ |
| 279 |
echo "Temp dir is not set"; \ |
| 280 |
exit 1; \ |
| 281 |
fi |
| 282 |
$(BUILD_CMD) --target "update" \ |
| 283 |
--output "type=local,dest=$($@_TMP_OUT)" \ |
| 284 |
--file "./hack/dockerfiles/generate-files.Dockerfile" . |
| 285 |
cp -R "$($@_TMP_OUT)"/. . |
| 286 |
rm -rf "$($@_TMP_OUT)"/* |
| 287 |
|
| 288 |
.PHONY: validate-bind-dir |
| 289 |
validate-bind-dir: |
| 290 |
@case "$(BIND_DIR)" in \ |
| 291 |
".."*|"/"*) echo "Make needs to be run from the project-root directory, with BIND_DIR set to \".\" or a subdir"; \ |
| 292 |
exit 1 ;; \ |
| 293 |
esac |