...
1#
2# github.com/docker/cli
3#
4# Makefile for developing using Docker
5#
6
7# Overridable env vars
8DOCKER_CLI_MOUNTS ?= -v "$(CURDIR)":/go/src/github.com/docker/cli
9DOCKER_CLI_CONTAINER_NAME ?=
10DOCKER_CLI_GO_BUILD_CACHE ?= y
11
12# Sets the name of the company that produced the windows binary.
13PACKAGER_NAME ?=
14
15DEV_DOCKER_IMAGE_NAME = docker-cli-dev$(IMAGE_TAG)
16E2E_IMAGE_NAME = docker-cli-e2e
17ENGINE_VERSION ?=
18CACHE_VOLUME_NAME := docker-cli-dev-cache
19ifeq ($(DOCKER_CLI_GO_BUILD_CACHE),y)
20DOCKER_CLI_MOUNTS += -v "$(CACHE_VOLUME_NAME):/root/.cache/go-build"
21endif
22VERSION = $(shell cat VERSION)
23ENVVARS = -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
26export DOCKER_BUILDKIT=1
27
28# build docker image (dockerfiles/Dockerfile.build)
29.PHONY: build_docker_image
30build_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
34DOCKER_RUN_NAME_OPTION := $(if $(DOCKER_CLI_CONTAINER_NAME),--name $(DOCKER_CLI_CONTAINER_NAME),)
35DOCKER_RUN := docker run --rm $(ENVVARS) $(DOCKER_CLI_MOUNTS) $(DOCKER_RUN_NAME_OPTION)
36
37.PHONY: binary
38binary: ## build executable
39 PACKAGER_NAME=$(PACKAGER_NAME) docker buildx bake binary
40
41build: binary ## alias for binary
42
43plugins: ## build the CLI plugin examples
44 docker buildx bake plugins
45
46plugins-cross: ## build the CLI plugin examples for all platforms
47 docker buildx bake plugins-cross
48
49.PHONY: clean
50clean: 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
55cross:
56 PACKAGER_NAME=$(PACKAGER_NAME) docker buildx bake cross
57
58.PHONY: dynbinary
59dynbinary: ## build dynamically linked binary
60 USE_GLIBC=1 PACKAGER_NAME=$(PACKAGER_NAME) docker buildx bake dynbinary
61
62.PHONY: dev
63dev: 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
68shell: dev ## alias for dev
69
70.PHONY: lint
71lint: ## run linters
72 docker buildx bake lint
73
74.PHONY: shellcheck
75shellcheck: ## run shellcheck validation
76 docker buildx bake shellcheck
77
78.PHONY: fmt
79fmt: ## run gofumpt
80 $(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make fmt
81
82.PHONY: vendor
83vendor: ## 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
91validate-vendor: ## validate vendor
92 docker buildx bake validate-vendor
93
94.PHONY: mod-outdated
95mod-outdated: ## check outdated dependencies
96 docker buildx bake mod-outdated
97
98.PHONY: authors
99authors: ## generate AUTHORS file from git history
100 docker buildx bake update-authors
101
102.PHONY: manpages
103manpages: 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
107mddocs: build_docker_image ## generate markdown files from go source
108 $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make mddocs
109
110.PHONY: yamldocs
111yamldocs: 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
115test: test-unit test-e2e
116
117.PHONY: test-unit
118test-unit: ## run unit tests
119 docker buildx bake test
120
121.PHONY: test-coverage
122test-coverage: ## run test with coverage
123 docker buildx bake test-coverage
124
125.PHONY: build-e2e-image
126build-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
131test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e-connhelper-ssh ## run all e2e tests
132
133.PHONY: test-e2e-experimental
134test-e2e-experimental: build-e2e-image # run experimental e2e tests
135 docker run --rm $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 \
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-non-experimental
141test-e2e-non-experimental: build-e2e-image # run non-experimental e2e tests
142 docker run --rm $(ENVVARS) \
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: test-e2e-connhelper-ssh
148test-e2e-connhelper-ssh: build-e2e-image # run experimental SSH-connection helper e2e tests
149 docker run --rm $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 -e TEST_CONNHELPER=ssh \
150 --mount type=bind,src=$(CURDIR)/build/coverage,dst=/tmp/coverage \
151 --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
152 $(E2E_IMAGE_NAME)
153
154.PHONY: help
155help: ## print this help
156 @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)
View as plain text