Makefile 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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: cli compose-plugin
  28. protos: ## Generate go code from .proto files
  29. @docker build . --target protos \
  30. --output ./cli/server/protos
  31. cli: ## Compile the cli
  32. @docker build . --target cli \
  33. --platform local \
  34. --build-arg BUILD_TAGS=e2e,kube \
  35. --build-arg GIT_TAG=$(GIT_TAG) \
  36. --output ./bin
  37. compose-plugin: ## Compile the compose cli-plugin
  38. @docker build . --target compose-plugin \
  39. --platform local \
  40. --build-arg BUILD_TAGS=e2e,kube \
  41. --build-arg GIT_TAG=$(GIT_TAG) \
  42. --output ./bin
  43. e2e-compose: ## Run End to end local tests. Set E2E_TEST=TestName to run a single test
  44. gotestsum $(TEST_FLAGS) ./pkg/e2e -- -count=1
  45. e2e-local: ## Run End to end local tests. Set E2E_TEST=TestName to run a single test
  46. gotestsum $(TEST_FLAGS) ./local/e2e/container ./local/e2e/cli-only -- -count=1
  47. e2e-win-ci: ## Run end to end local tests on Windows CI, no Docker for Linux containers available ATM. Set E2E_TEST=TestName to run a single test
  48. go test -count=1 -v $(TEST_FLAGS) ./local/e2e/cli-only
  49. e2e-kube: ## Run End to end Kube tests. Set E2E_TEST=TestName to run a single test
  50. go test -timeout 10m -count=1 -v $(TEST_FLAGS) ./kube/e2e
  51. e2e-aci: ## Run End to end ACI tests. Set E2E_TEST=TestName to run a single test
  52. go test -timeout 15m -count=1 -v $(TEST_FLAGS) ./aci/e2e
  53. e2e-ecs: ## Run End to end ECS tests. Set E2E_TEST=TestName to run a single test
  54. go test -timeout 20m -count=1 -v $(TEST_FLAGS) ./ecs/e2e/ecs ./ecs/e2e/ecs-local
  55. cross: ## Compile the CLI for linux, darwin and windows
  56. @docker build . --target cross \
  57. --build-arg BUILD_TAGS \
  58. --build-arg GIT_TAG=$(GIT_TAG) \
  59. --output ./bin \
  60. test: ## Run unit tests
  61. @docker build --progress=plain . \
  62. --build-arg BUILD_TAGS=kube \
  63. --build-arg GIT_TAG=$(GIT_TAG) \
  64. --target test
  65. cache-clear: ## Clear the builder cache
  66. @docker builder prune --force --filter type=exec.cachemount --filter=unused-for=24h
  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. check-dependencies: ## check dependency updates
  73. go list -u -m -f '{{if not .Indirect}}{{if .Update}}{{.}}{{end}}{{end}}' all
  74. import-restrictions: ## run import-restrictions script
  75. @docker build . \
  76. --target import-restrictions
  77. serve: cli ## start server
  78. @./bin/docker serve --address unix:///tmp/backend.sock
  79. moby-cli-link: ## Create com.docker.cli symlink if does not already exist
  80. ln -s $(MOBY_DOCKER) /usr/local/bin/com.docker.cli
  81. install: ## Link /usr/local/bin/ to current binary
  82. ln -fs $(BINARY_FOLDER)/docker /usr/local/bin/docker
  83. validate-headers: ## Check license header for all files
  84. @docker build . --target check-license-headers
  85. go-mod-tidy: ## Run go mod tidy in a container and output resulting go.mod and go.sum
  86. @docker build . --target go-mod-tidy --output .
  87. validate-go-mod: ## Validate go.mod and go.sum are up-to-date
  88. @docker build . --target check-go-mod
  89. validate: validate-go-mod validate-headers ## Validate sources
  90. pre-commit: validate import-restrictions check-dependencies lint cli test e2e-local
  91. build-aci-sidecar: ## build aci sidecar image locally and tag it with make build-aci-sidecar tag=0.1
  92. docker build -t docker/aci-hostnames-sidecar:$(tag) aci/etchosts
  93. publish-aci-sidecar: build-aci-sidecar ## build & publish aci sidecar image with make publish-aci-sidecar tag=0.1
  94. docker pull docker/aci-hostnames-sidecar:$(tag) && echo "Failure: Tag already exists" || docker push docker/aci-hostnames-sidecar:$(tag)
  95. build-ecs-search-sidecar: ## build ecs search sidecar image locally and tag it with make build-ecs-search-sidecar tag=0.1
  96. docker build -t docker/ecs-searchdomain-sidecar:$(tag) ecs/resolv
  97. publish-ecs-search-sidecar: build-ecs-search-sidecar ## build & publish ecs search sidecar image with make publish-ecs-search-sidecar tag=0.1
  98. docker pull docker/ecs-searchdomain-sidecar:$(tag) && echo "Failure: Tag already exists" || docker push docker/ecs-searchdomain-sidecar:$(tag)
  99. build-ecs-secrets-sidecar: ## build ecs secrets sidecar image locally and tag it with make build-ecs-secrets-sidecar tag=0.1
  100. docker build -t docker/ecs-secrets-sidecar:$(tag) ecs/secrets
  101. publish-ecs-secrets-sidecar: build-ecs-secrets-sidecar ## build & publish ecs secrets sidecar image with make publish-ecs-secrets-sidecar tag=0.1
  102. docker pull docker/ecs-secrets-sidecar:$(tag) && echo "Failure: Tag already exists" || docker push docker/ecs-secrets-sidecar:$(tag)
  103. clean-aci-e2e: ## Make sure no ACI tests are currently runnnig in the CI when invoking this. Delete ACI E2E tests resources that might have leaked when ctrl-C E2E tests.
  104. @ echo "Will delete resource groups: "
  105. @ az group list | jq '.[].name' | grep -i E2E-Test
  106. az group list | jq '.[].name' | grep -i E2E-Test | xargs -n1 az group delete -y --no-wait -g
  107. help: ## Show help
  108. @echo Please specify a build target. The choices are:
  109. @grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
  110. FORCE:
  111. .PHONY: all validate protos cli e2e-local cross test cache-clear lint check-dependencies serve classic-link help clean-aci-e2e go-mod-tidy