sponge/Makefile

215 lines
6.5 KiB
Makefile
Raw Permalink Normal View History

2022-11-02 23:52:22 +08:00
SHELL := /bin/bash
2022-09-19 23:24:11 +08:00
PROJECT_NAME := "github.com/zhufuyi/sponge"
PKG := "$(PROJECT_NAME)"
2022-10-09 22:26:28 +08:00
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/ | grep -v /api/)
2022-09-19 23:24:11 +08:00
2023-09-02 22:18:32 +08:00
# delete the templates code start
2022-10-07 22:50:45 +08:00
.PHONY: install
2024-01-06 16:55:48 +08:00
# installation of dependent plugins
2022-10-07 22:50:45 +08:00
install:
2022-11-03 23:53:59 +08:00
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/envoyproxy/protoc-gen-validate@latest
go install github.com/srikrsna/protoc-gen-gotag@latest
go install github.com/zhufuyi/sponge/cmd/protoc-gen-go-gin@latest
2022-11-19 23:21:58 +08:00
go install github.com/zhufuyi/sponge/cmd/protoc-gen-go-rpc-tmpl@latest
2022-11-03 23:53:59 +08:00
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
2023-09-02 22:18:32 +08:00
go install github.com/swaggo/swag/cmd/swag@v1.8.12
2022-11-03 23:53:59 +08:00
go install github.com/ofabry/go-callvis@latest
2022-10-07 22:50:45 +08:00
go install golang.org/x/pkgsite/cmd/pkgsite@latest
2023-09-02 22:18:32 +08:00
# delete the templates code end
2022-10-07 22:50:45 +08:00
2022-09-30 23:39:37 +08:00
2022-09-19 23:24:11 +08:00
.PHONY: ci-lint
2023-12-15 13:32:33 +08:00
# check code formatting, naming conventions, security, maintainability, etc. the rules in the .golangci.yml file
2024-04-27 15:34:12 +08:00
ci-lint:
@gofmt -s -w .
2022-09-19 23:24:11 +08:00
golangci-lint run ./...
.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:
go test -short -coverprofile=cover.out -covermode=atomic ${PKG_LIST}
2022-09-27 22:30:59 +08:00
go tool cover -html=cover.out
2022-09-19 23:24:11 +08:00
2022-10-17 23:11:21 +08:00
.PHONY: graph
# generate interactive visual function dependency graphs
graph:
@echo "generating graph ......"
2022-11-04 23:32:40 +08:00
@cp -f cmd/serverNameExample_mixExample/main.go .
go-callvis -skipbrowser -format=svg -nostd -file=serverNameExample_mixExample github.com/zhufuyi/sponge
@rm -f main.go serverNameExample_mixExample.gv
2022-10-17 23:11:21 +08:00
2023-12-15 13:32:33 +08:00
# delete the templates code start
2023-09-02 22:18:32 +08:00
.PHONY: docs
2024-04-27 15:34:12 +08:00
# generate swagger docs, only for ⓵ Web services created based on sql
docs:
go mod tidy
@gofmt -s -w .
2023-09-02 22:18:32 +08:00
@bash scripts/swag-docs.sh $(HOST)
2023-12-15 13:32:33 +08:00
# delete the templates code end
2023-09-02 22:18:32 +08:00
2022-10-17 23:11:21 +08:00
.PHONY: proto
2024-04-27 15:34:12 +08:00
# generate *.go and template code by proto files, the default is all the proto files in the api directory. you can specify the proto file, multiple files are separated by commas, e.g. make proto FILES=api/user/v1/user.proto
2024-03-15 00:52:35 +08:00
proto:
2023-09-24 16:56:36 +08:00
@bash scripts/protoc.sh $(FILES)
2024-03-15 00:52:35 +08:00
go mod tidy
@gofmt -s -w .
2022-10-17 23:11:21 +08:00
.PHONY: proto-doc
# generate doc from *.proto files
proto-doc:
@bash scripts/proto-doc.sh
2022-09-30 23:39:37 +08:00
.PHONY: build
2022-11-04 23:32:40 +08:00
# build serverNameExample_mixExample for linux amd64 binary
2022-09-30 23:39:37 +08:00
build:
2023-03-11 19:24:49 +08:00
@echo "building 'serverNameExample_mixExample', linux binary file will output to 'cmd/serverNameExample_mixExample'"
2023-09-02 22:18:32 +08:00
@cd cmd/serverNameExample_mixExample && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
2022-10-17 23:11:21 +08:00
2022-10-20 23:44:41 +08:00
# delete the templates code start
2023-09-02 22:18:32 +08:00
2022-10-17 23:11:21 +08:00
.PHONY: build-sponge
# build sponge for linux amd64 binary
build-sponge:
2023-03-11 19:24:49 +08:00
@echo "building 'sponge', linux binary file will output to 'cmd/sponge'"
2023-09-02 22:18:32 +08:00
@cd cmd/sponge && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "all=-s -w"
2022-09-30 23:39:37 +08:00
2023-12-02 16:41:49 +08:00
.PHONY: image-build-sponge
# build a sponge docker image, e.g. make image-build-sponge TAG=v1.5.8
image-build-sponge:
@echo "build a sponge docker image'"
2023-12-09 22:14:23 +08:00
@cd cmd/sponge/scripts && bash build-sponge-image.sh $(TAG)
2023-12-02 16:41:49 +08:00
2023-09-02 22:18:32 +08:00
# delete the templates code end
2023-02-19 17:19:47 +08:00
2022-09-30 23:39:37 +08:00
.PHONY: run
2024-04-27 15:34:12 +08:00
# build and run service
2022-09-30 23:39:37 +08:00
run:
@bash scripts/run.sh
2023-03-25 15:18:36 +08:00
2023-02-19 17:19:47 +08:00
.PHONY: run-nohup
2023-12-15 13:32:33 +08:00
# run service with nohup in local, if you want to stop the server, pass the parameter stop, e.g. make run-nohup CMD=stop
2023-02-19 17:19:47 +08:00
run-nohup:
2023-03-25 15:18:36 +08:00
@bash scripts/run-nohup.sh $(CMD)
2023-02-19 17:19:47 +08:00
2022-09-30 23:39:37 +08:00
2023-12-15 13:32:33 +08:00
.PHONY: run-docker
# run service in local docker, if you want to update the service, run the make run-docker command again.
run-docker: image-build-local
@bash scripts/deploy-docker.sh
2023-09-02 22:18:32 +08:00
.PHONY: binary-package
# packaged binary files
binary-package: build
@bash scripts/binary-package.sh
.PHONY: deploy-binary
# deploy binary to remote linux server, e.g. make deploy-binary USER=root PWD=123456 IP=192.168.1.10
deploy-binary: binary-package
@expect scripts/deploy-binary.sh $(USER) $(PWD) $(IP)
.PHONY: image-build-local
2023-03-25 15:18:36 +08:00
# build image for local docker, tag=latest, use binary files to build
2023-09-02 22:18:32 +08:00
image-build-local: build
2023-03-25 15:18:36 +08:00
@bash scripts/image-build-local.sh
2022-09-27 22:30:59 +08:00
2022-09-30 23:39:37 +08:00
.PHONY: image-build
2023-03-25 15:18:36 +08:00
# build image for remote repositories, 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
2023-03-25 15:18:36 +08:00
# build image for remote repositories, 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
2023-09-02 22:18:32 +08:00
.PHONY: image-build-rpc-test
2023-11-04 16:23:24 +08:00
# build grpc test image for remote repositories, e.g. make image-build-rpc-test REPO_HOST=addr TAG=latest
2023-09-02 22:18:32 +08:00
image-build-rpc-test:
@bash scripts/image-rpc-test.sh $(REPO_HOST) $(TAG)
2023-03-11 19:24:49 +08:00
.PHONY: patch
2024-04-27 15:34:12 +08:00
# patch some dependent code, e.g. make patch TYPE=types-pb , make patch TYPE=init-your_db_driver, replace "your_db_driver" with mysql, mongodb, postgresql, tidb, sqlite
patch:
@bash scripts/patch.sh $(TYPE)
2023-08-29 22:15:02 +08:00
.PHONY: copy-proto
2024-04-27 15:34:12 +08:00
# copy proto file from the grpc server directory, multiple directories or proto files separated by commas. default is to copy all proto files, e.g. make copy-proto SERVER=yourServerDir, copy specified proto files, e.g. make copy-proto SERVER=yourServerDir PROTO_FILE=yourProtoFile1,yourProtoFile2
2023-08-29 22:15:02 +08:00
copy-proto:
2023-12-15 13:32:33 +08:00
@sponge patch copy-proto --server-dir=$(SERVER) --proto-file=$(PROTO_FILE)
2023-09-07 22:22:10 +08:00
.PHONY: update-config
# update internal/config code base on yaml file
update-config:
@sponge config --server-dir=.
2023-08-29 22:15:02 +08:00
2022-09-19 23:24:11 +08:00
.PHONY: clean
2023-03-03 21:05:25 +08:00
# clean binary file, cover.out, template file
2022-09-19 23:24:11 +08:00
clean:
2023-12-15 22:04:06 +08:00
@rm -vrf cmd/serverNameExample_mixExample/serverNameExample_mixExample*
2022-09-27 22:30:59 +08:00
@rm -vrf cover.out
2023-03-03 21:05:25 +08:00
@rm -vrf main.go serverNameExample_mixExample.gv
2023-09-02 22:18:32 +08:00
@rm -vrf internal/ecode/*.go.gen*
@rm -vrf internal/routers/*.go.gen*
@rm -vrf internal/handler/*.go.gen*
@rm -vrf internal/service/*.go.gen*
2023-03-11 19:24:49 +08:00
@rm -rf serverNameExample-binary.tar.gz
2022-09-19 23:24:11 +08:00
@echo "clean finished"
# show help
help:
@echo ''
@echo 'Usage:'
2024-04-27 15:34:12 +08:00
@echo ' make <target>'
2022-09-19 23:24:11 +08:00
@echo ''
@echo 'Targets:'
2023-09-17 10:54:42 +08:00
@awk '/^[a-zA-Z\-_0-9]+:/ { \
2022-09-19 23:24:11 +08:00
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
2024-03-31 15:29:28 +08:00
printf "\033[1;36m %-22s\033[0m %s\n", helpCommand,helpMessage; \
2022-09-19 23:24:11 +08:00
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := all