-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
108 lines (83 loc) · 3.85 KB
/
Makefile
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
.PHONY: clean run build install dep test lint format docker
SHELL := /bin/bash
PATHINSTBIN = $(abspath ./bin)
export PATH := $(PATHINSTBIN):$(PATH)
BIN_NAME ?= fetch-api
DEFAULT_INSTALL_DIR := $(go env GOPATH)/$(PATHINSTBIN)
DEFAULT_ARCH := $(shell go env GOARCH)
DEFAULT_GOOS := $(shell go env GOOS)
ARCH ?= $(DEFAULT_ARCH)
GOOS ?= $(DEFAULT_GOOS)
INSTALL_DIR ?= $(DEFAULT_INSTALL_DIR)
.DEFAULT_GOAL := run
# Dependency versions
GOLANGCI_VERSION = latest
SWAGGO_VERSION = $(shell go list -m -f '{{.Version}}' github.com/swaggo/swag)
PROTOC_VERSION = 28.3
PROTOC_GEN_GO_VERSION = $(shell go list -m -f '{{.Version}}' google.golang.org/protobuf)
PROTOC_GEN_GO_GRPC_VERSION = v1.5.1
help:
@echo "\nSpecify a subcommand:\n"
@grep -hE '^[0-9a-zA-Z_-]+:.*?## .*$$' ${MAKEFILE_LIST} | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[0;36m%-20s\033[m %s\n", $$1, $$2}'
@echo ""
build: ## Build the binary
@CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) \
go build -o $(PATHINSTBIN)/$(BIN_NAME) ./cmd/$(BIN_NAME)
run: build ## Run the binary
@./$(PATHINSTBIN)/$(BIN_NAME)
all: clean target
clean: ## Clean all build artifacts
@rm -rf $(PATHINSTBIN)
install: build ## Install the binary
@install -d $(INSTALL_DIR)
@rm -f $(INSTALL_DIR)/$(BIN_NAME)
@cp $(PATHINSTBIN)/$(BIN_NAME) $(INSTALL_DIR)/$(BIN_NAME)
tidy: ## Tidy go modules
@go mod tidy
test: ## Run tests
@go test ./...
lint: ## Run linter
@golangci-lint run
format: ## Format code
@golangci-lint run --fix
docker: dep ## Build docker image
@docker build -f ./Dockerfile . -t dimozone/$(BIN_NAME):$(VER_CUT)
@docker tag dimozone/$(BIN_NAME):$(VER_CUT) dimozone/$(BIN_NAME):latest
tools-protoc:
@mkdir -p $(PATHINSTBIN)
ifeq ($(shell uname | tr A-Z a-z), darwin)
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-osx-x86_64.zip > bin/protoc.zip
endif
ifeq ($(shell uname | tr A-Z a-z), linux)
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip > bin/protoc.zip
endif
unzip -o $(PATHINSTBIN)/protoc.zip -d $(PATHINSTBIN)/protoclib
mv -f $(PATHINSTBIN)/protoclib/bin/protoc $(PATHINSTBIN)/protoc
rm -rf $(PATHINSTBIN)/include
mv $(PATHINSTBIN)/protoclib/include $(PATHINSTBIN)/
rm $(PATHINSTBIN)/protoc.zip
tools-protoc-gen-go:
@mkdir -p bin
curl -L https://github.com/protocolbuffers/protobuf-go/releases/download/${PROTOC_GEN_GO_VERSION}/protoc-gen-go.${PROTOC_GEN_GO_VERSION}.$(shell uname | tr A-Z a-z).amd64.tar.gz | tar -zOxf - protoc-gen-go > ./bin/protoc-gen-go
@chmod +x ./bin/protoc-gen-go
tools-protoc-gen-go-grpc:
@mkdir -p bin
curl -L https://github.com/grpc/grpc-go/releases/download/cmd/protoc-gen-go-grpc/${PROTOC_GEN_GO_GRPC_VERSION}/protoc-gen-go-grpc.${PROTOC_GEN_GO_GRPC_VERSION}.$(shell uname | tr A-Z a-z).amd64.tar.gz | tar -zOxf - ./protoc-gen-go-grpc > ./bin/protoc-gen-go-grpc
@chmod +x ./bin/protoc-gen-go-grpc
tools-golangci-lint: ## Install golangci-lint
@mkdir -p $(PATHINSTBIN)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | BINARY=golangci-lint bash -s -- ${GOLANGCI_VERSION}
tools-swagger: ## install swagger tool
@mkdir -p $(PATHINSTBIN)
GOBIN=$(PATHINSTBIN) go install github.com/swaggo/swag/cmd/swag@$(SWAGGO_VERSION)
tools: tools-golangci-lint tools-swagger tools-protoc tools-protoc-gen-go tools-protoc-gen-go-grpc ## Install all tools
generate: go-generate generate-grpc generate-swagger ## run all file generation for the project
go-generate:## run go generate
@go generate ./...
generate-grpc:
@protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
pkg/grpc/*.proto
generate-swagger: ## generate swagger documentation
@swag -version
swag init -g cmd/fetch-api/main.go --parseDependency --parseInternal