github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/cli/docker.Makefile (about) 1 # 2 # github.com/docker/cli 3 # 4 # Makefile for developing using Docker 5 # 6 7 # Overridable env vars 8 DOCKER_CLI_MOUNTS ?= -v "$(CURDIR)":/go/src/github.com/docker/cli 9 DOCKER_CLI_CONTAINER_NAME ?= 10 DOCKER_CLI_GO_BUILD_CACHE ?= y 11 12 DEV_DOCKER_IMAGE_NAME = docker-cli-dev$(IMAGE_TAG) 13 BINARY_NATIVE_IMAGE_NAME = docker-cli-native$(IMAGE_TAG) 14 LINTER_IMAGE_NAME = docker-cli-lint$(IMAGE_TAG) 15 CROSS_IMAGE_NAME = docker-cli-cross$(IMAGE_TAG) 16 VALIDATE_IMAGE_NAME = docker-cli-shell-validate$(IMAGE_TAG) 17 E2E_IMAGE_NAME = docker-cli-e2e$(IMAGE_TAG) 18 E2E_ENGINE_VERSION ?= 19 CACHE_VOLUME_NAME := docker-cli-dev-cache 20 ifeq ($(DOCKER_CLI_GO_BUILD_CACHE),y) 21 DOCKER_CLI_MOUNTS += -v "$(CACHE_VOLUME_NAME):/root/.cache/go-build" 22 endif 23 VERSION = $(shell cat VERSION) 24 ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM -e TESTFLAGS -e TESTDIRS -e GOOS -e GOARCH -e GOARM -e TEST_ENGINE_VERSION=$(E2E_ENGINE_VERSION) 25 26 # Some Dockerfiles use features that are only supported with BuildKit enabled 27 export DOCKER_BUILDKIT=1 28 29 # build docker image (dockerfiles/Dockerfile.build) 30 .PHONY: build_docker_image 31 build_docker_image: 32 # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment 33 cat ./dockerfiles/Dockerfile.dev | docker build ${DOCKER_BUILD_ARGS} --build-arg=GO_VERSION -t $(DEV_DOCKER_IMAGE_NAME) - 34 35 # build docker image having the linting tools (dockerfiles/Dockerfile.lint) 36 .PHONY: build_linter_image 37 build_linter_image: 38 # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment 39 cat ./dockerfiles/Dockerfile.lint | docker build ${DOCKER_BUILD_ARGS} --build-arg=GO_VERSION -t $(LINTER_IMAGE_NAME) - 40 41 .PHONY: build_cross_image 42 build_cross_image: 43 # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment 44 cat ./dockerfiles/Dockerfile.cross | docker build ${DOCKER_BUILD_ARGS} --build-arg=GO_VERSION -t $(CROSS_IMAGE_NAME) - 45 46 .PHONY: build_shell_validate_image 47 build_shell_validate_image: 48 # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment 49 cat ./dockerfiles/Dockerfile.shellcheck | docker build --build-arg=GO_VERSION -t $(VALIDATE_IMAGE_NAME) - 50 51 .PHONY: build_binary_native_image 52 build_binary_native_image: 53 # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment 54 cat ./dockerfiles/Dockerfile.binary-native | docker build --build-arg=GO_VERSION -t $(BINARY_NATIVE_IMAGE_NAME) - 55 56 .PHONY: build_e2e_image 57 build_e2e_image: 58 docker build -t $(E2E_IMAGE_NAME) --build-arg=GO_VERSION --build-arg VERSION=$(VERSION) --build-arg GITCOMMIT=$(GITCOMMIT) -f ./dockerfiles/Dockerfile.e2e . 59 60 DOCKER_RUN_NAME_OPTION := $(if $(DOCKER_CLI_CONTAINER_NAME),--name $(DOCKER_CLI_CONTAINER_NAME),) 61 DOCKER_RUN := docker run --rm $(ENVVARS) $(DOCKER_CLI_MOUNTS) $(DOCKER_RUN_NAME_OPTION) 62 63 binary: build_binary_native_image ## build the CLI 64 $(DOCKER_RUN) $(BINARY_NATIVE_IMAGE_NAME) 65 66 build: binary ## alias for binary 67 68 plugins: build_binary_native_image ## build the CLI plugin examples 69 $(DOCKER_RUN) $(BINARY_NATIVE_IMAGE_NAME) ./scripts/build/plugins 70 71 .PHONY: clean 72 clean: build_docker_image ## clean build artifacts 73 $(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make clean 74 docker volume rm -f $(CACHE_VOLUME_NAME) 75 76 .PHONY: test-unit 77 test-unit: build_docker_image ## run unit tests (using go test) 78 $(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make test-unit 79 80 .PHONY: test ## run unit and e2e tests 81 test: test-unit test-e2e 82 83 .PHONY: cross 84 cross: build_cross_image ## build the CLI for macOS and Windows 85 $(DOCKER_RUN) $(CROSS_IMAGE_NAME) make cross 86 87 .PHONY: binary-windows 88 binary-windows: build_cross_image ## build the CLI for Windows 89 $(DOCKER_RUN) $(CROSS_IMAGE_NAME) make $@ 90 91 .PHONY: plugins-windows 92 plugins-windows: build_cross_image ## build the example CLI plugins for Windows 93 $(DOCKER_RUN) $(CROSS_IMAGE_NAME) make $@ 94 95 .PHONY: binary-osx 96 binary-osx: build_cross_image ## build the CLI for macOS 97 $(DOCKER_RUN) $(CROSS_IMAGE_NAME) make $@ 98 99 .PHONY: plugins-osx 100 plugins-osx: build_cross_image ## build the example CLI plugins for macOS 101 $(DOCKER_RUN) $(CROSS_IMAGE_NAME) make $@ 102 103 .PHONY: dev 104 dev: build_docker_image ## start a build container in interactive mode for in-container development 105 $(DOCKER_RUN) -it \ 106 --mount type=bind,src=/data/docker/run/docker.sock,dst=/data/docker/run/docker.sock \ 107 $(DEV_DOCKER_IMAGE_NAME) 108 109 shell: dev ## alias for dev 110 111 .PHONY: lint 112 lint: build_linter_image ## run linters 113 $(DOCKER_RUN) -it $(LINTER_IMAGE_NAME) 114 115 .PHONY: fmt 116 fmt: ## run gofmt 117 $(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make fmt 118 119 .PHONY: vendor 120 vendor: build_docker_image vendor.conf ## download dependencies (vendor/) listed in vendor.conf 121 $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make vendor 122 123 dynbinary: build_cross_image ## build the CLI dynamically linked 124 $(DOCKER_RUN) -it $(CROSS_IMAGE_NAME) make dynbinary 125 126 .PHONY: authors 127 authors: ## generate AUTHORS file from git history 128 $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make authors 129 130 .PHONY: compose-jsonschema 131 compose-jsonschema: build_docker_image ## generate compose-file schemas 132 $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make compose-jsonschema 133 134 .PHONY: manpages 135 manpages: build_docker_image ## generate man pages from go source and markdown 136 $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make manpages 137 138 .PHONY: yamldocs 139 yamldocs: build_docker_image ## generate documentation YAML files consumed by docs repo 140 $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make yamldocs 141 142 .PHONY: shellcheck 143 shellcheck: build_shell_validate_image ## run shellcheck validation 144 $(DOCKER_RUN) -it $(VALIDATE_IMAGE_NAME) make shellcheck 145 146 .PHONY: test-e2e 147 test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e-connhelper-ssh ## run all e2e tests 148 149 .PHONY: test-e2e-experimental 150 test-e2e-experimental: build_e2e_image # run experimental e2e tests 151 docker run --rm --mount type=bind,src=/data/docker/run/docker.sock,dst=/data/docker/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 $(E2E_IMAGE_NAME) 152 153 .PHONY: test-e2e-non-experimental 154 test-e2e-non-experimental: build_e2e_image # run non-experimental e2e tests 155 docker run --rm --mount type=bind,src=/data/docker/run/docker.sock,dst=/data/docker/run/docker.sock $(ENVVARS) -e TEST_ENGINE_VERSION=$(E2E_ENGINE_VERSION) $(E2E_IMAGE_NAME) 156 157 .PHONY: test-e2e-connhelper-ssh 158 test-e2e-connhelper-ssh: build_e2e_image # run experimental SSH-connection helper e2e tests 159 docker run --rm --mount type=bind,src=/data/docker/run/docker.sock,dst=/data/docker/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 -e TEST_CONNHELPER=ssh $(E2E_IMAGE_NAME) 160 161 .PHONY: help 162 help: ## print this help 163 @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)