-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
111 lines (91 loc) · 3.52 KB
/
Copy pathMakefile
File metadata and controls
111 lines (91 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
ifndef $(GOPATH)
GOPATH=$(shell go env GOPATH)
export GOPATH
endif
APP_TAGS ?= ""
BUILD_GOOS ?= linux
BUILD_GOARCH ?= amd64
BUILD_CGO_ENABLED ?= 0
DOCKER_BUILDKIT ?= 1
DOCKER_CONTAINER_IMAGE="demdxx/udetect-server-example:latest"
COMMIT_NUMBER ?= $(shell git rev-parse --short HEAD)
BUILD_VERSION ?= $(shell git describe --exact-match --tags $(git log -n1 --pretty='%h'))
OS_LIST = linux darwin
ARCH_LIST = amd64 arm64
ifeq ($(BUILD_VERSION),)
BUILD_VERSION := commit-$(COMMIT_NUMBER)
endif
.PHONY: lint
lint: golint ## Run linter checks
.PHONY: tidy
tidy: ## Run go mod tidy
go mod tidy
.PHONY: test
test: ## Run unit tests
go test -v -race ./...
.PHONY: golint
golint: $(GOLANGLINTCI)
# golint -set_exit_status ./...
golangci-lint run -v ./...
.PHONY: fmt
fmt: ## Run formatting code
@echo "Fix formatting"
@gofmt -w ${GO_FMT_FLAGS} $$(go list -f "{{ .Dir }}" ./...); if [ "$${errors}" != "" ]; then echo "$${errors}"; fi
.PHONY: buf-generate
buf-generate: ## Not use
cd protocol && buf generate
.PHONY: build-proto
build-proto: ## Build protocol objects from protobuf defenition
# go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
# go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-swagger@latest
# go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
# go install github.com/golang/protobuf/protoc-gen-go@latest
# go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
protoc -I. \
-Isubmodules/googleapis \
--go_out . --go_opt paths=source_relative \
--go-grpc_out . --go-grpc_opt paths=source_relative \
--grpc-gateway_out . --grpc-gateway_opt paths=source_relative \
--grpc-gateway_opt logtostderr=true \
--swagger_out=logtostderr=true:. \
protocol/*.proto
.PHONY: init-submodules
init-submodules: ## Init submodules
git submodule update --init --recursive
.PHONY: pull-submodules
pull-submodules: ## Pull submodules
git submodule update --recursive --remote
.PHONY: help
help: ## Print help description
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: build-example
build-example: ## Build example server
@echo "Build example server"
@rm -rf .build/server
cd examples/server/ && \
GOOS=${BUILD_GOOS} GOARCH=${BUILD_GOARCH} CGO_ENABLED=${BUILD_CGO_ENABLED} \
go build -ldflags "-X main.buildDate=`date -u +%Y%m%d.%H%M%S` -X main.buildCommit=${COMMIT_NUMBER} -X main.appVersion=${BUILD_VERSION}" \
-tags ${APP_TAGS} -o "../../.build/server" ./main.go
.PHONY: run-server
run-server: build-example ## Run example server
DOCKER_BUILDKIT=${DOCKER_BUILDKIT} docker compose -f docker/develop/docker-compose.yml run --rm server
.PHONY: build-prod-example
build-prod-example:
@echo "Build server application"
@rm -rf .build/
@cd examples/server/; \
for os in $(OS_LIST); do \
for arch in $(ARCH_LIST); do \
echo "Build $$os/$$arch"; \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=${BUILD_CGO_ENABLED} go build \
-ldflags "-X main.buildDate=`date -u +%Y%m%d.%H%M%S` -X main.buildCommit=${COMMIT_NUMBER} -X main.appVersion=${BUILD_VERSION}" \
-o ../../.build/$$os/$$arch/server ./main.go; \
done \
done
.PHONY: docker-build
docker-build: build-prod-example ## Build docker example server
echo "Build server docker image"
DOCKER_BUILDKIT=${DOCKER_BUILDKIT} docker buildx build \
--push --platform linux/amd64,linux/arm64,darwin/amd64,darwin/arm64 \
-t ${DOCKER_CONTAINER_IMAGE} -f docker/server-example.dockerfile .
.DEFAULT_GOAL := help