105 lines
3.1 KiB
Makefile
105 lines
3.1 KiB
Makefile
.PHONY: help test-race lint sec-scan gci-format db-mysql-init docker-image-build db-mysql-down generate
|
|
|
|
help: ## show how tot use this tools
|
|
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
|
|
|
PROJECT_NAME?=member
|
|
|
|
########
|
|
# test #
|
|
########
|
|
|
|
test-race: ## launch all tests with race detection
|
|
go test ./... -cover -race
|
|
|
|
########
|
|
# lint #
|
|
########
|
|
|
|
lint: ## lints the entire codebase
|
|
@golangci-lint run ./... --config=./.golangci.yaml
|
|
|
|
#######
|
|
# sec #
|
|
#######
|
|
|
|
sec-scan: trivy-scan vuln-scan ## scan for security and vulnerability issues
|
|
|
|
trivy-scan: ## scan for sec issues with trivy (trivy binary needed)
|
|
trivy fs --exit-code 1 --no-progress --severity CRITICAL ./
|
|
|
|
vuln-scan: ## scan for vulnerability issues with govulncheck (govulncheck binary needed)
|
|
govulncheck ./...
|
|
|
|
######
|
|
# db #
|
|
######
|
|
MYSQL_SQL_PATH="./database/migrations/mysql"
|
|
|
|
db-mysql-init:
|
|
@( \
|
|
printf "Enter migrate name: "; read -r MIGRATE_NAME && \
|
|
migrate create -ext sql -dir ${MYSQL_SQL_PATH} $${MIGRATE_NAME} \
|
|
)
|
|
|
|
db-mysql-up:
|
|
@( \
|
|
printf "Enter pass for db: \n"; read -rs DB_PASSWORD && \
|
|
printf "Enter port(3306...): \n"; read -r DB_PORT &&\
|
|
migrate --database "mysql://root:$${DB_PASSWORD}@tcp(localhost:$${DB_PORT})/$(PROJECT_NAME)?charset=utf8&parseTime=True&loc=Local" --path ${MYSQL_SQL_PATH} up \
|
|
)
|
|
|
|
db-mysql-down:
|
|
@( \
|
|
printf "Enter pass for db: \n"; read -s DB_PASSWORD && \
|
|
printf "Enter port(3306...): \n"; read -r DB_PORT &&\
|
|
migrate --database "mysql://root:$${DB_PASSWORD}@tcp(localhost:$${DB_PORT})/$(PROJECT_NAME)?charset=utf8&parseTime=True&loc=Local" --path ${MYSQL_SQL_PATH} down \
|
|
)
|
|
|
|
SQL_FILE_TIMESTAMP=$(shell date '+%Y%m%d%H%M%S')
|
|
|
|
gen-migrate-sql:
|
|
@( \
|
|
printf "Enter file name: "; read -r FILE_NAME; \
|
|
touch database/migrations/mysql/$(SQL_FILE_TIMESTAMP)_$$FILE_NAME.up.sql; \
|
|
touch database/migrations/mysql/$(SQL_FILE_TIMESTAMP)_$$FILE_NAME.down.sql; \
|
|
)
|
|
|
|
###########
|
|
# GCI #
|
|
###########
|
|
gci-format:
|
|
gci write --skip-generated -s standard -s default -s "prefix(yt.com/backend)" -s "prefix($(PROJECT_NAME))" ./
|
|
|
|
#########
|
|
# build #
|
|
#########
|
|
|
|
GitCommit=$(shell git rev-parse HEAD)
|
|
Date=$(shell date -Iseconds)
|
|
|
|
build:
|
|
@( \
|
|
printf "Enter file name: "; read -r VERSION; \
|
|
go build -ldflags "-s -w -X 'main.Version=$$VERSION' -X 'main.Built=$(Date)' -X 'main.GitCommit=$(GitCommit)'" -o ./bin/$(PROJECT_NAME) ./cmd/$(PROJECT_NAME) \
|
|
)
|
|
|
|
docker-image-build:
|
|
docker build \
|
|
-f ./build/Dockerfile \
|
|
-t $(PROJECT_NAME) \
|
|
--platform linux/amd64 \
|
|
--build-arg BUILT=$(Date) \
|
|
--build-arg GIT_COMMIT=$(GitCommit) \
|
|
--ssh default=$$HOME/.ssh/id_rsa \
|
|
./
|
|
|
|
generate:
|
|
@( \
|
|
printf "Generate protobuf .... "; \
|
|
# goctl rpc protoc ./generate/protobuf/member.proto --style=go_zero --go_out=./gen_result/pb --go-grpc_out=./gen_result/pb --zrpc_out=. \
|
|
# printf "Generate docker .... "; \
|
|
# goctl docker --go member.go --exe member --version 1.22 --tz Asia/Taipei --remote code.30cm.net --base gcr.io/distroless/static-debian12
|
|
# goctl model mysql ddl -c yes -s ./generate/database/mysql/20230529020011_account_uid_table.up.sql --style go_zero -d ./internal/model
|
|
|
|
)
|