forked from yotamloe/bindplane-op
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
300 lines (251 loc) · 9.88 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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
PWD=$(shell pwd)
ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort )
TOOLS_MOD_DIR := ./internal/tools
ADDLICENSE=addlicense
ALL_SRC := $(shell find . -name '*.go' -o -name '*.sh' -o -name 'Dockerfile' -type f | sort)
GIT_SHA=$(shell git rev-parse --short HEAD)
NAMESPACE=bindplane-dev
OUTDIR=./build
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
ifeq ($(GOARCH), amd64)
GOARCH_FULL=amd64_v1
endif
.PHONY: help
help:
@echo "TARGET\tDESCRIPTION" | expand -t 24
@grep '^.PHONY: .* #' Makefile | sed 's/\.PHONY: \(.*\) # \(.*\)/\1\t\2/' | sort | expand -t 24
.PHONY: gomoddownload
gomoddownload:
go mod download
.PHONY: install-git-hooks # installs git pre-commit hooks
install-git-hooks:
cp scripts/git_hooks/* .git/hooks/
.PHONY: install-tools # installs build tools
install-tools: install-git-hooks
cd $(TOOLS_MOD_DIR) && go install github.com/securego/gosec/v2/cmd/gosec
cd $(TOOLS_MOD_DIR) && go install github.com/google/addlicense
cd $(TOOLS_MOD_DIR) && go install github.com/swaggo/swag/cmd/swag
cd $(TOOLS_MOD_DIR) && go install github.com/99designs/gqlgen
cd $(TOOLS_MOD_DIR) && go install github.com/mgechev/revive
cd $(TOOLS_MOD_DIR) && go install github.com/uw-labs/lichen
cd $(TOOLS_MOD_DIR) && go install honnef.co/go/tools/cmd/staticcheck
cd $(TOOLS_MOD_DIR) && go install github.com/client9/misspell/cmd/misspell
cd $(TOOLS_MOD_DIR) && go install github.com/ory/go-acc
.PHONY: install-ui # [ui] npm install
install-ui:
cd ui && npm install
.PHONY: install # install-tools && install-ui
install: install-tools install-ui
.PHONY: ci # [ui] npm ci
ci:
cd ui && npm ci
ui/node_modules: ui/package.json ui/package-lock.json
$(MAKE) ci
.PHONY: dev # runs go serve, ui proxy server, and ui graphql generator [primary development target]
dev: ui/node_modules prep
./ui/node_modules/.bin/concurrently -c blue,magenta,cyan -n sv,ui,gq "go run ./cmd/bindplane/main.go serve --force-console-color --env development" "cd ui && npm start" "cd ui && npm run generate:watch"
.PHONY: test # runs go test for server tests
test: prep
go test ./... -race -cover -timeout 60s
.PHONY: test-with-cover
test-with-cover: prep
BINDPLANE_TEST_IMAGE="observiq/bindplane-amd64:$(GIT_SHA)" go-acc --tags=integration --output=coverage.out --ignore=generated --ignore=mocks ./...
show-coverage: test-with-cover
# Show coverage as HTML in the default browser.
go tool cover -html=coverage.out
.PHONY: bench
bench:
go test -benchmem -run=^$$ -bench ^* ./...
.PHONY: tidy # runs go mod tidy
tidy:
$(MAKE) for-all CMD="rm -fr go.sum"
$(MAKE) for-all CMD="go mod tidy"
.PHONY: lint # runs revive linter and npm run lint
lint:
revive -formatter friendly -exclude "internal/graphql/schema.*" -set_exit_status ./...
cd ui && npm run lint && cd ..
.PHONY: vet # runs go vet
vet:
GOOS=darwin go vet ./...
GOOS=linux go vet ./...
GOOS=windows go vet ./...
.PHONY: secure # runs gosec to identify security issues
secure: prep
gosec -exclude-generated -exclude-dir internal/tools ./...
.PHONY: generate # runs go generate to generate graphql resolver and runs add-license
generate:
go generate ./...
@$(MAKE) add-license
.PHONY: swagger # generates the REST API documentation using swagger
swagger:
swag init --parseDependency --parseInternal -g model/rest.go -o docs/swagger/
@$(MAKE) add-license
.PHONY: init-server # runs bindplane init server to setup the server
init-server: prep
go run cmd/bindplane/main.go init server
.PHONY: for-all
for-all:
@set -e; for dir in $(ALL_MODULES); do \
(cd "$${dir}" && $${CMD} ); \
done
# TODO(jsirianni): Add secure: https://github.com/observIQ/bindplane/issues/478
.PHONY: ci-check
ci-check: vet test lint check-license scan-licenses
.PHONY: check-license # checks for missing license header in source files
check-license:
@ADDLICENSEOUT=`$(ADDLICENSE) -check $(ALL_SRC) 2>&1`; \
if [ "$$ADDLICENSEOUT" ]; then \
echo "$(ADDLICENSE) FAILED => add License errors:\n"; \
echo "$$ADDLICENSEOUT\n"; \
echo "Use 'make add-license' to fix this."; \
exit 1; \
else \
echo "Check License finished successfully"; \
fi
.PHONY: add-license # adds license header to source files
add-license:
@ADDLICENSEOUT=`$(ADDLICENSE) -y "" -c "observIQ, Inc." $(ALL_SRC) 2>&1`; \
if [ "$$ADDLICENSEOUT" ]; then \
echo "$(ADDLICENSE) FAILED => add License errors:\n"; \
echo "$$ADDLICENSEOUT\n"; \
exit 1; \
else \
echo "Add License finished successfully"; \
fi
.PHONY: scan-licenses # checks dependencies for permitted licenses
scan-licenses:
lichen --config=./license.yaml $$(find build/bindplane* | xargs)
# TLS will run the tls generation script only when the
# tls directory is missing
tls:
mkdir tls
docker run \
-v ${PWD}/scripts/generate-dev-certificates.sh:/generate-dev-certificates.sh \
-v ${PWD}/tls:/tls \
--entrypoint=/bin/sh \
alpine/openssl /generate-dev-certificates.sh
.PHONY: docker-http
docker-http:
docker run -d -p 3010:3001 \
--name "bindplane-server-${GIT_SHA}-http" \
-e BINDPLANE_CONFIG_SESSIONS_SECRET=403dd8ff-72a9-4401-9a66-e54b37d6e0ce \
-e BINDPLANE_CONFIG_LOG_OUTPUT=stdout \
"observiq/bindplane-$(GOARCH):${GIT_SHA}" \
--host 0.0.0.0 \
--port "3001" \
--server-url http://localhost:3010 \
--remote-url ws://localhost:3010 \
--secret-key 403dd8ff-72a9-4401-9a66-e54b37d6e0ce
docker logs "bindplane-server-${GIT_SHA}-http"
dist/bindplane_$(GOOS)_$(GOARCH_FULL)/bindplane profile set docker-http \
--server-url http://localhost:3010 --remote-url ws://localhost:3010
dist/bindplane_$(GOOS)_$(GOARCH_FULL)/bindplane profile use docker-http
.PHONY: docker-https
docker-https: tls
docker run -d \
-p 3011:3001 \
--name "bindplane-server-${GIT_SHA}-https" \
-e BINDPLANE_CONFIG_SESSIONS_SECRET=403dd8ff-72a9-4401-9a66-e54b37d6e0ce \
-e BINDPLANE_CONFIG_LOG_OUTPUT=stdout \
-v "${PWD}/tls:/tls" \
"observiq/bindplane-$(GOARCH):latest" \
--tls-cert /tls/bindplane.crt --tls-key /tls/bindplane.key \
--host 0.0.0.0 \
--port "3001" \
--server-url https://localhost:3011 \
--remote-url wss://localhost:3011 \
--secret-key 403dd8ff-72a9-4401-9a66-e54b37d6e0ce
docker logs "bindplane-server-${GIT_SHA}-https"
dist/bindplane_$(GOOS)_$(GOARCH_FULL)/bindplane profile set docker-https \
--server-url https://localhost:3011 --remote-url wss://localhost:3011 \
--tls-ca tls/bindplane-ca.crt
dist/bindplane_$(GOOS)_$(GOARCH_FULL)/bindplane profile use docker-https
.PHONY: docker-https-mtls
docker-https-mtls: tls
docker run -d \
-p 3012:3001 \
--name "bindplane-server-${GIT_SHA}-https-mtls" \
-e BINDPLANE_CONFIG_SESSIONS_SECRET=403dd8ff-72a9-4401-9a66-e54b37d6e0ce \
-e BINDPLANE_CONFIG_LOG_OUTPUT=stdout \
-v "${PWD}/tls:/tls" \
"observiq/bindplane-$(GOARCH):latest" \
--tls-cert /tls/bindplane.crt --tls-key /tls/bindplane.key --tls-ca /tls/bindplane-ca.crt --tls-ca /tls/test-ca.crt \
--host 0.0.0.0 \
--port "3001" \
--server-url https://localhost:3012 \
--remote-url wss://localhost:3012 \
--secret-key 403dd8ff-72a9-4401-9a66-e54b37d6e0ce
docker logs "bindplane-server-${GIT_SHA}-https-mtls"
dist/bindplane_$(GOOS)_$(GOARCH_FULL)/bindplane profile set docker-https-mtls \
--server-url https://localhost:3012 --remote-url wss://localhost:3012 \
--tls-cert tls/bindplane-client.crt --tls-key ./tls/bindplane-client.key --tls-ca tls/bindplane-ca.crt
dist/bindplane_$(GOOS)_$(GOARCH_FULL)/bindplane profile use docker-https-mtls
.PHONY: docker-all
docker-all: docker-clean docker-http docker-https docker-https-mtls
.PHONY: docker-clean
docker-clean:
docker ps -a | grep bindplane-server | awk '{print $$1}' | xargs -I{} docker rm --force {}
# Call 'release-test' first.
.PHONY: inspec-continer-image
inspec-continer-image: prep docker-http
docker exec -u root bindplane-server-${GIT_SHA}-http apt-get update -qq
docker exec -u root bindplane-server-${GIT_SHA}-http apt-get install -qq -y procps net-tools
cinc-auditor exec test/inspec/docker/integration.rb -t "docker://bindplane-server-${GIT_SHA}-http"
.PHONY: run
run: docker-http
# Called by commands such as 'vet', useful when the ui has not
# been built before (in ci)
prep: ui/build
ui/build:
mkdir ui/build
touch ui/build/index.html
.PHONY: ui-test # [ui] runs ui tests in watch mode
ui-test:
cd ui && CI=true npm run test --watchAll
# ui-build builds the static site to be embeded into the Go binary.
# make install should be called before, if you are not up to date.
.PHONY: ui-build # [ui] builds the static site to be embeded into the Go binary
ui-build:
cd ui && npm run build
# goreleaser will call ui-build to ensure the static site
# is up to date. goreleaser will not call `make install`.
.PHONY: build # builds bindplane and bindplanectl using goreleaser
build:
goreleaser build --rm-dist --skip-validate --single-target --snapshot
.PHONY: clean # removes the dist folder
clean:
rm -rf $(OUTDIR)
.PHONY: release-test
release-test:
goreleaser release --rm-dist --skip-publish --skip-validate --snapshot
# Kitchen prep will build a release and ensure the required
# gems are installed for using Kitchen with GCE
.PHONY: kitchen-prep
kitchen-prep: release-test
sudo cinc gem install --no-user-install kitchen-google
sudo cinc gem install --no-user-install kitchen-sync
mkdir -p dist/kitchen
cp dist/bindplane_*amd64.deb dist/kitchen
cp dist/bindplane_*amd64.rpm dist/kitchen
cp scripts/install-linux.sh dist/kitchen
# Assumes you have a ssh key pair at ~/.ssh/id_rsa && ~/.ssh/id_rsa.pub
# Assumes you are authenticated to GCP with Gcloud SDK
#
# Run all tests:
# make kitchen
# Run tests against specific OS:
# make kitchen ARGS=sles
.PHONY: kitchen
kitchen:
kitchen test -c 10 $(ARGS)
.PHONY: kitchen-clean
kitchen-clean:
kitchen destroy -c 10
ALLDOC=$(shell find . \( -name "*.md" -o -name "*.yaml" \) | grep -v ui/node_modules)
.PHONY: misspell # checks for spelling errors in .md and .yaml files
misspell:
misspell -error $(ALLDOC)
.PHONY: misspell-fix # fixes spelling errors in .md and .yaml files
misspell-fix:
misspell -w $(ALLDOC)