Makefile 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. DRIVE_PREFIX?=
  16. ifeq ($(OS),Windows_NT)
  17. DETECTED_OS = Windows
  18. DRIVE_PREFIX=C:
  19. else
  20. DETECTED_OS = $(shell uname -s)
  21. endif
  22. ifeq ($(DETECTED_OS),Windows)
  23. BINARY_EXT=.exe
  24. endif
  25. BUILD_FLAGS?=
  26. TEST_FLAGS?=
  27. E2E_TEST?=
  28. ifneq ($(E2E_TEST),)
  29. TEST_FLAGS:=$(TEST_FLAGS) -run '$(E2E_TEST)'
  30. endif
  31. EXCLUDE_E2E_TESTS?=
  32. ifneq ($(EXCLUDE_E2E_TESTS),)
  33. TEST_FLAGS:=$(TEST_FLAGS) -skip '$(EXCLUDE_E2E_TESTS)'
  34. endif
  35. BUILDX_CMD ?= docker buildx
  36. # DESTDIR overrides the output path for binaries and other artifacts
  37. # this is used by docker/docker-ce-packaging for the apt/rpm builds,
  38. # so it's important that the resulting binary ends up EXACTLY at the
  39. # path $DESTDIR/docker-compose when specified.
  40. #
  41. # See https://github.com/docker/docker-ce-packaging/blob/e43fbd37e48fde49d907b9195f23b13537521b94/rpm/SPECS/docker-compose-plugin.spec#L47
  42. #
  43. # By default, all artifacts go to subdirectories under ./bin/ in the
  44. # repo root, e.g. ./bin/build, ./bin/coverage, ./bin/release.
  45. DESTDIR ?=
  46. all: build
  47. .PHONY: build ## Build the compose cli-plugin
  48. build:
  49. GO111MODULE=on go build $(BUILD_FLAGS) -trimpath -tags "$(GO_BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" -o "$(or $(DESTDIR),./bin/build)/docker-compose$(BINARY_EXT)" ./cmd
  50. .PHONY: binary
  51. binary:
  52. $(BUILDX_CMD) bake binary
  53. .PHONY: binary-with-coverage
  54. binary-with-coverage:
  55. $(BUILDX_CMD) bake binary-with-coverage
  56. .PHONY: install
  57. install: binary
  58. mkdir -p ~/.docker/cli-plugins
  59. install $(or $(DESTDIR),./bin/build)/docker-compose ~/.docker/cli-plugins/docker-compose
  60. .PHONY: e2e-compose
  61. e2e-compose: example-provider ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test
  62. go run gotest.tools/gotestsum@latest --format testname --junitfile "/tmp/report/report.xml" -- -v $(TEST_FLAGS) -count=1 ./pkg/e2e
  63. .PHONY: e2e-compose-standalone
  64. e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test
  65. go run gotest.tools/gotestsum@latest --format testname --junitfile "/tmp/report/report.xml" -- $(TEST_FLAGS) -v -count=1 -parallel=1 --tags=standalone ./pkg/e2e
  66. .PHONY: build-and-e2e-compose
  67. 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
  68. .PHONY: build-and-e2e-compose-standalone
  69. 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
  70. .PHONY: example-provider
  71. example-provider: ## build example provider for e2e tests
  72. go build -o bin/build/example-provider docs/examples/provider.go
  73. .PHONY: mocks
  74. mocks:
  75. mockgen --version >/dev/null 2>&1 || go install go.uber.org/mock/[email protected]
  76. mockgen -destination pkg/mocks/mock_docker_cli.go -package mocks github.com/docker/cli/cli/command Cli
  77. mockgen -destination pkg/mocks/mock_docker_api.go -package mocks github.com/docker/docker/client APIClient
  78. mockgen -destination pkg/mocks/mock_docker_compose_api.go -package mocks -source=./pkg/api/api.go Service
  79. .PHONY: e2e
  80. e2e: e2e-compose e2e-compose-standalone ## Run end to end local tests in both modes. Set E2E_TEST=TestName to run a single test
  81. .PHONY: build-and-e2e
  82. 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
  83. .PHONY: cross
  84. cross: ## Compile the CLI for linux, darwin and windows
  85. $(BUILDX_CMD) bake binary-cross
  86. .PHONY: test
  87. test: ## Run unit tests
  88. $(BUILDX_CMD) bake test
  89. .PHONY: cache-clear
  90. cache-clear: ## Clear the builder cache
  91. $(BUILDX_CMD) prune --force --filter type=exec.cachemount --filter=unused-for=24h
  92. .PHONY: lint
  93. lint: ## run linter(s)
  94. $(BUILDX_CMD) bake lint
  95. .PHONY: fmt
  96. fmt:
  97. gofumpt --version >/dev/null 2>&1 || go install mvdan.cc/gofumpt@latest
  98. gofumpt -w .
  99. .PHONY: docs
  100. docs: ## generate documentation
  101. $(eval $@_TMP_OUT := $(shell mktemp -d -t compose-output.XXXXXXXXXX))
  102. $(BUILDX_CMD) bake --set "*.output=type=local,dest=$($@_TMP_OUT)" docs-update
  103. rm -rf ./docs/internal
  104. cp -R "$(DRIVE_PREFIX)$($@_TMP_OUT)"/out/* ./docs/
  105. rm -rf "$(DRIVE_PREFIX)$($@_TMP_OUT)"/*
  106. .PHONY: validate-docs
  107. validate-docs: ## validate the doc does not change
  108. $(BUILDX_CMD) bake docs-validate
  109. .PHONY: check-dependencies
  110. check-dependencies: ## check dependency updates
  111. go list -u -m -f '{{if not .Indirect}}{{if .Update}}{{.}}{{end}}{{end}}' all
  112. .PHONY: validate-headers
  113. validate-headers: ## Check license header for all files
  114. $(BUILDX_CMD) bake license-validate
  115. .PHONY: go-mod-tidy
  116. go-mod-tidy: ## Run go mod tidy in a container and output resulting go.mod and go.sum
  117. $(BUILDX_CMD) bake vendor-update
  118. .PHONY: validate-go-mod
  119. validate-go-mod: ## Validate go.mod and go.sum are up-to-date
  120. $(BUILDX_CMD) bake vendor-validate
  121. validate: validate-go-mod validate-headers validate-docs ## Validate sources
  122. pre-commit: validate check-dependencies lint build test e2e-compose
  123. help: ## Show help
  124. @echo Please specify a build target. The choices are:
  125. @grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'