Makefile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # Copyright 2020 Docker Compose CLI authors
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. export DOCKER_BUILDKIT=1
  12. UNAME_S := $(shell uname -s)
  13. ifeq ($(UNAME_S),Linux)
  14. MOBY_DOCKER=/usr/bin/docker
  15. endif
  16. ifeq ($(UNAME_S),Darwin)
  17. MOBY_DOCKER=/Applications/Docker.app/Contents/Resources/bin/docker
  18. endif
  19. BINARY_FOLDER=$(shell pwd)/bin
  20. GIT_TAG?=$(shell git describe --tags --match "v[0-9]*")
  21. TEST_FLAGS?=
  22. E2E_TEST?=
  23. ifeq ($(E2E_TEST),)
  24. else
  25. TEST_FLAGS=-run $(E2E_TEST)
  26. endif
  27. all: compose-plugin
  28. .PHONY: compose-plugin
  29. compose-plugin: ## Compile the compose cli-plugin
  30. @docker build . --target compose-plugin \
  31. --platform local \
  32. --build-arg BUILD_TAGS=e2e,kube \
  33. --build-arg GIT_TAG=$(GIT_TAG) \
  34. --output ./bin
  35. .PHONY: e2e-compose
  36. e2e-compose: ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test
  37. docker compose version
  38. go test $(TEST_FLAGS) -count=1 ./pkg/e2e
  39. .PHONY: e2e-compose-standalone
  40. e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test
  41. rm -f /usr/local/bin/docker-compose
  42. cp bin/docker-compose /usr/local/bin
  43. docker-compose version
  44. go test $(TEST_FLAGS) -v -count=1 -parallel=1 --tags=standalone ./pkg/e2e
  45. .PHONY: mocks
  46. mocks:
  47. mockgen -destination pkg/mocks/mock_docker_cli.go -package mocks github.com/docker/cli/cli/command Cli
  48. mockgen -destination pkg/mocks/mock_docker_api.go -package mocks github.com/docker/docker/client APIClient
  49. .PHONY: e2e
  50. e2e: e2e-compose e2e-compose-standalone ## Run end to end local tests in both modes. Set E2E_TEST=TestName to run a single test
  51. .PHONY: cross
  52. cross: ## Compile the CLI for linux, darwin and windows
  53. @docker build . --target cross \
  54. --build-arg BUILD_TAGS \
  55. --build-arg GIT_TAG=$(GIT_TAG) \
  56. --output ./bin \
  57. .PHONY: test
  58. test: ## Run unit tests
  59. @docker build --progress=plain . \
  60. --build-arg BUILD_TAGS=kube \
  61. --build-arg GIT_TAG=$(GIT_TAG) \
  62. --target test
  63. .PHONY: cache-clear
  64. cache-clear: ## Clear the builder cache
  65. @docker builder prune --force --filter type=exec.cachemount --filter=unused-for=24h
  66. .PHONY: lint
  67. lint: ## run linter(s)
  68. @docker build . \
  69. --build-arg BUILD_TAGS=kube,e2e \
  70. --build-arg GIT_TAG=$(GIT_TAG) \
  71. --target lint
  72. .PHONY: docs
  73. docs: ## generate documentation
  74. $(eval $@_TMP_OUT := $(shell mktemp -d -t dockercli-output.XXXXXXXXXX))
  75. docker build . \
  76. --output type=local,dest=$($@_TMP_OUT) \
  77. -f ./docs/docs.Dockerfile \
  78. --target update
  79. rm -rf ./docs/internal
  80. cp -R "$($@_TMP_OUT)"/out/* ./docs/
  81. rm -rf "$($@_TMP_OUT)"/*
  82. .PHONY: validate-docs
  83. validate-docs: ## validate the doc does not change
  84. @docker build . \
  85. -f ./docs/docs.Dockerfile \
  86. --target validate
  87. .PHONY: check-dependencies
  88. check-dependencies: ## check dependency updates
  89. go list -u -m -f '{{if not .Indirect}}{{if .Update}}{{.}}{{end}}{{end}}' all
  90. .PHONY: validate-headers
  91. validate-headers: ## Check license header for all files
  92. @docker build . --target check-license-headers
  93. .PHONY: go-mod-tidy
  94. go-mod-tidy: ## Run go mod tidy in a container and output resulting go.mod and go.sum
  95. @docker build . --target go-mod-tidy --output .
  96. .PHONY: validate-go-mod
  97. validate-go-mod: ## Validate go.mod and go.sum are up-to-date
  98. @docker build . --target check-go-mod
  99. validate: validate-go-mod validate-headers validate-docs ## Validate sources
  100. pre-commit: validate check-dependencies lint compose-plugin test e2e-compose
  101. help: ## Show help
  102. @echo Please specify a build target. The choices are:
  103. @grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'