-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMakefile
70 lines (54 loc) · 2.9 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
.PHONY : prepare build run
$(eval $(service):;@:)
check:
@[ "${service}" ] || ( echo "\x1b[31;1mERROR: 'service' is not set\x1b[0m"; exit 1 )
@if [ ! -d "services/$(service)" ]; then echo "\x1b[31;1mERROR: service '$(service)' undefined\x1b[0m"; exit 1; fi
prepare: check
@if [ ! -f services/$(service)/.env ]; then cp services/$(service)/.env.sample services/$(service)/.env; fi;
init:
@candi -scope=4
add-module: check
@candi -scope=5 -servicename=$(service)
build: check
@go build -o services/$(service)/bin services/$(service)/*.go
run: build
@WORKDIR="services/$(service)/" ./services/$(service)/bin
proto: check
@if [ ! -d "sdk/$(service)" ]; then echo "creating new proto files..." && mkdir sdk/$(service) && mkdir sdk/$(service)/proto; fi
$(foreach proto_file, $(shell find services/$(service)/api/proto -name '*.proto'),\
protoc --proto_path=services/$(service)/api/proto --go_out=plugins=grpc:sdk/$(service)/proto \
--go_opt=paths=source_relative $(proto_file);)
migration: check
@WORKDIR="services/$(service)/" go run services/$(service)/cmd/migration/*.go
docker: check
docker build --build-arg SERVICE_NAME=$(service) -t $(service):latest .
run-container: check
docker run --name=$(service) --network="host" -d $(service)
deploy: check
@[ "${level}" ] || ( echo "\x1b[31;1mERROR: 'level' is not set\x1b[0m" ; exit 1 )
# kubectl create configmap $(level)-$(service)-env --from-file services/$(service)/.env --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -f services/$(service)/deployments/k8s/$(level)-$(service).yaml
# mocks all interfaces in sdk for unit test
mocks:
@mockery --all --keeptree --dir=sdk --output=./sdk/mocks
@if [ -f sdk/mocks/Option.go ]; then rm sdk/mocks/Option.go; fi;
# unit test & calculate code coverage from selected service (please run mocks before run this rule)
test: check
@echo "\x1b[32;1m>>> running unit test and calculate coverage for service $(service)\x1b[0m"
@if [ -f services/$(service)/coverage.txt ]; then rm services/$(service)/coverage.txt; fi;
@go test -race ./services/$(service)/... -cover -coverprofile=services/$(service)/coverage.txt -covermode=atomic \
-coverpkg=$$(go list ./services/$(service)/... | grep -v -e mocks -e codebase | tr '\n' ',')
@go tool cover -func=services/$(service)/coverage.txt
sonar: check
@echo "\x1b[32;1m>>> running sonar scanner for service $(service)\x1b[0m"
@[ "${level}" ] || ( echo "\x1b[31;1mERROR: 'level' is not set\x1b[0m" ; exit 1 )
@sonar-scanner -Dsonar.projectKey=$(service)-$(level) \
-Dsonar.projectName=$(service)-$(level) \
-Dsonar.sources=./services/$(service) \
-Dsonar.exclusions=**/mocks/**,**/module.go \
-Dsonar.test.inclusions=**/*_test.go \
-Dsonar.test.exclusions=**/mocks/** \
-Dsonar.coverage.exclusions=**/mocks/**,**/*_test.go,**/main.go \
-Dsonar.go.coverage.reportPaths=./services/$(service)/coverage.txt
clear:
rm -rf sdk/mocks services/$(service)/mocks services/$(service)/bin bin