Makefile 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. PKG := github.com/docker/compose/v2
  12. VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
  13. GO_LDFLAGS ?= -w -X ${PKG}/internal.Version=${VERSION}
  14. GO_BUILDTAGS ?= e2e
  15. ifeq ($(OS),Windows_NT)
  16. DETECTED_OS = Windows
  17. else
  18. DETECTED_OS = $(shell uname -s)
  19. endif
  20. ifeq ($(DETECTED_OS),Linux)
  21. MOBY_DOCKER=/usr/bin/docker
  22. endif
  23. ifeq ($(DETECTED_OS),Darwin)
  24. MOBY_DOCKER=/Applications/Docker.app/Contents/Resources/bin/docker
  25. endif
  26. ifeq ($(DETECTED_OS),Windows)
  27. BINARY_EXT=.exe
  28. endif
  29. TEST_COVERAGE_FLAGS = -coverprofile=coverage.out -covermode=atomic
  30. ifneq ($(DETECTED_OS),Windows)
  31. # go race detector requires gcc on Windows so not used by default
  32. # https://github.com/golang/go/issues/27089
  33. TEST_COVERAGE_FLAGS += -race
  34. endif
  35. BUILD_FLAGS?=
  36. TEST_FLAGS?=
  37. E2E_TEST?=
  38. ifeq ($(E2E_TEST),)
  39. else
  40. TEST_FLAGS=-run $(E2E_TEST)
  41. endif
  42. BUILDX_CMD ?= docker buildx
  43. DESTDIR ?= ./bin/build
  44. all: build
  45. .PHONY: build ## Build the compose cli-plugin
  46. build:
  47. GO111MODULE=on go build $(BUILD_FLAGS) -trimpath -tags "$(GO_BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" -o "$(DESTDIR)/docker-compose$(BINARY_EXT)" ./cmd
  48. .PHONY: binary
  49. binary:
  50. $(BUILDX_CMD) bake binary
  51. .PHONY: binary-with-coverage
  52. binary-with-coverage:
  53. $(BUILDX_CMD) bake binary-with-coverage
  54. .PHONY: install
  55. install: binary
  56. mkdir -p ~/.docker/cli-plugins
  57. install bin/build/docker-compose ~/.docker/cli-plugins/docker-compose
  58. .PHONY: e2e-compose
  59. e2e-compose: ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test
  60. rm -rf covdatafiles
  61. mkdir covdatafiles
  62. GOCOVERDIR=covdatafiles go test $(TEST_FLAGS) -count=1 ./pkg/e2e
  63. go tool covdata textfmt -i=covdatafiles -o=coverage.out
  64. .PHONY: e2e-compose-standalone
  65. e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test
  66. go test $(TEST_FLAGS) -v -count=1 -parallel=1 --tags=standalone ./pkg/e2e
  67. .PHONY: test-cucumber
  68. test-cucumber:
  69. go test $(TEST_FLAGS) -v -count=1 -parallel=1 ./e2e
  70. .PHONY: build-and-e2e-compose
  71. build-and-e2e-compose: build 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
  72. .PHONY: build-and-e2e-compose-standalone
  73. build-and-e2e-compose-standalone: build 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
  74. .PHONY: mocks
  75. mocks:
  76. mockgen --version >/dev/null 2>&1 || go install github.com/golang/mock/[email protected]
  77. mockgen -destination pkg/mocks/mock_docker_cli.go -package mocks github.com/docker/cli/cli/command Cli
  78. mockgen -destination pkg/mocks/mock_docker_api.go -package mocks github.com/docker/docker/client APIClient
  79. mockgen -destination pkg/mocks/mock_docker_compose_api.go -package mocks -source=./pkg/api/api.go Service
  80. .PHONY: e2e
  81. e2e: e2e-compose e2e-compose-standalone ## Run end to end local tests in both modes. Set E2E_TEST=TestName to run a single test
  82. .PHONY: build-and-e2e
  83. build-and-e2e: build 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
  84. .PHONY: cross
  85. cross: ## Compile the CLI for linux, darwin and windows
  86. $(BUILDX_CMD) bake binary-cross
  87. .PHONY: test
  88. test: ## Run unit tests
  89. $(BUILDX_CMD) bake test
  90. .PHONY: cache-clear
  91. cache-clear: ## Clear the builder cache
  92. $(BUILDX_CMD) prune --force --filter type=exec.cachemount --filter=unused-for=24h
  93. .PHONY: lint
  94. lint: ## run linter(s)
  95. $(BUILDX_CMD) bake lint
  96. .PHONY: docs
  97. docs: ## generate documentation
  98. $(eval $@_TMP_OUT := $(shell mktemp -d -t compose-output.XXXXXXXXXX))
  99. $(BUILDX_CMD) bake --set "*.output=type=local,dest=$($@_TMP_OUT)" docs-update
  100. rm -rf ./docs/internal
  101. cp -R "$($@_TMP_OUT)"/out/* ./docs/
  102. rm -rf "$($@_TMP_OUT)"/*
  103. .PHONY: validate-docs
  104. validate-docs: ## validate the doc does not change
  105. $(BUILDX_CMD) bake docs-validate
  106. .PHONY: check-dependencies
  107. check-dependencies: ## check dependency updates
  108. go list -u -m -f '{{if not .Indirect}}{{if .Update}}{{.}}{{end}}{{end}}' all
  109. .PHONY: validate-headers
  110. validate-headers: ## Check license header for all files
  111. $(BUILDX_CMD) bake license-validate
  112. .PHONY: go-mod-tidy
  113. go-mod-tidy: ## Run go mod tidy in a container and output resulting go.mod and go.sum
  114. $(BUILDX_CMD) bake vendor-update
  115. .PHONY: validate-go-mod
  116. validate-go-mod: ## Validate go.mod and go.sum are up-to-date
  117. $(BUILDX_CMD) bake vendor-validate
  118. validate: validate-go-mod validate-headers validate-docs ## Validate sources
  119. pre-commit: validate check-dependencies lint build test e2e-compose
  120. help: ## Show help
  121. @echo Please specify a build target. The choices are:
  122. @grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'