builder.Makefile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. GOOS?=$(shell go env GOOS)
  12. GOARCH?=$(shell go env GOARCH)
  13. PKG_NAME := github.com/docker/compose-cli
  14. PROTOS=$(shell find cli/server/protos -name \*.proto)
  15. EXTENSION:=
  16. ifeq ($(GOOS),windows)
  17. EXTENSION:=.exe
  18. endif
  19. STATIC_FLAGS=CGO_ENABLED=0
  20. GIT_TAG?=$(shell git describe --tags --match "v[0-9]*")
  21. LDFLAGS="-s -w -X $(PKG_NAME)/internal.Version=${GIT_TAG}"
  22. GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
  23. BINARY?=bin/docker
  24. BINARY_WITH_EXTENSION=$(BINARY)$(EXTENSION)
  25. COMPOSE_BINARY?=bin/docker-compose
  26. COMPOSE_BINARY_WITH_EXTENSION=$(COMPOSE_BINARY)$(EXTENSION)
  27. WORK_DIR:=$(shell mktemp -d)
  28. TAGS:=
  29. ifdef BUILD_TAGS
  30. TAGS=-tags $(BUILD_TAGS)
  31. LINT_TAGS=--build-tags $(BUILD_TAGS)
  32. endif
  33. .PHONY: protos
  34. protos:
  35. protoc -I. --go_out=plugins=grpc,paths=source_relative:. ${PROTOS}
  36. .PHONY: cli
  37. cli:
  38. GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(BINARY_WITH_EXTENSION) ./cli
  39. .PHONY: compose-plugin
  40. compose-plugin:
  41. GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY_WITH_EXTENSION) ./cmd
  42. .PHONY: cross
  43. cross:
  44. GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-amd64 ./cli
  45. GOOS=linux GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-arm64 ./cli
  46. GOOS=linux GOARM=6 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-armv6 ./cli
  47. GOOS=linux GOARM=7 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-armv7 ./cli
  48. GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-darwin-amd64 ./cli
  49. GOOS=darwin GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(BINARY)-darwin-arm64 ./cli
  50. GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-windows-amd64.exe ./cli
  51. .PHONY: cross-compose-plugin
  52. cross-compose-plugin:
  53. GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-amd64 ./cmd
  54. GOOS=linux GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-arm64 ./cmd
  55. GOOS=linux GOARM=6 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv6 ./cmd
  56. GOOS=linux GOARM=7 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv7 ./cmd
  57. GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-darwin-amd64 ./cmd
  58. GOOS=darwin GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-darwin-arm64 ./cmd
  59. GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-windows-amd64.exe ./cmd
  60. .PHONY: test
  61. test:
  62. go test $(TAGS) -cover $(shell go list $(TAGS) ./... | grep -vE 'e2e')
  63. .PHONY: lint
  64. lint:
  65. golangci-lint run $(LINT_TAGS) --timeout 10m0s ./...
  66. .PHONY: import-restrictions
  67. import-restrictions:
  68. import-restrictions --configuration import-restrictions.yaml
  69. .PHONY: check-licese-headers
  70. check-license-headers:
  71. ./scripts/validate/fileheader
  72. .PHONY: check-go-mod
  73. check-go-mod:
  74. ./scripts/validate/check-go-mod
  75. .PHONY: yamldocs
  76. yamldocs:
  77. go run docs/yaml/main/generate.go