builder.Makefile 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. PROTOS=$(shell find protos -name \*.proto)
  14. EXTENSION:=
  15. ifeq ($(GOOS),windows)
  16. EXTENSION:=.exe
  17. endif
  18. STATIC_FLAGS=CGO_ENABLED=0
  19. GIT_TAG?=$(shell git describe --tags --match "v[0-9]*")
  20. LDFLAGS="-s -w -X main.version=${GIT_TAG}"
  21. GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
  22. BINARY?=bin/docker
  23. BINARY_WITH_EXTENSION=$(BINARY)$(EXTENSION)
  24. TAGS:=
  25. ifdef BUILD_TAGS
  26. TAGS=-tags $(BUILD_TAGS)
  27. endif
  28. TAR_TRANSFORM:=--transform s/packaging/docker/ --transform s/bin/docker/
  29. ifneq ($(findstring bsd,$(shell tar --version)),)
  30. TAR_TRANSFORM=-s /packaging/docker/ -s /bin/docker/
  31. endif
  32. all: cli
  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: cross
  40. cross:
  41. GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-amd64 ./cli
  42. GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-darwin-amd64 ./cli
  43. GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-windows-amd64.exe ./cli
  44. .PHONY: test
  45. test:
  46. go test $(TAGS) -cover $(shell go list ./... | grep -vE 'e2e')
  47. .PHONY: lint
  48. lint:
  49. golangci-lint run --timeout 10m0s ./...
  50. .PHONY: import-restrictions
  51. import-restrictions:
  52. import-restrictions --configuration import-restrictions.yaml
  53. .PHONY: check-licese-headers
  54. check-license-headers:
  55. ./scripts/validate/fileheader
  56. .PHONY: check-go-mod
  57. check-go-mod:
  58. ./scripts/validate/check-go-mod
  59. .PHONY: package
  60. package: cross
  61. mkdir -p dist
  62. tar -czf dist/docker-linux-amd64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-linux-amd64
  63. tar -czf dist/docker-darwin-amd64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-darwin-amd64
  64. rm -f dist/docker-windows-amd64.zip && zip dist/docker-windows-amd64.zip -j packaging/LICENSE $(BINARY)-windows-amd64.exe