Debian Codegraph @

cli/docker.Makefile

raw
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 # Sets the name of the company that produced the windows binary.
13 PACKAGER_NAME ?=
14
15 DEV_DOCKER_IMAGE_NAME = docker-cli-dev$(IMAGE_TAG)
16 E2E_IMAGE_NAME = docker-cli-e2e
17 ENGINE_VERSION ?=
18 CACHE_VOLUME_NAME := docker-cli-dev-cache
19 ifeq ($(DOCKER_CLI_GO_BUILD_CACHE),y)
20 DOCKER_CLI_MOUNTS += -v "$(CACHE_VOLUME_NAME):/root/.cache/go-build"
21 endif
22 VERSION = $(shell cat VERSION)
23 ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM -e TESTFLAGS -e TESTDIRS -e GOOS -e GOARCH -e GOARM -e ENGINE_VERSION
24
25 # Some Dockerfiles use features that are only supported with BuildKit enabled
26 export DOCKER_BUILDKIT=1
27
28 # build docker image (dockerfiles/Dockerfile.build)
29 .PHONY: build_docker_image
30 build_docker_image:
31 # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment
32 cat ./dockerfiles/Dockerfile.dev | docker build ${DOCKER_BUILD_ARGS} --build-arg=GO_VERSION -t $(DEV_DOCKER_IMAGE_NAME) -
33
34 DOCKER_RUN_NAME_OPTION := $(if $(DOCKER_CLI_CONTAINER_NAME),--name $(DOCKER_CLI_CONTAINER_NAME),)
35 DOCKER_RUN := docker run --rm $(ENVVARS) $(DOCKER_CLI_MOUNTS) $(DOCKER_RUN_NAME_OPTION)
36
37 .PHONY: binary
38 binary: ## build executable
39 PACKAGER_NAME=$(PACKAGER_NAME) docker buildx bake binary
40
41 build: binary ## alias for binary
42
43 plugins: ## build the CLI plugin examples
44 docker buildx bake plugins
45
46 plugins-cross: ## build the CLI plugin examples for all platforms
47 docker buildx bake plugins-cross
48
49 .PHONY: clean
50 clean: build_docker_image ## clean build artifacts
51 $(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make clean
52 docker volume rm -f $(CACHE_VOLUME_NAME)
53
54 .PHONY: cross
55 cross:
56 PACKAGER_NAME=$(PACKAGER_NAME) docker buildx bake cross
57
58 .PHONY: dynbinary
59 dynbinary: ## build dynamically linked binary
60 USE_GLIBC=1 PACKAGER_NAME=$(PACKAGER_NAME) docker buildx bake dynbinary
61
62 .PHONY: dev
63 dev: build_docker_image ## start a build container in interactive mode for in-container development
64 $(DOCKER_RUN) -it \
65 --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
66 $(DEV_DOCKER_IMAGE_NAME)
67
68 shell: dev ## alias for dev
69
70 .PHONY: lint
71 lint: ## run linters
72 docker buildx bake lint
73
74 .PHONY: shellcheck
75 shellcheck: ## run shellcheck validation
76 docker buildx bake shellcheck
77
78 .PHONY: fmt
79 fmt: ## run gofumpt
80 $(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make fmt
81
82 .PHONY: vendor
83 vendor: ## update vendor with go modules
84 $(eval $@_TMP_OUT := $(shell mktemp -d -t dockercli-output.XXXXXXXXXX))
85 docker buildx bake --set "*.output=$($@_TMP_OUT)" update-vendor
86 rm -rf ./vendor
87 cp -R "$($@_TMP_OUT)"/out/* .
88 rm -rf $($@_TMP_OUT)/*
89
90 .PHONY: validate-vendor
91 validate-vendor: ## validate vendor
92 docker buildx bake validate-vendor
93
94 .PHONY: mod-outdated
95 mod-outdated: ## check outdated dependencies
96 docker buildx bake mod-outdated
97
98 .PHONY: authors
99 authors: ## generate AUTHORS file from git history
100 docker buildx bake update-authors
101
102 .PHONY: manpages
103 manpages: build_docker_image ## generate man pages from go source and markdown
104 $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make manpages
105
106 .PHONY: mddocs
107 mddocs: build_docker_image ## generate markdown files from go source
108 $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make mddocs
109
110 .PHONY: yamldocs
111 yamldocs: build_docker_image ## generate documentation YAML files consumed by docs repo
112 $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make yamldocs
113
114 .PHONY: test ## run unit and e2e tests
115 test: test-unit test-e2e
116
117 .PHONY: test-unit
118 test-unit: ## run unit tests
119 docker buildx bake test
120
121 .PHONY: test-coverage
122 test-coverage: ## run test with coverage
123 docker buildx bake test-coverage
124
125 .PHONY: build-e2e-image
126 build-e2e-image:
127 mkdir -p $(CURDIR)/build/coverage
128 IMAGE_NAME=$(E2E_IMAGE_NAME) VERSION=$(VERSION) docker buildx bake e2e-image
129
130 .PHONY: test-e2e
131 test-e2e: test-e2e-local test-e2e-connhelper-ssh ## run all e2e tests
132
133 .PHONY: test-e2e-local
134 test-e2e-local: build-e2e-image # run experimental e2e tests
135 docker run --rm $(ENVVARS) \
136 --mount type=bind,src=$(CURDIR)/build/coverage,dst=/tmp/coverage \
137 --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
138 $(E2E_IMAGE_NAME)
139
140 .PHONY: test-e2e-connhelper-ssh
141 test-e2e-connhelper-ssh: build-e2e-image # run experimental SSH-connection helper e2e tests
142 docker run --rm $(ENVVARS) -e TEST_CONNHELPER=ssh \
143 --mount type=bind,src=$(CURDIR)/build/coverage,dst=/tmp/coverage \
144 --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
145 $(E2E_IMAGE_NAME)
146
147 .PHONY: help
148 help: ## print this help
149 @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)