github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/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_shell_validate_image
    42  build_shell_validate_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.shellcheck | docker build --build-arg=GO_VERSION -t $(VALIDATE_IMAGE_NAME) -
    45  
    46  .PHONY: build_binary_native_image
    47  build_binary_native_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.binary-native | docker build --build-arg=GO_VERSION -t $(BINARY_NATIVE_IMAGE_NAME) -
    50  
    51  .PHONY: build_e2e_image
    52  build_e2e_image:
    53  	docker build -t $(E2E_IMAGE_NAME) --build-arg=GO_VERSION --build-arg VERSION=$(VERSION) --build-arg GITCOMMIT=$(GITCOMMIT) -f ./dockerfiles/Dockerfile.e2e .
    54  
    55  DOCKER_RUN_NAME_OPTION := $(if $(DOCKER_CLI_CONTAINER_NAME),--name $(DOCKER_CLI_CONTAINER_NAME),)
    56  DOCKER_RUN := docker run --rm $(ENVVARS) $(DOCKER_CLI_MOUNTS) $(DOCKER_RUN_NAME_OPTION)
    57  
    58  binary: build_binary_native_image ## build the CLI
    59  	$(DOCKER_RUN) $(BINARY_NATIVE_IMAGE_NAME)
    60  
    61  build: binary ## alias for binary
    62  
    63  plugins: build_binary_native_image ## build the CLI plugin examples
    64  	$(DOCKER_RUN) $(BINARY_NATIVE_IMAGE_NAME) ./scripts/build/plugins
    65  
    66  .PHONY: clean
    67  clean: build_docker_image ## clean build artifacts
    68  	$(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make clean
    69  	docker volume rm -f $(CACHE_VOLUME_NAME)
    70  
    71  .PHONY: test-unit
    72  test-unit: build_docker_image ## run unit tests (using go test)
    73  	$(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make test-unit
    74  
    75  .PHONY: test ## run unit and e2e tests
    76  test: test-unit test-e2e
    77  
    78  .PHONY: plugins-windows
    79  plugins-windows: build_cross_image ## build the example CLI plugins for Windows
    80  	$(DOCKER_RUN) $(CROSS_IMAGE_NAME) make $@
    81  
    82  .PHONY: plugins-osx
    83  plugins-osx: build_cross_image ## build the example CLI plugins for macOS
    84  	$(DOCKER_RUN) $(CROSS_IMAGE_NAME) make $@
    85  
    86  .PHONY: dev
    87  dev: build_docker_image ## start a build container in interactive mode for in-container development
    88  	$(DOCKER_RUN) -it \
    89  		--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
    90  		$(DEV_DOCKER_IMAGE_NAME)
    91  
    92  shell: dev ## alias for dev
    93  
    94  .PHONY: lint
    95  lint: build_linter_image ## run linters
    96  	$(DOCKER_RUN) -it $(LINTER_IMAGE_NAME)
    97  
    98  .PHONY: fmt
    99  fmt: ## run gofmt
   100  	$(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make fmt
   101  
   102  .PHONY: vendor
   103  vendor: build_docker_image vendor.conf ## download dependencies (vendor/) listed in vendor.conf
   104  	$(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make vendor
   105  
   106  .PHONY: authors
   107  authors: ## generate AUTHORS file from git history
   108  	$(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make authors
   109  
   110  .PHONY: compose-jsonschema
   111  compose-jsonschema: build_docker_image ## generate compose-file schemas
   112  	$(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make compose-jsonschema
   113  
   114  .PHONY: manpages
   115  manpages: build_docker_image ## generate man pages from go source and markdown
   116  	$(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make manpages
   117  
   118  .PHONY: yamldocs
   119  yamldocs: build_docker_image ## generate documentation YAML files consumed by docs repo
   120  	$(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make yamldocs
   121  
   122  .PHONY: shellcheck
   123  shellcheck: build_shell_validate_image ## run shellcheck validation
   124  	$(DOCKER_RUN) -it $(VALIDATE_IMAGE_NAME) make shellcheck
   125  
   126  .PHONY: test-e2e
   127  test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e-connhelper-ssh ## run all e2e tests
   128  
   129  .PHONY: test-e2e-experimental
   130  test-e2e-experimental: build_e2e_image # run experimental e2e tests
   131  	docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 $(E2E_IMAGE_NAME)
   132  
   133  .PHONY: test-e2e-non-experimental
   134  test-e2e-non-experimental: build_e2e_image # run non-experimental e2e tests
   135  	docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock $(ENVVARS) -e TEST_ENGINE_VERSION=$(E2E_ENGINE_VERSION) $(E2E_IMAGE_NAME)
   136  
   137  .PHONY: test-e2e-connhelper-ssh
   138  test-e2e-connhelper-ssh: build_e2e_image # run experimental SSH-connection helper e2e tests
   139  	docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 -e TEST_CONNHELPER=ssh $(E2E_IMAGE_NAME)
   140  
   141  .PHONY: help
   142  help: ## print this help
   143  	@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)