sponge/Makefile

171 lines
4.4 KiB
Makefile
Raw Normal View History

2022-09-19 23:24:11 +08:00
SHELL := /bin/bash
PROJECT_NAME := "github.com/zhufuyi/sponge"
PKG := "$(PROJECT_NAME)"
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go)
2022-10-07 22:50:45 +08:00
.PHONY: install
2022-09-27 22:30:59 +08:00
# installation of dependent tools
2022-10-07 22:50:45 +08:00
install:
2022-09-19 23:24:11 +08:00
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.0
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0
2022-10-01 20:28:41 +08:00
go install github.com/envoyproxy/protoc-gen-validate@v0.6.7
2022-09-19 23:24:11 +08:00
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.10.0
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@v2.10.0
go install github.com/mohuishou/protoc-gen-go-gin@v0.1.0
go install github.com/srikrsna/protoc-gen-gotag@v0.6.2
go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@v1.5.1
go install github.com/golang/mock/mockgen@v1.6.0
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.49.0
go install github.com/swaggo/swag/cmd/swag@v1.8.6
go install github.com/ofabry/go-callvis@v0.6.1
2022-10-07 22:50:45 +08:00
go install golang.org/x/pkgsite/cmd/pkgsite@latest
.PHONY: mod
# add missing and remove unused modules
mod:
go mod tidy
2022-09-19 23:24:11 +08:00
2022-09-30 23:39:37 +08:00
.PHONY: fmt
# go format *.go files
fmt:
2022-10-07 22:50:45 +08:00
gofmt -s -w .
2022-09-30 23:39:37 +08:00
2022-09-19 23:24:11 +08:00
.PHONY: ci-lint
2022-09-27 22:30:59 +08:00
# check the code specification against the rules in the .golangci.yml file
2022-10-07 22:50:45 +08:00
ci-lint: fmt
2022-09-19 23:24:11 +08:00
golangci-lint run ./...
.PHONY: dep
2022-09-27 22:30:59 +08:00
# download dependencies to the directory vendor
2022-09-19 23:24:11 +08:00
dep:
2022-10-07 22:50:45 +08:00
go mod download
2022-09-19 23:24:11 +08:00
.PHONY: test
2022-10-07 22:50:45 +08:00
# go test *_test.go files, the parameter -count=1 means that caching is disabled
2022-09-19 23:24:11 +08:00
test:
2022-10-07 22:50:45 +08:00
go test -count=1 -short ${PKG_LIST}
2022-09-19 23:24:11 +08:00
.PHONY: cover
2022-09-27 22:30:59 +08:00
# generate test coverage
2022-09-19 23:24:11 +08:00
cover:
2022-09-27 22:30:59 +08:00
go test -short -coverprofile cover.out -covermode=atomic ${PKG_LIST}
go tool cover -html=cover.out
2022-09-19 23:24:11 +08:00
2022-09-30 23:39:37 +08:00
.PHONY: build
# go build the linux amd64 binary file
build:
@cd cmd/serverNameExample && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOPROXY=https://goproxy.cn,direct go build -gcflags "all=-N -l"
@echo "build finished, binary file in path 'cmd/serverNameExample'"
.PHONY: run
# run server
run:
@bash scripts/run.sh
.PHONY: docker-image
2022-10-01 20:28:41 +08:00
# build docker image, use binary files to build
docker-image: build
@bash scripts/grpc_health_probe.sh
@mv -f cmd/serverNameExample/serverNameExample build/
@mkdir -p build/configs && cp -f configs/serverNameExample.yml build/configs/
docker build -t project-name-example.server-name-example:latest build/
@rm -rf build/serverNameExample build/configs build/grpc_health_probe
2022-09-27 22:30:59 +08:00
2022-09-30 23:39:37 +08:00
.PHONY: image-build
2022-10-07 22:50:45 +08:00
# build docker image with parameters, use binary files to build, e.g. make image-build REPO_HOST=addr TAG=latest
2022-10-01 20:28:41 +08:00
image-build:
2022-09-30 23:39:37 +08:00
@bash scripts/image-build.sh $(REPO_HOST) $(TAG)
2022-10-01 20:28:41 +08:00
.PHONY: image-build2
2022-10-07 22:50:45 +08:00
# build docker image with parameters, phase II build, e.g. make image-build2 REPO_HOST=addr TAG=latest
2022-10-01 20:28:41 +08:00
image-build2:
@bash scripts/image-build2.sh $(REPO_HOST) $(TAG)
2022-09-30 23:39:37 +08:00
.PHONY: image-push
2022-10-07 22:50:45 +08:00
# push docker image to remote repositories, e.g. make image-push REPO_HOST=addr TAG=latest
2022-09-30 23:39:37 +08:00
image-push:
@bash scripts/image-push.sh $(REPO_HOST) $(TAG)
.PHONY: deploy-k8s
# deploy service to k8s
deploy-k8s:
@bash scripts/deploy-k8s.sh
2022-09-19 23:24:11 +08:00
2022-10-07 22:50:45 +08:00
.PHONY: deploy-docker
# deploy service to docker
deploy-docker:
@bash scripts/deploy-docker.sh
2022-09-19 23:24:11 +08:00
.PHONY: clean
2022-09-27 22:30:59 +08:00
# clean binary file, cover.out, redundant dependency packages
2022-09-19 23:24:11 +08:00
clean:
2022-09-29 23:32:03 +08:00
@rm -vrf cmd/serverNameExample/serverNameExample
2022-09-27 22:30:59 +08:00
@rm -vrf cover.out
2022-10-07 22:50:45 +08:00
go mod tidy
2022-09-19 23:24:11 +08:00
@echo "clean finished"
.PHONY: docs
2022-10-07 22:50:45 +08:00
# generate swagger docs, the host address can be changed via parameters, e.g. make docs HOST=192.168.3.37
2022-09-19 23:24:11 +08:00
docs:
2022-10-07 22:50:45 +08:00
@bash scripts/swag-docs.sh $(HOST)
2022-09-19 23:24:11 +08:00
.PHONY: graph
2022-09-27 22:30:59 +08:00
# generate interactive visual function dependency graphs
2022-09-19 23:24:11 +08:00
graph:
@echo "generating graph ......"
2022-10-07 22:50:45 +08:00
@cp -f cmd/serverNameExample/main.go .
go-callvis -skipbrowser -format=svg -nostd -file=serverNameExample github.com/zhufuyi/sponge
@rm -f main.go serverNameExample.gv
2022-09-19 23:24:11 +08:00
.PHONY: proto
2022-09-27 22:30:59 +08:00
# generate *.pb.go codes from *.proto files
2022-09-19 23:24:11 +08:00
proto:
@bash scripts/protoc.sh
.PHONY: proto-doc
2022-09-27 22:30:59 +08:00
# generate doc from *.proto files
2022-09-19 23:24:11 +08:00
proto-doc:
@bash scripts/proto-doc.sh
# show help
help:
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m %-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := all