-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile
139 lines (115 loc) · 3.3 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
TESTS= $(shell go list ./... | grep -v -e gowasm_test -e cmd)
GOPATH= $(shell go env GOPATH)
GOMODCACHE= $(shell go env GOMODCACHE)
# go 1.20 patch
ifeq ($(GOMODCACHE),)
GOMODCACHE := $(shell go env GOPATH)/pkg/mod
endif
COMMIT= $(shell git describe --tags --dirty)
BUILDTIME= $(shell date +"%d %b %Y")
GOBUILD=go build -ldflags '-s -r ./ -X "main.version=${COMMIT}${VARIANT}" -X "main.buildTime=${BUILDTIME}"' -tags patch_runtime
ARCHIVE= $(shell ./deployment/zipname.sh)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
UPX = upx
else
UPX = echo noupx
endif
ifeq ($(UNAME_S),Darwin)
STRIP = echo nostrip
else
STRIP = strip --strip-all
endif
EXE =
ifdef OS
EXE = .exe
endif
BINS=diode$(EXE) config_server$(EXE)
.PHONY: default
default: diode$(EXE)
.PHONY: runtime
runtime:
@./patch_runtime.sh
.PHONY: all
all: $(BINS)
.PHONY: openssl
openssl:
go mod download
bash "$(GOMODCACHE)/github.com/diodechain/[email protected]/install_openssl.sh"
.PHONY: test
test: runtime
go test -race $(TESTS)
.PHONY: windows_test
windows_test: runtime
go test $(TESTS)
.PHONY: ci_test
ci_test: runtime
$(MAKE) test
$(MAKE) diode_race_test
chmod +x ./diode_race_test
./ci_test.sh
.PHONY: format
format: runtime
go fmt ./...
.PHONY: lint
lint: runtime
go vet ./...
cd tools && go install honnef.co/go/tools/cmd/staticcheck@latest
$(GOPATH)/bin/staticcheck -go 1.22 ./...
# Exclude rules from security check:
# G104 (CWE-703): Errors unhandled.
# G108 (CWE-200): Profiling endpoint is automatically exposed on /debug/pprof
# G110 (CWE-409): Potential DoS vulnerability via decompression bomb.
# G112: Potential slowloris attack
# G114: Use of net/http serve function that has no support for setting timeouts
# G204 (CWE-78): Subprocess launched with variable.
# G304 (CWE-22): Potential file inclusion via variable.
# G402 (CWE-295): TLS InsecureSkipVerify set true.
# G404 (CWE-338): Use of weak random number generator (math/rand instead of crypto/rand).
.PHONY: seccheck
seccheck: runtime
if [ ! -f ./gosec ]; \
then \
curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b ./ v2.20.0; \
fi;
./gosec -exclude=G104,G108,G110,G112,G114,G204,G304,G402,G404 -exclude-dir .history ./...
.PHONY: clean
clean:
-rm $(BINS)
go clean -cache
.PHONY: install
install:
$(MAKE) diode
mv diode /usr/local/bin/diode
.PHONY: uninstall
uninstall:
rm -rf /usr/local/bin/diode
dist: diode$(EXE)
mkdir -p dist
cp diode$(EXE) dist/
$(STRIP) dist/diode$(EXE)
$(UPX) --force dist/diode$(EXE)
.PHONY: archive
archive: $(ARCHIVE)
$(ARCHIVE): dist
zip -1 -j $(ARCHIVE) dist/*
.PHONY: gateway
gateway: diode_debug
scp -C diode_debug [email protected]:diode_go_client
ssh [email protected] 'svc -k .'
.PHONY: diode$(EXE)
diode$(EXE): runtime
$(GOBUILD) -o diode$(EXE) cmd/diode/*.go
.PHONY: config_server$(EXE)
config_server$(EXE): runtime
GODEBUG=netdns=go CGO_ENABLED=0 $(GOBUILD) -ldflags "-X main.serverAddress=localhost:1081 -X main.configPath=./.diode.yml" -o config_server$(EXE) cmd/config_server/config_server.go
.PHONY: gauge$(EXE)
gauge$(EXE): runtime
$(GOBUILD) -o gauge$(EXE) cmd/gauge/*.go
.PHONY: diode_race_test
diode_race_test: runtime
$(GOBUILD) -race -o diode_race_test cmd/diode/*.go
.PHONY: debug
diode_debug: VARIANT=-debug
diode_debug: runtime
$(GOBUILD) -gcflags="-N -l" -o diode_debug cmd/diode/*.go