BUILD_TIME := $(shell date "+%F %T") COMMIT_SHA1 := $(shell git rev-parse HEAD ) # 版本手动指定 VERSION=v2.0.0 LDFLAGS := -ldflags "-X 'registration-service/internal.BuildTime=${BUILD_TIME}' -X 'registration-service/internal.CommitID=${COMMIT_SHA1}' -X 'registration-service/internal.Version=${VERSION}'" SOURCE := ./registration.go BUILD_NAME := registration-service IMAGE=192.168.1.181:5000/ida/assets-registration REV=$(shell git rev-parse --short HEAD) REPO=${IMAGE}-${REV}:${VERSION} TAG=docker.oa.com:5000/chainweaver/ida-registration:${VERSION} TAG2=192.168.1.181:5000/chainweaver/ida-registration:${VERSION} .PHONY:gen-code start-service build gen-code: @sh ./scripts/generate_code.sh registration-service registration registrationpb #gen-code: # # # 先生成 go-zero 的基础代码,此时可能只包含部分 grpc pb、service 定义文件 # # goctl rpc 工具一次只能读取一个 proto 文件,不要用 *.proto(go-zero 的 cli flag 会将 * 识别成多个文件参数,报错了) # goctl rpc protoc --go_out=./internal/types --go-grpc_out=./internal/types --zrpc_out=. ./proto/registration.proto # # # 再用原生 protoc 生成所有的 grpc pb、service 定义文件 # protoc --go_out=./internal/types --go-grpc_out=./internal/types ./proto/*.proto start-service: go run ./registration.go build: go build ${LDFLAGS} -o ${BUILD_NAME} ./registration.go build-docker: # 1. 安装下载modvendor程序 go install github.com/goware/modvendor@v0.5.0 # 2. 将依赖包导入到自己的项目根目录下 GO111MODULE=on go mod vendor # 3. 使用modvendor将vendor下第三方依赖的.c/.h/.a文件copy到vendor对应目录下 modvendor -copy="**/*.c **/*.h **/*.a" -v docker build -t ${REPO} -f ./docker/Dockerfile . docker tag ${REPO} ${TAG} docker tag ${REPO} ${TAG2} gen-cert: bash ./scripts/generate_cert.sh ./cert ut: go test -coverprofile cover.out ./... cd scripts && ./ut_cover.sh # go test -coverprofile cover.out ./... # go tool cover -func=cover.out | tail -1 | grep -P '\d+\.\d+(?=\%)' -o