builder.Makefile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 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. WORK_DIR:=$(shell mktemp -d)
  26. TAGS:=
  27. ifdef BUILD_TAGS
  28. TAGS=-tags $(BUILD_TAGS)
  29. LINT_TAGS=--build-tags $(BUILD_TAGS)
  30. endif
  31. TAR_TRANSFORM:=--transform s/packaging/docker/ --transform s/bin/docker/ --transform s/docker-linux-amd64/docker/ --transform s/docker-darwin-amd64/docker/
  32. ifneq ($(findstring bsd,$(shell tar --version)),)
  33. TAR_TRANSFORM=-s /packaging/docker/ -s /bin/docker/ -s /docker-linux-amd64/docker/ -s /docker-darwin-amd64/docker/
  34. endif
  35. all: cli
  36. .PHONY: protos
  37. protos:
  38. protoc -I. --go_out=plugins=grpc,paths=source_relative:. ${PROTOS}
  39. .PHONY: cli
  40. cli:
  41. GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(BINARY_WITH_EXTENSION) ./cli
  42. .PHONY: cross
  43. cross:
  44. GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-amd64 ./cli
  45. GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-darwin-amd64 ./cli
  46. GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-windows-amd64.exe ./cli
  47. .PHONY: test
  48. test:
  49. go test $(TAGS) -cover $(shell go list ./... | grep -vE 'e2e')
  50. .PHONY: lint
  51. lint:
  52. golangci-lint run $(LINT_TAGS) --timeout 10m0s ./...
  53. .PHONY: import-restrictions
  54. import-restrictions:
  55. import-restrictions --configuration import-restrictions.yaml
  56. .PHONY: check-licese-headers
  57. check-license-headers:
  58. ./scripts/validate/fileheader
  59. .PHONY: check-go-mod
  60. check-go-mod:
  61. ./scripts/validate/check-go-mod
  62. .PHONY: package
  63. package: cross
  64. mkdir -p dist
  65. tar -czf dist/docker-linux-amd64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-linux-amd64
  66. tar -czf dist/docker-darwin-amd64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-darwin-amd64
  67. cp $(BINARY)-windows-amd64.exe $(WORK_DIR)/docker.exe
  68. rm -f dist/docker-windows-amd64.zip && zip dist/docker-windows-amd64.zip -j packaging/LICENSE $(WORK_DIR)/docker.exe
  69. rm -r $(WORK_DIR)