2017-04-25 12:57:06 -04:00
|
|
|
#
|
|
|
|
# github.com/docker/cli
|
|
|
|
#
|
|
|
|
# Makefile for developing using Docker
|
|
|
|
#
|
|
|
|
|
2019-01-14 13:40:30 -05:00
|
|
|
# Overridable env vars
|
|
|
|
DOCKER_CLI_MOUNTS ?= -v "$(CURDIR)":/go/src/github.com/docker/cli
|
|
|
|
DOCKER_CLI_CONTAINER_NAME ?=
|
|
|
|
DOCKER_CLI_GO_BUILD_CACHE ?= y
|
|
|
|
|
2021-10-11 10:54:09 -04:00
|
|
|
# Sets the name of the company that produced the windows binary.
|
|
|
|
COMPANY_NAME ?=
|
|
|
|
|
2017-08-15 16:59:43 -04:00
|
|
|
DEV_DOCKER_IMAGE_NAME = docker-cli-dev$(IMAGE_TAG)
|
2021-11-17 11:18:15 -05:00
|
|
|
E2E_IMAGE_NAME = docker-cli-e2e
|
2020-05-19 12:38:19 -04:00
|
|
|
E2E_ENGINE_VERSION ?=
|
2018-12-10 06:30:52 -05:00
|
|
|
CACHE_VOLUME_NAME := docker-cli-dev-cache
|
2019-01-14 13:40:30 -05:00
|
|
|
ifeq ($(DOCKER_CLI_GO_BUILD_CACHE),y)
|
|
|
|
DOCKER_CLI_MOUNTS += -v "$(CACHE_VOLUME_NAME):/root/.cache/go-build"
|
2018-12-10 06:30:52 -05:00
|
|
|
endif
|
2017-05-22 16:22:42 -04:00
|
|
|
VERSION = $(shell cat VERSION)
|
2020-05-19 12:38:19 -04:00
|
|
|
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)
|
2017-04-25 12:57:06 -04:00
|
|
|
|
2020-09-24 07:01:42 -04:00
|
|
|
# Some Dockerfiles use features that are only supported with BuildKit enabled
|
|
|
|
export DOCKER_BUILDKIT=1
|
|
|
|
|
2017-04-25 12:57:06 -04:00
|
|
|
# build docker image (dockerfiles/Dockerfile.build)
|
2017-05-09 17:29:14 -04:00
|
|
|
.PHONY: build_docker_image
|
2017-04-25 12:57:06 -04:00
|
|
|
build_docker_image:
|
Do not patch Dockerfiles in CI
When building the Dockerfiles for development, those images are mainly used to
create a reproducible build-environment. The source code is bind-mounted into
the image at runtime; there is no need to create an image with the actual
source code, and copying the source code into the image would lead to a new
image being created for each code-change (possibly leading up to many "dangling"
images for previous code-changes).
However, when building (and using) the development images in CI, bind-mounting
is not an option, because the daemon is running remotely.
To make this work, the circle-ci script patched the Dockerfiles when CI is run;
adding a `COPY` to the respective Dockerfiles.
Patching Dockerfiles is not really a "best practice" and, even though the source
code does not and up in the image, the source would still be _sent_ to the daemon
for each build (unless BuildKit is used).
This patch updates the makefiles, circle-ci script, and Dockerfiles;
- When building the Dockerfiles locally, pipe the Dockerfile through stdin.
Doing so, prevents the build-context from being sent to the daemon. This speeds
up the build, and doesn't fill up the Docker "temp" directory with content that's
not used
- Now that no content is sent, add the COPY instructions to the Dockerfiles, and
remove the code in the circle-ci script to "live patch" the Dockerfiles.
Before this patch is applied (with cache):
```
$ time make -f docker.Makefile build_shell_validate_image
docker build -t docker-cli-shell-validate -f ./dockerfiles/Dockerfile.shellcheck .
Sending build context to Docker daemon 41MB
Step 1/2 : FROM debian:stretch-slim
...
Successfully built 81e14e8ad856
Successfully tagged docker-cli-shell-validate:latest
2.75 real 0.45 user 0.56 sys
```
After this patch is applied (with cache)::
```
$ time make -f docker.Makefile build_shell_validate_image
cat ./dockerfiles/Dockerfile.shellcheck | docker build -t docker-cli-shell-validate -
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM debian:stretch-slim
...
Successfully built 81e14e8ad856
Successfully tagged docker-cli-shell-validate:latest
0.33 real 0.07 user 0.08 sys
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-11-28 19:06:10 -05:00
|
|
|
# build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment
|
2019-07-18 05:13:45 -04:00
|
|
|
cat ./dockerfiles/Dockerfile.dev | docker build ${DOCKER_BUILD_ARGS} --build-arg=GO_VERSION -t $(DEV_DOCKER_IMAGE_NAME) -
|
2017-04-25 12:57:06 -04:00
|
|
|
|
2019-01-14 13:40:30 -05:00
|
|
|
DOCKER_RUN_NAME_OPTION := $(if $(DOCKER_CLI_CONTAINER_NAME),--name $(DOCKER_CLI_CONTAINER_NAME),)
|
|
|
|
DOCKER_RUN := docker run --rm $(ENVVARS) $(DOCKER_CLI_MOUNTS) $(DOCKER_RUN_NAME_OPTION)
|
2018-01-18 12:53:22 -05:00
|
|
|
|
2021-09-26 12:01:38 -04:00
|
|
|
.PHONY: binary
|
|
|
|
binary:
|
2021-10-11 10:54:09 -04:00
|
|
|
COMPANY_NAME=$(COMPANY_NAME) docker buildx bake binary
|
2017-05-12 12:07:57 -04:00
|
|
|
|
2018-07-31 07:15:41 -04:00
|
|
|
build: binary ## alias for binary
|
2017-04-25 12:57:06 -04:00
|
|
|
|
2021-11-17 11:18:15 -05:00
|
|
|
plugins: ## build the CLI plugin examples
|
|
|
|
docker buildx bake plugins
|
|
|
|
|
|
|
|
plugins-cross: ## build the CLI plugin examples for all platforms
|
|
|
|
docker buildx bake plugins-cross
|
2018-12-10 10:30:19 -05:00
|
|
|
|
2017-05-09 17:29:14 -04:00
|
|
|
.PHONY: clean
|
2018-07-31 07:15:41 -04:00
|
|
|
clean: build_docker_image ## clean build artifacts
|
2019-01-14 13:40:30 -05:00
|
|
|
$(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make clean
|
2018-12-10 06:30:52 -05:00
|
|
|
docker volume rm -f $(CACHE_VOLUME_NAME)
|
2017-04-25 12:57:06 -04:00
|
|
|
|
2021-09-26 12:01:38 -04:00
|
|
|
.PHONY: cross
|
|
|
|
cross:
|
2021-10-11 10:54:09 -04:00
|
|
|
COMPANY_NAME=$(COMPANY_NAME) docker buildx bake cross
|
2021-09-26 12:01:38 -04:00
|
|
|
|
|
|
|
.PHONY: dynbinary
|
|
|
|
dynbinary: ## build dynamically linked binary
|
2021-10-11 10:54:09 -04:00
|
|
|
USE_GLIBC=1 COMPANY_NAME=$(COMPANY_NAME) docker buildx bake dynbinary
|
2021-09-26 12:01:38 -04:00
|
|
|
|
2017-05-09 17:29:14 -04:00
|
|
|
.PHONY: dev
|
2018-07-31 07:15:41 -04:00
|
|
|
dev: build_docker_image ## start a build container in interactive mode for in-container development
|
2019-01-14 13:40:30 -05:00
|
|
|
$(DOCKER_RUN) -it \
|
2020-08-28 07:34:20 -04:00
|
|
|
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
|
2020-08-28 07:19:09 -04:00
|
|
|
$(DEV_DOCKER_IMAGE_NAME)
|
2017-05-02 15:10:03 -04:00
|
|
|
|
2018-07-31 07:15:41 -04:00
|
|
|
shell: dev ## alias for dev
|
2017-05-11 18:52:17 -04:00
|
|
|
|
2017-05-09 17:29:14 -04:00
|
|
|
.PHONY: lint
|
2021-08-05 02:44:16 -04:00
|
|
|
lint: ## run linters
|
|
|
|
docker buildx bake lint
|
2017-05-09 17:29:14 -04:00
|
|
|
|
2021-09-26 12:01:38 -04:00
|
|
|
.PHONY: shellcheck
|
|
|
|
shellcheck: ## run shellcheck validation
|
|
|
|
docker buildx bake shellcheck
|
|
|
|
|
2018-12-10 08:17:14 -05:00
|
|
|
.PHONY: fmt
|
2019-01-07 11:32:56 -05:00
|
|
|
fmt: ## run gofmt
|
2019-01-14 13:40:30 -05:00
|
|
|
$(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make fmt
|
2018-12-10 08:17:14 -05:00
|
|
|
|
2017-05-09 17:29:14 -04:00
|
|
|
.PHONY: vendor
|
2021-12-16 15:15:53 -05:00
|
|
|
vendor: ## update vendor with go modules
|
|
|
|
$(eval $@_TMP_OUT := $(shell mktemp -d -t dockercli-output.XXXXXXXXXX))
|
|
|
|
docker buildx bake --set "*.output=$($@_TMP_OUT)" update-vendor
|
|
|
|
rm -rf ./vendor
|
|
|
|
cp -R "$($@_TMP_OUT)"/out/* .
|
|
|
|
rm -rf $($@_TMP_OUT)/*
|
|
|
|
|
|
|
|
.PHONY: validate-vendor
|
|
|
|
validate-vendor: ## validate vendor
|
|
|
|
docker buildx bake validate-vendor
|
|
|
|
|
|
|
|
.PHONY: mod-outdated
|
|
|
|
mod-outdated: ## check outdated dependencies
|
2022-01-13 07:47:43 -05:00
|
|
|
docker buildx bake mod-outdated
|
2017-05-11 18:52:17 -04:00
|
|
|
|
2018-01-02 09:47:31 -05:00
|
|
|
.PHONY: authors
|
|
|
|
authors: ## generate AUTHORS file from git history
|
2021-12-20 19:44:40 -05:00
|
|
|
docker buildx bake update-authors
|
2018-01-02 09:47:31 -05:00
|
|
|
|
2017-05-10 21:24:32 -04:00
|
|
|
.PHONY: manpages
|
2018-07-31 07:15:41 -04:00
|
|
|
manpages: build_docker_image ## generate man pages from go source and markdown
|
2019-01-14 13:40:30 -05:00
|
|
|
$(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make manpages
|
2017-05-10 21:24:32 -04:00
|
|
|
|
|
|
|
.PHONY: yamldocs
|
2018-07-31 07:15:41 -04:00
|
|
|
yamldocs: build_docker_image ## generate documentation YAML files consumed by docs repo
|
2019-01-14 13:40:30 -05:00
|
|
|
$(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make yamldocs
|
2017-06-29 09:10:04 -04:00
|
|
|
|
2021-12-07 08:50:16 -05:00
|
|
|
.PHONY: test ## run unit and e2e tests
|
|
|
|
test: test-unit test-e2e
|
|
|
|
|
|
|
|
.PHONY: test-unit
|
|
|
|
test-unit: ## run unit tests
|
|
|
|
docker buildx bake test
|
|
|
|
|
|
|
|
.PHONY: test-coverage
|
|
|
|
test-coverage: ## run test with coverage
|
|
|
|
docker buildx bake test-coverage
|
|
|
|
|
2021-11-17 11:18:15 -05:00
|
|
|
.PHONY: build-e2e-image
|
|
|
|
build-e2e-image:
|
2021-12-07 08:50:16 -05:00
|
|
|
mkdir -p $(CURDIR)/build/coverage
|
2021-11-17 11:18:15 -05:00
|
|
|
IMAGE_NAME=$(E2E_IMAGE_NAME) VERSION=$(VERSION) docker buildx bake e2e-image
|
|
|
|
|
2019-01-07 11:32:56 -05:00
|
|
|
.PHONY: test-e2e
|
|
|
|
test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e-connhelper-ssh ## run all e2e tests
|
2018-06-25 05:46:35 -04:00
|
|
|
|
|
|
|
.PHONY: test-e2e-experimental
|
2021-11-17 11:18:15 -05:00
|
|
|
test-e2e-experimental: build-e2e-image # run experimental e2e tests
|
2021-12-07 08:50:16 -05:00
|
|
|
docker run --rm $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 -e TEST_ENGINE_VERSION=$(E2E_ENGINE_VERSION) \
|
|
|
|
--mount type=bind,src=$(CURDIR)/build/coverage,dst=/tmp/coverage \
|
|
|
|
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
|
|
|
|
$(E2E_IMAGE_NAME)
|
2018-06-25 05:46:35 -04:00
|
|
|
|
|
|
|
.PHONY: test-e2e-non-experimental
|
2021-11-17 11:18:15 -05:00
|
|
|
test-e2e-non-experimental: build-e2e-image # run non-experimental e2e tests
|
2021-12-07 08:50:16 -05:00
|
|
|
docker run --rm $(ENVVARS) -e TEST_ENGINE_VERSION=$(E2E_ENGINE_VERSION) \
|
|
|
|
--mount type=bind,src=$(CURDIR)/build/coverage,dst=/tmp/coverage \
|
|
|
|
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
|
|
|
|
$(E2E_IMAGE_NAME)
|
2018-07-31 07:15:41 -04:00
|
|
|
|
2018-09-06 01:38:01 -04:00
|
|
|
.PHONY: test-e2e-connhelper-ssh
|
2021-11-17 11:18:15 -05:00
|
|
|
test-e2e-connhelper-ssh: build-e2e-image # run experimental SSH-connection helper e2e tests
|
2021-12-07 08:50:16 -05:00
|
|
|
docker run --rm $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 -e TEST_ENGINE_VERSION=$(E2E_ENGINE_VERSION) -e TEST_CONNHELPER=ssh \
|
|
|
|
--mount type=bind,src=$(CURDIR)/build/coverage,dst=/tmp/coverage \
|
|
|
|
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
|
|
|
|
$(E2E_IMAGE_NAME)
|
2018-09-06 01:38:01 -04:00
|
|
|
|
2018-07-31 07:15:41 -04:00
|
|
|
.PHONY: help
|
|
|
|
help: ## print this help
|
2019-01-10 07:30:03 -05:00
|
|
|
@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)
|