Merge pull request #1511 from wk8/wk8/small_makefile_tweaks

Make it possible to override the volume mounts and shell for the dev container
This commit is contained in:
Brian Goff 2019-02-21 11:06:10 -08:00 committed by GitHub
commit 35c39d3264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 20 deletions

View File

@ -4,17 +4,21 @@
# Makefile for developing using Docker # Makefile for developing using Docker
# #
# Overridable env vars
DOCKER_CLI_MOUNTS ?= -v "$(CURDIR)":/go/src/github.com/docker/cli
DOCKER_CLI_SHELL ?= ash
DOCKER_CLI_CONTAINER_NAME ?=
DOCKER_CLI_GO_BUILD_CACHE ?= y
DEV_DOCKER_IMAGE_NAME = docker-cli-dev$(IMAGE_TAG) DEV_DOCKER_IMAGE_NAME = docker-cli-dev$(IMAGE_TAG)
BINARY_NATIVE_IMAGE_NAME = docker-cli-native$(IMAGE_TAG) BINARY_NATIVE_IMAGE_NAME = docker-cli-native$(IMAGE_TAG)
LINTER_IMAGE_NAME = docker-cli-lint$(IMAGE_TAG) LINTER_IMAGE_NAME = docker-cli-lint$(IMAGE_TAG)
CROSS_IMAGE_NAME = docker-cli-cross$(IMAGE_TAG) CROSS_IMAGE_NAME = docker-cli-cross$(IMAGE_TAG)
VALIDATE_IMAGE_NAME = docker-cli-shell-validate$(IMAGE_TAG) VALIDATE_IMAGE_NAME = docker-cli-shell-validate$(IMAGE_TAG)
E2E_IMAGE_NAME = docker-cli-e2e$(IMAGE_TAG) E2E_IMAGE_NAME = docker-cli-e2e$(IMAGE_TAG)
GO_BUILD_CACHE ?= y
MOUNTS = -v "$(CURDIR)":/go/src/github.com/docker/cli
CACHE_VOLUME_NAME := docker-cli-dev-cache CACHE_VOLUME_NAME := docker-cli-dev-cache
ifeq ($(GO_BUILD_CACHE),y) ifeq ($(DOCKER_CLI_GO_BUILD_CACHE),y)
MOUNTS += -v "$(CACHE_VOLUME_NAME):/root/.cache/go-build" DOCKER_CLI_MOUNTS += -v "$(CACHE_VOLUME_NAME):/root/.cache/go-build"
endif endif
VERSION = $(shell cat VERSION) VERSION = $(shell cat VERSION)
ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM
@ -50,9 +54,11 @@ build_binary_native_image:
build_e2e_image: build_e2e_image:
docker build -t $(E2E_IMAGE_NAME) --build-arg VERSION=$(VERSION) --build-arg GITCOMMIT=$(GITCOMMIT) -f ./dockerfiles/Dockerfile.e2e . docker build -t $(E2E_IMAGE_NAME) --build-arg VERSION=$(VERSION) --build-arg GITCOMMIT=$(GITCOMMIT) -f ./dockerfiles/Dockerfile.e2e .
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)
binary: build_binary_native_image ## build the CLI binary: build_binary_native_image ## build the CLI
docker run --rm $(ENVVARS) $(MOUNTS) $(BINARY_NATIVE_IMAGE_NAME) $(DOCKER_RUN) $(BINARY_NATIVE_IMAGE_NAME)
build: binary ## alias for binary build: binary ## alias for binary
@ -61,23 +67,23 @@ plugins: build_binary_native_image ## build the CLI plugin examples
.PHONY: clean .PHONY: clean
clean: build_docker_image ## clean build artifacts clean: build_docker_image ## clean build artifacts
docker run --rm $(ENVVARS) $(MOUNTS) $(DEV_DOCKER_IMAGE_NAME) make clean $(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make clean
docker volume rm -f $(CACHE_VOLUME_NAME) docker volume rm -f $(CACHE_VOLUME_NAME)
.PHONY: test-unit .PHONY: test-unit
test-unit: build_docker_image ## run unit tests (using go test) test-unit: build_docker_image ## run unit tests (using go test)
docker run --rm $(ENVVARS) $(MOUNTS) $(DEV_DOCKER_IMAGE_NAME) make test-unit $(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make test-unit
.PHONY: test ## run unit and e2e tests .PHONY: test ## run unit and e2e tests
test: test-unit test-e2e test: test-unit test-e2e
.PHONY: cross .PHONY: cross
cross: build_cross_image ## build the CLI for macOS and Windows cross: build_cross_image ## build the CLI for macOS and Windows
docker run --rm $(ENVVARS) $(MOUNTS) $(CROSS_IMAGE_NAME) make cross $(DOCKER_RUN) $(CROSS_IMAGE_NAME) make cross
.PHONY: binary-windows .PHONY: binary-windows
binary-windows: build_cross_image ## build the CLI for Windows binary-windows: build_cross_image ## build the CLI for Windows
docker run --rm $(ENVVARS) $(MOUNTS) $(CROSS_IMAGE_NAME) make $@ $(DOCKER_RUN) $(CROSS_IMAGE_NAME) make $@
.PHONY: plugins-windows .PHONY: plugins-windows
plugins-windows: build_cross_image ## build the example CLI plugins for Windows plugins-windows: build_cross_image ## build the example CLI plugins for Windows
@ -85,7 +91,7 @@ plugins-windows: build_cross_image ## build the example CLI plugins for Windows
.PHONY: binary-osx .PHONY: binary-osx
binary-osx: build_cross_image ## build the CLI for macOS binary-osx: build_cross_image ## build the CLI for macOS
docker run --rm $(ENVVARS) $(MOUNTS) $(CROSS_IMAGE_NAME) make $@ $(DOCKER_RUN) $(CROSS_IMAGE_NAME) make $@
.PHONY: plugins-osx .PHONY: plugins-osx
plugins-osx: build_cross_image ## build the example CLI plugins for macOS plugins-osx: build_cross_image ## build the example CLI plugins for macOS
@ -93,42 +99,42 @@ plugins-osx: build_cross_image ## build the example CLI plugins for macOS
.PHONY: dev .PHONY: dev
dev: build_docker_image ## start a build container in interactive mode for in-container development dev: build_docker_image ## start a build container in interactive mode for in-container development
docker run -ti --rm $(ENVVARS) $(MOUNTS) \ $(DOCKER_RUN) -it \
-v /var/run/docker.sock:/var/run/docker.sock \ -v /var/run/docker.sock:/var/run/docker.sock \
$(DEV_DOCKER_IMAGE_NAME) ash $(DEV_DOCKER_IMAGE_NAME) $(DOCKER_CLI_SHELL)
shell: dev ## alias for dev shell: dev ## alias for dev
.PHONY: lint .PHONY: lint
lint: build_linter_image ## run linters lint: build_linter_image ## run linters
docker run -ti --rm $(ENVVARS) $(MOUNTS) $(LINTER_IMAGE_NAME) $(DOCKER_RUN) -it $(LINTER_IMAGE_NAME)
.PHONY: fmt .PHONY: fmt
fmt: ## run gofmt fmt: ## run gofmt
docker run --rm $(ENVVARS) $(MOUNTS) $(DEV_DOCKER_IMAGE_NAME) make fmt $(DOCKER_RUN) $(DEV_DOCKER_IMAGE_NAME) make fmt
.PHONY: vendor .PHONY: vendor
vendor: build_docker_image vendor.conf ## download dependencies (vendor/) listed in vendor.conf vendor: build_docker_image vendor.conf ## download dependencies (vendor/) listed in vendor.conf
docker run -ti --rm $(ENVVARS) $(MOUNTS) $(DEV_DOCKER_IMAGE_NAME) make vendor $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make vendor
dynbinary: build_cross_image ## build the CLI dynamically linked dynbinary: build_cross_image ## build the CLI dynamically linked
docker run -ti --rm $(ENVVARS) $(MOUNTS) $(CROSS_IMAGE_NAME) make dynbinary $(DOCKER_RUN) -it $(CROSS_IMAGE_NAME) make dynbinary
.PHONY: authors .PHONY: authors
authors: ## generate AUTHORS file from git history authors: ## generate AUTHORS file from git history
docker run -ti --rm $(ENVVARS) $(MOUNTS) $(DEV_DOCKER_IMAGE_NAME) make authors $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make authors
.PHONY: manpages .PHONY: manpages
manpages: build_docker_image ## generate man pages from go source and markdown manpages: build_docker_image ## generate man pages from go source and markdown
docker run -ti --rm $(ENVVARS) $(MOUNTS) $(DEV_DOCKER_IMAGE_NAME) make manpages $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make manpages
.PHONY: yamldocs .PHONY: yamldocs
yamldocs: build_docker_image ## generate documentation YAML files consumed by docs repo yamldocs: build_docker_image ## generate documentation YAML files consumed by docs repo
docker run -ti --rm $(ENVVARS) $(MOUNTS) $(DEV_DOCKER_IMAGE_NAME) make yamldocs $(DOCKER_RUN) -it $(DEV_DOCKER_IMAGE_NAME) make yamldocs
.PHONY: shellcheck .PHONY: shellcheck
shellcheck: build_shell_validate_image ## run shellcheck validation shellcheck: build_shell_validate_image ## run shellcheck validation
docker run -ti --rm $(ENVVARS) $(MOUNTS) $(VALIDATE_IMAGE_NAME) make shellcheck $(DOCKER_RUN) -it $(VALIDATE_IMAGE_NAME) make shellcheck
.PHONY: test-e2e .PHONY: test-e2e
test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e-connhelper-ssh ## run all e2e tests test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e-connhelper-ssh ## run all e2e tests