Makefile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. ifneq (, $(BUILDX_BIN))
  12. export BUILDX_CMD = $(BUILDX_BIN)
  13. else ifneq (, $(shell docker buildx version))
  14. export BUILDX_CMD = docker buildx
  15. else ifneq (, $(shell which buildx))
  16. export BUILDX_CMD = $(which buildx)
  17. else
  18. $(error "Buildx is required: https://github.com/docker/buildx#installing")
  19. endif
  20. UNAME_S := $(shell uname -s)
  21. ifeq ($(UNAME_S),Linux)
  22. MOBY_DOCKER=/usr/bin/docker
  23. endif
  24. ifeq ($(UNAME_S),Darwin)
  25. MOBY_DOCKER=/Applications/Docker.app/Contents/Resources/bin/docker
  26. endif
  27. BINARY_FOLDER=$(shell pwd)/bin
  28. GIT_TAG?=$(shell git describe --tags --match "v[0-9]*")
  29. TEST_FLAGS?=
  30. E2E_TEST?=
  31. ifeq ($(E2E_TEST),)
  32. else
  33. TEST_FLAGS=-run $(E2E_TEST)
  34. endif
  35. all: compose-plugin
  36. .PHONY: compose-plugin
  37. compose-plugin: ## Compile the compose cli-plugin
  38. $(BUILDX_CMD) bake binary
  39. .PHONY: install
  40. install: compose-plugin
  41. mkdir -p ~/.docker/cli-plugins
  42. install bin/build/docker-compose ~/.docker/cli-plugins/docker-compose
  43. .PHONY: e2e-compose
  44. e2e-compose: ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test
  45. docker compose version
  46. go test $(TEST_FLAGS) -count=1 ./pkg/e2e
  47. .PHONY: e2e-compose-standalone
  48. e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test
  49. docker-compose version
  50. go test $(TEST_FLAGS) -v -count=1 -parallel=1 --tags=standalone ./pkg/e2e
  51. .PHONY: build-and-e2e-compose
  52. build-and-e2e-compose: compose-plugin e2e-compose ## Compile the compose cli-plugin and run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test
  53. .PHONY: build-and-e2e-compose-standalone
  54. build-and-e2e-compose-standalone: compose-plugin e2e-compose-standalone ## Compile the compose cli-plugin and run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test
  55. .PHONY: mocks
  56. mocks:
  57. mockgen -destination pkg/mocks/mock_docker_cli.go -package mocks github.com/docker/cli/cli/command Cli
  58. mockgen -destination pkg/mocks/mock_docker_api.go -package mocks github.com/docker/docker/client APIClient
  59. mockgen -destination pkg/mocks/mock_docker_compose_api.go -package mocks -source=./pkg/api/api.go Service
  60. .PHONY: e2e
  61. e2e: e2e-compose e2e-compose-standalone ## Run end to end local tests in both modes. Set E2E_TEST=TestName to run a single test
  62. .PHONY: build-and-e2e
  63. build-and-e2e: compose-plugin e2e-compose e2e-compose-standalone ## Compile the compose cli-plugin and run end to end local tests in both modes. Set E2E_TEST=TestName to run a single test
  64. .PHONY: cross
  65. cross: ## Compile the CLI for linux, darwin and windows
  66. $(BUILDX_CMD) bake binary
  67. .PHONY: test
  68. test: ## Run unit tests
  69. $(BUILDX_CMD) bake test
  70. .PHONY: cache-clear
  71. cache-clear: ## Clear the builder cache
  72. $(BUILDX_CMD) prune --force --filter type=exec.cachemount --filter=unused-for=24h
  73. .PHONY: lint
  74. lint: ## run linter(s)
  75. $(BUILDX_CMD) bake lint
  76. .PHONY: docs
  77. docs: ## generate documentation
  78. $(eval $@_TMP_OUT := $(shell mktemp -d -t compose-output.XXXXXXXXXX))
  79. $(BUILDX_CMD) bake --set "*.output=type=local,dest=$($@_TMP_OUT)" docs-update
  80. rm -rf ./docs/internal
  81. cp -R "$($@_TMP_OUT)"/out/* ./docs/
  82. rm -rf "$($@_TMP_OUT)"/*
  83. .PHONY: validate-docs
  84. validate-docs: ## validate the doc does not change
  85. $(BUILDX_CMD) bake docs-validate
  86. .PHONY: check-dependencies
  87. check-dependencies: ## check dependency updates
  88. go list -u -m -f '{{if not .Indirect}}{{if .Update}}{{.}}{{end}}{{end}}' all
  89. .PHONY: validate-headers
  90. validate-headers: ## Check license header for all files
  91. $(BUILDX_CMD) bake license-validate
  92. .PHONY: go-mod-tidy
  93. go-mod-tidy: ## Run go mod tidy in a container and output resulting go.mod and go.sum
  94. $(BUILDX_CMD) bake vendor-update
  95. .PHONY: validate-go-mod
  96. validate-go-mod: ## Validate go.mod and go.sum are up-to-date
  97. $(BUILDX_CMD) bake vendor-validate
  98. validate: validate-go-mod validate-headers validate-docs ## Validate sources
  99. pre-commit: validate check-dependencies lint compose-plugin test e2e-compose
  100. help: ## Show help
  101. @echo Please specify a build target. The choices are:
  102. @grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'