-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile.example
229 lines (190 loc) · 9.15 KB
/
Makefile.example
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# Makefile example.
# Check the installation manual about the changes needed before using it
SHELL=/usr/bin/bash
# Import Go env variables
export PATH := $(PATH):$(GOROOT)/bin:$(GOPATH)/bin
IMAGE_NAME := graphoscope
REMOTE := root@localhost
REMOTE_PATH := /opt/graphoscope
VERSION := $(shell cat VERSION)
# Build plugins and binary file to deploy
compile:
rm -rf build/plugins/* build/$(IMAGE_NAME)*
docker build --target plugins-builder -t $(IMAGE_NAME)-plugins:$(VERSION) -f Dockerfile .
docker run --rm --entrypoint sh \
-v $(shell pwd)/build/plugins:/opt/mount:Z \
$(IMAGE_NAME)-plugins:$(VERSION) \
-c "cp -r /go/plugins/* /opt/mount/"
docker build -t $(IMAGE_NAME):$(VERSION) -f Dockerfile .
docker run --rm --entrypoint sh \
-v $(shell pwd)/build:/opt/mount:Z \
$(IMAGE_NAME):$(VERSION) \
-c "cp /go/graphoscope /opt/mount/"
tar -czvf build/$(IMAGE_NAME)-linux-amd64-v$(VERSION).tar.gz \
assets \
certs/graphoscope.* \
definitions/{outputs,processors,sources}/*.yaml.example \
docs \
files/graphoscope.service \
files/*.example \
files/demo.csv \
files/features.yaml \
graphoscope.yaml.example \
Makefile.example \
VERSION \
-C build plugins graphoscope
docker rmi $(IMAGE_NAME):$(VERSION) $(IMAGE_NAME)-plugins:$(VERSION)
# Run local installation
install:
# Systemd files
cp files/graphoscope.service /etc/systemd/system/
chmod 644 /etc/systemd/system/graphoscope.service
systemctl daemon-reload
systemctl stop graphoscope
# Prepare needed folders
mkdir -p /etc/$(IMAGE_NAME)/certs
mkdir -p $(REMOTE_PATH)/{files,upload}
mkdir -p $(REMOTE_PATH)/definitions/{outputs,processors,sources}
mkdir -p /var/log/$(IMAGE_NAME)
# Copy the content
cp graphoscope.yaml.example /etc/$(IMAGE_NAME)/graphoscope.yaml
cp certs/graphoscope.* /etc/$(IMAGE_NAME)/certs/
cp definitions/sources/demo.yaml.example $(REMOTE_PATH)/definitions/sources/demo.yaml
cp files/groups.json.example $(REMOTE_PATH)/files/groups.json
cp files/formats.yaml.example $(REMOTE_PATH)/files/formats.yaml
cp files/demo.csv $(REMOTE_PATH)/files/
chmod 600 /etc/$(IMAGE_NAME)/graphoscope.yaml
chmod 600 /etc/$(IMAGE_NAME)/certs/*
# Updatable assets, sync with the "update" target
cp -r plugins $(REMOTE_PATH)/
cp -r assets $(REMOTE_PATH)/
cp -r docs $(REMOTE_PATH)/
cp graphoscope $(REMOTE_PATH)/
cp files/features.yaml $(REMOTE_PATH)/files/
cp VERSION $(REMOTE_PATH)/
chmod 744 $(REMOTE_PATH)/$(IMAGE_NAME)
# Install on the remote server
install-remote:
# Systemd files
scp files/graphoscope.service $(REMOTE):/etc/systemd/system/
ssh $(REMOTE) chmod 644 /etc/systemd/system/graphoscope.service
ssh $(REMOTE) systemctl daemon-reload
ssh $(REMOTE) systemctl stop graphoscope
# Prepare needed folders
ssh $(REMOTE) mkdir -p /etc/$(IMAGE_NAME)/certs
ssh $(REMOTE) mkdir -p $(REMOTE_PATH)/{files,plugins,upload}
ssh $(REMOTE) mkdir -p $(REMOTE_PATH)/definitions/{outputs,processors,sources}
ssh $(REMOTE) mkdir -p /var/log/$(IMAGE_NAME)
# Copy the content
scp graphoscope.yaml.example $(REMOTE):/etc/$(IMAGE_NAME)/graphoscope.yaml
scp certs/graphoscope.* $(REMOTE):/etc/$(IMAGE_NAME)/certs/
scp definitions/sources/demo.yaml.example $(REMOTE):$(REMOTE_PATH)/definitions/sources/demo.yaml
scp files/groups.json.example $(REMOTE):$(REMOTE_PATH)/files/groups.json
scp files/formats.yaml.example $(REMOTE):$(REMOTE_PATH)/files/formats.yaml
scp files/demo.csv $(REMOTE):$(REMOTE_PATH)/files/
ssh $(REMOTE) chmod 600 /etc/$(IMAGE_NAME)/graphoscope.yaml
ssh $(REMOTE) chmod 600 /etc/$(IMAGE_NAME)/certs/*
# Updatable assets, sync with the "update-remote" target
scp -r assets $(REMOTE):$(REMOTE_PATH)/
scp -r docs $(REMOTE):$(REMOTE_PATH)/
scp -r build/plugins $(REMOTE):$(REMOTE_PATH)/
scp build/$(IMAGE_NAME) $(REMOTE):$(REMOTE_PATH)/
scp files/features.yaml $(REMOTE):$(REMOTE_PATH)/files/
scp VERSION $(REMOTE):$(REMOTE_PATH)/
ssh $(REMOTE) chmod 744 $(REMOTE_PATH)/$(IMAGE_NAME)
# Update existing local service,
# sync with the "install" target
update:
systemctl stop graphoscope
# Clear old data
rm -rf $(REMOTE_PATH)/assets $(REMOTE_PATH)/docs $(REMOTE_PATH)/plugins
# Copy new content
cp -r plugins $(REMOTE_PATH)/
cp -r assets $(REMOTE_PATH)/
cp -r docs $(REMOTE_PATH)/
cp graphoscope $(REMOTE_PATH)/
cp files/features.yaml $(REMOTE_PATH)/files/
cp VERSION $(REMOTE_PATH)/
chmod 744 $(REMOTE_PATH)/$(IMAGE_NAME)
systemctl start graphoscope
# Update existing remote service,
# sync with the "install-remote" target
update-remote:
ssh $(REMOTE) systemctl stop graphoscope
# Clear old data
ssh $(REMOTE) rm -rf $(REMOTE_PATH)/{assets,docs,plugins}
# Copy new content
scp -r assets $(REMOTE):$(REMOTE_PATH)/
scp -r docs $(REMOTE):$(REMOTE_PATH)/
scp -r build/plugins $(REMOTE):$(REMOTE_PATH)/
scp build/$(IMAGE_NAME) $(REMOTE):$(REMOTE_PATH)/
scp files/features.yaml $(REMOTE):$(REMOTE_PATH)/files/
scp VERSION $(REMOTE):$(REMOTE_PATH)/
ssh $(REMOTE) chmod 744 $(REMOTE_PATH)/$(IMAGE_NAME)
ssh $(REMOTE) systemctl start graphoscope
# Uninstall the service
uninstall:
systemctl stop graphoscope
rm -rf $(REMOTE_PATH)
rm -rf /var/log/$(IMAGE_NAME)
rm -rf /etc/$(IMAGE_NAME)
rm -rf /etc/systemd/system/graphoscope.service
uninstall-remote:
ssh $(REMOTE) systemctl stop graphoscope
ssh $(REMOTE) rm -rf $(REMOTE_PATH)
ssh $(REMOTE) rm -rf /var/log/$(IMAGE_NAME)
ssh $(REMOTE) rm -rf /etc/$(IMAGE_NAME)
ssh $(REMOTE) rm -rf /etc/systemd/system/graphoscope.service
# Build plugins locally, mainly for development
plugins-local:
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/elasticsearch.v7.so plugins/src/elasticsearch.v7/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/elasticsearch.v8.so plugins/src/elasticsearch.v8/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/http.so plugins/src/http/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/rest.so plugins/src/rest/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/mongodb.so plugins/src/mongodb/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/postgresql.so plugins/src/postgresql/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/redis.so plugins/src/redis/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/mysql.so plugins/src/mysql/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/file-csv.so plugins/src/file/csv/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/misp.so plugins/src/misp/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/pastelyzer.so plugins/src/pastelyzer/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/abuseipdb.so plugins/src/abuseipdb/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/hashlookup.so plugins/src/hashlookup/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/circl_passive_ssl.so plugins/src/circl_passive_ssl/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/phishtank.so plugins/src/phishtank/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/sources/ipinfo.so plugins/src/ipinfo/*.go
CGO_CFLAGS="-g -O2 -Wno-return-local-addr" go build -buildmode=plugin -ldflags="-w" -o plugins/sources/sqlite.so plugins/src/sqlite/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/processors/taxonomy.so plugins/src/taxonomy/*.go
go build -buildmode=plugin -ldflags="-w" -o plugins/processors/modify.so plugins/src/modify/*.go
go build -buildmode=plugin -ldflags="-w" -o /dev/null plugins/src/template/*.go
# Test Go code
test:
go test plugins/src/elasticsearch.v7/*.go
go test plugins/src/elasticsearch.v8/*.go
go test plugins/src/http/*.go
go test plugins/src/rest/*.go
go test plugins/src/mongodb/*.go
go test plugins/src/postgresql/*.go
go test plugins/src/redis/*.go
go test plugins/src/mysql/*.go
go test plugins/src/file/csv/*.go
go test plugins/src/misp/*.go
go test plugins/src/pastelyzer/*.go
go test plugins/src/abuseipdb/*.go
go test plugins/src/hashlookup/*.go
go test plugins/src/circl_passive_ssl/*.go
go test plugins/src/phishtank/*.go
go test plugins/src/ipinfo/*.go
CGO_CFLAGS="-g -O2 -Wno-return-local-addr" go test plugins/src/sqlite/*.go
go test plugins/src/taxonomy/*.go
go test plugins/src/modify/*.go
# Update dependencies
mod:
go get -u ./...
go mod tidy
# Check for Golang errors & inefficient code. Install with:
# curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh
# mv bin/golangci-lint "$GOPATH/bin/" && rm -rf bin
lint:
golangci-lint run --timeout=2m --enable=revive --enable=gosec --enable=govet --enable=prealloc --exclude-dirs "(ideas)" ./...
# golint .