-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathMakefile
More file actions
450 lines (385 loc) · 15.8 KB
/
Makefile
File metadata and controls
450 lines (385 loc) · 15.8 KB
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# All source code and documents, used when checking for misspellings
ALLDOC := $(shell find . \( -name "*.md" -o -name "*.yaml" \) \
-type f | sort)
ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort )
ALL_MDATAGEN_MODULES := $(shell find . -type f -name "metadata.yaml" -exec dirname {} \; | sort )
# All source code files
ALL_SRC := $(shell find . -name '*.go' -o -name '*.sh' -o -name 'Dockerfile*' -type f | sort)
OUTDIR=./dist
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
INTEGRATION_TEST_ARGS?=-tags integration
TOOLS_MOD_DIR := ./internal/tools
# Directories migrated to the contrib repo, excluded from testing.
# Keep in sync with the components filter in .github/workflows/checks.yml.
MIGRATED_MODULE_PATTERNS := $(shell cat migrated-modules.txt)
# Generate gosec -exclude-dir flags from migrated module patterns
GOSEC_MIGRATED_EXCLUDES := $(foreach pat,$(MIGRATED_MODULE_PATTERNS),-exclude-dir=$(patsubst %/,%,$(pat)))
ifeq ($(GOOS), windows)
EXT?=.exe
else
EXT?=
endif
SNAPSHOT := $(shell git rev-parse --short HEAD)
PREVIOUS_TAG := $(shell git tag --sort=v:refname --no-contains HEAD | grep -E "[0-9]+\.[0-9]+\.[0-9]+$$" | grep -v 'version' | tail -n1)
CURRENT_TAG := $(shell git tag --sort=v:refname --points-at HEAD | grep -E "v[0-9]+\.[0-9]+\.[0-9]+$$" | grep -v 'version' | tail -n1)
# Version will be the tag pointing to the current commit, or the previous version tag if there is no such tag
VERSION ?= $(if $(CURRENT_TAG),$(CURRENT_TAG),$(PREVIOUS_TAG)-SNAPSHOT-$(SNAPSHOT))
.PHONY: version
version:
@printf $(VERSION)
# Build binaries for current GOOS/GOARCH by default
.DEFAULT_GOAL := build-binaries
# Builds just the agent for current GOOS/GOARCH pair
.PHONY: agent
agent:
CGO_ENABLED=0 go build -ldflags "-s -w -X github.com/observiq/bindplane-otel-contrib/pkg/version.version=$(VERSION)" -tags bindplane -o $(OUTDIR)/collector_$(GOOS)_$(GOARCH)$(EXT) ./cmd/collector
# Builds just the updater for current GOOS/GOARCH pair
.PHONY: updater
updater:
cd ./updater/; CGO_ENABLED=0 go build -ldflags "-s -w -X github.com/observiq/bindplane-otel-collector/updater/internal/version.version=$(VERSION)" -o ../$(OUTDIR)/updater_$(GOOS)_$(GOARCH)$(EXT) ./cmd/updater
# Builds the updater + agent for current GOOS/GOARCH pair
.PHONY: build-binaries
build-binaries: agent updater
.PHONY: build-all
build-all: build-linux build-darwin build-windows
.PHONY: build-linux
build-linux: build-linux-amd64 build-linux-arm64 build-linux-arm build-linux-ppc64 build-linux-ppc64le
.PHONY: build-darwin
build-darwin: build-darwin-amd64 build-darwin-arm64
.PHONY: build-windows
build-windows: build-windows-amd64 build-windows-arm64
.PHONY: build-linux-ppc64
build-linux-ppc64:
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64 $(MAKE) build-binaries -j2
.PHONY: build-linux-ppc64le
build-linux-ppc64le:
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le $(MAKE) build-binaries -j2
.PHONY: build-linux-amd64
build-linux-amd64:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(MAKE) build-binaries -j2
.PHONY: build-linux-arm64
build-linux-arm64:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(MAKE) build-binaries -j2
.PHONY: build-linux-arm
build-linux-arm:
CGO_ENABLED=0 GOOS=linux GOARCH=arm $(MAKE) build-binaries -j2
.PHONY: build-darwin-amd64
build-darwin-amd64:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(MAKE) build-binaries -j2
.PHONY: build-darwin-arm64
build-darwin-arm64:
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 $(MAKE) build-binaries -j2
.PHONY: build-windows-amd64
build-windows-amd64:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(MAKE) build-binaries -j2
.PHONY: build-windows-arm64
build-windows-arm64:
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 $(MAKE) build-binaries -j2
# tool-related commands
.PHONY: install-tools
install-tools:
cd $(TOOLS_MOD_DIR) && go install github.com/client9/misspell/cmd/misspell
cd $(TOOLS_MOD_DIR) && go install github.com/google/addlicense
cd $(TOOLS_MOD_DIR) && go install github.com/mgechev/revive
cd $(TOOLS_MOD_DIR) && go install go.opentelemetry.io/collector/cmd/mdatagen
cd $(TOOLS_MOD_DIR) && go install github.com/securego/gosec/v2/cmd/gosec
# update cosign in release.yml when updating this version
# update cosign in docs/verify-signature.md when updating this version
go install github.com/sigstore/cosign/cmd/cosign@v1.13.1
cd $(TOOLS_MOD_DIR) && go install github.com/uw-labs/lichen
cd $(TOOLS_MOD_DIR) && go install github.com/vektra/mockery/v2
cd $(TOOLS_MOD_DIR) && go install golang.org/x/tools/cmd/goimports
cd $(TOOLS_MOD_DIR) && go install gotest.tools/gotestsum
# Fast install that checks if tools exist (for CI with cache)
.PHONY: install-tools-ci
install-tools-ci:
@command -v misspell > /dev/null 2>&1 || (cd $(TOOLS_MOD_DIR) && go install github.com/client9/misspell/cmd/misspell)
@command -v addlicense > /dev/null 2>&1 || (cd $(TOOLS_MOD_DIR) && go install github.com/google/addlicense)
@command -v revive > /dev/null 2>&1 || (cd $(TOOLS_MOD_DIR) && go install github.com/mgechev/revive)
@command -v mdatagen > /dev/null 2>&1 || (cd $(TOOLS_MOD_DIR) && go install go.opentelemetry.io/collector/cmd/mdatagen)
@command -v gosec > /dev/null 2>&1 || (cd $(TOOLS_MOD_DIR) && go install github.com/securego/gosec/v2/cmd/gosec)
@command -v cosign > /dev/null 2>&1 || go install github.com/sigstore/cosign/cmd/cosign@v1.13.1
@command -v lichen > /dev/null 2>&1 || (cd $(TOOLS_MOD_DIR) && go install github.com/uw-labs/lichen)
@command -v mockery > /dev/null 2>&1 || (cd $(TOOLS_MOD_DIR) && go install github.com/vektra/mockery/v2)
@command -v goimports > /dev/null 2>&1 || (cd $(TOOLS_MOD_DIR) && go install golang.org/x/tools/cmd/goimports)
@command -v gotestsum > /dev/null 2>&1 || (cd $(TOOLS_MOD_DIR) && go install gotest.tools/gotestsum)
.PHONY: lint
lint:
revive -config revive/config.toml -formatter friendly ./...
.PHONY: misspell
misspell:
misspell -error $(ALLDOC)
.PHONY: misspell-fix
misspell-fix:
misspell -w $(ALLDOC)
.PHONY: test
test:
@echo "running tests in root"
@gotestsum --rerun-fails --packages="./..." -- -race
@set -e; for dir in $(ALL_MODULES); do \
if [ "$${dir}" = "." ]; then continue; fi; \
SKIP=false; \
for pattern in $(MIGRATED_MODULE_PATTERNS); do \
case "$${dir}" in "./$${pattern}"*) SKIP=true; break;; esac; \
done; \
if [ "$${SKIP}" = "true" ]; then \
echo "skipping migrated module $${dir}"; \
continue; \
fi; \
(cd "$${dir}" && \
echo "running tests in $${dir}" && \
gotestsum --rerun-fails --packages="./..." -- -race) || exit 1; \
done
.PHONY: test-no-race
test-no-race:
$(MAKE) for-all CMD="gotestsum --rerun-fails --packages="./..." "
.PHONY: test-with-cover
test-with-cover:
$(MAKE) for-all CMD="go test -coverprofile=cover.out ./..."
$(MAKE) for-all CMD="go tool cover -html=cover.out -o cover.html"
.PHONY: test-updater-integration
test-updater-integration:
cd updater; gotestsum --rerun-fails --packages="./..." -- \
$(INTEGRATION_TEST_ARGS) -race
.PHONY: bench
bench:
$(MAKE) for-all CMD="go test -benchmem -run=^$$ -bench ^* ./..."
.PHONY: check-fmt
check-fmt:
goimports -d ./ | diff -u /dev/null -
.PHONY: fmt
fmt:
goimports -w .
.PHONY: tidy
tidy:
$(MAKE) for-all CMD="go mod tidy -compat=1.25.9"
.PHONY: gosec
gosec:
gosec \
-exclude-dir=updater \
-exclude-dir=internal/tools \
-exclude-dir=cmd/plugindocgen \
$(GOSEC_MIGRATED_EXCLUDES) \
./...
# exclude the testdata dir; it contains a go program for testing.
cd updater; gosec -exclude-dir internal/service/testdata ./...
# This target performs all checks that CI will do (excluding the build itself)
.PHONY: ci-checks
ci-checks: check-fmt check-license check-mod-paths check-dependabot misspell lint gosec test
# This target checks that every go.mod has the correct module path.
# Root must be github.com/observiq/bindplane-otel-collector.
# Subdirectories must be github.com/observiq/bindplane-otel-collector/<relative-path>.
# Modules with legacy paths that cannot be renamed are excluded.
MOD_PATH_EXCLUDES := ./cmd/plugindocgen
.PHONY: check-mod-paths
check-mod-paths:
@FAILED=0; \
for dir in $(ALL_MODULES); do \
SKIP=false; \
for pattern in $(MIGRATED_MODULE_PATTERNS); do \
case "$${dir}" in "./$${pattern}"*) SKIP=true; break;; esac; \
done; \
if [ "$${SKIP}" = "true" ]; then continue; fi; \
case " $(MOD_PATH_EXCLUDES) " in *" $${dir} "*) continue ;; esac; \
MOD=$$(head -1 "$${dir}/go.mod" | sed 's/^module //'); \
if [ "$${dir}" = "." ]; then \
EXPECTED="github.com/observiq/bindplane-otel-collector"; \
else \
RELPATH=$$(echo "$${dir}" | sed 's|^\./||'); \
EXPECTED="github.com/observiq/bindplane-otel-collector/$${RELPATH}"; \
fi; \
if [ "$${MOD}" != "$${EXPECTED}" ]; then \
echo "MISMATCH: $${dir}/go.mod"; \
echo " got: $${MOD}"; \
echo " expected: $${EXPECTED}"; \
FAILED=1; \
fi; \
done; \
if [ "$${FAILED}" -eq 1 ]; then \
echo ""; \
echo "check-mod-paths FAILED: module paths must match directory structure."; \
exit 1; \
else \
echo "Check module paths finished successfully"; \
fi
# This target checks that every directory with a go.mod has an entry in dependabot.yml
.PHONY: check-dependabot
check-dependabot:
@FAILED=0; \
DEPENDABOT_DIRS=$$(grep 'directory:' .github/dependabot.yml | sed 's/.*directory: *"\(.*\)"/\1/'); \
for dir in $(ALL_MODULES); do \
SKIP=false; \
for pattern in $(MIGRATED_MODULE_PATTERNS); do \
case "$${dir}" in "./$${pattern}"*) SKIP=true; break;; esac; \
done; \
if [ "$${SKIP}" = "true" ]; then continue; fi; \
if [ "$${dir}" = "." ]; then \
EXPECTED="/"; \
else \
EXPECTED=$$(echo "$${dir}" | sed 's|^\./|/|'); \
fi; \
if ! echo "$${DEPENDABOT_DIRS}" | grep -qx "$${EXPECTED}"; then \
echo "MISSING: $${dir}/go.mod has no entry in .github/dependabot.yml (expected directory: \"$${EXPECTED}\")"; \
FAILED=1; \
fi; \
done; \
if [ "$${FAILED}" -eq 1 ]; then \
echo ""; \
echo "check-dependabot FAILED: add missing entries to .github/dependabot.yml"; \
exit 1; \
else \
echo "Check dependabot finished successfully"; \
fi
# This target checks that license copyright header is on every source file
.PHONY: check-license
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
# This target adds a license copyright header is on every source file that is missing one
.PHONY: add-license
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
# update-otel attempts to update otel dependencies in go.mods,
# and update the otel versions in the docs.
# Usage: make update-otel OTEL_VERSION=vx.x.x CONTRIB_VERSION=vx.x.x PDATA_VERSION=vx.x.x-rcx BDOT_CONTRIB_VERSION=vx.x.x
.PHONY: update-otel
update-otel:
./scripts/update-otel.sh "$(OTEL_VERSION)" "$(CONTRIB_VERSION)" "$(PDATA_VERSION)"
./scripts/update-docs.sh "$(OTEL_VERSION)" "$(CONTRIB_VERSION)" "$(BDOT_CONTRIB_VERSION)"
$(MAKE) tidy
# Double make tidy - this unfortunately is needed due to the order in which modules are tidied.
# The modules this seems to effect are plugindocgen and bindplaneextension
$(MAKE) tidy
# update-modules updates all submodules to be the new version.
# Usage: make update-modules NEW_VERSION=vx.x.x
.PHONY: update-modules
update-modules:
./scripts/update-module-version.sh "$(NEW_VERSION)"
$(MAKE) tidy
# update-contrib updates all bindplane-otel-contrib dependencies to the new version.
# Usage: make update-contrib BDOT_CONTRIB_VERSION=vx.x.x
.PHONY: update-contrib
update-contrib:
./scripts/update-bindplane-contrib.sh "$(BDOT_CONTRIB_VERSION)"
$(MAKE) tidy
# Downloads and setups dependencies that are packaged with binary
.PHONY: release-prep
release-prep:
@rm -rf release_deps
@mkdir release_deps
@echo 'v$(CURR_VERSION)' > release_deps/VERSION.txt
./buildscripts/download-dependencies.sh release_deps
@cp -r ./plugins release_deps/
@cp config/example.yaml release_deps/config.yaml
@cp config/logging.yaml release_deps/logging.yaml
@cp service/com.observiq.collector.plist release_deps/com.observiq.collector.plist
@jq ".files[] | select(.service != null)" windows/wix.json >> release_deps/windows_service.json
.PHONY: release-prep-gpg
release-prep-gpg:
$(MAKE) release-prep
@cp -r ./signature/gpg release_deps/gpg
@rm release_deps/gpg/revocations.md
@rm release_deps/gpg/deb-revocations/.keep
@cd release_deps/gpg && tar -czf ../gpg-keys.tar.gz .
# Build and sign, skip release and ignore dirty git tree
.PHONY: release-test
release-test:
# If there are no MSIs in the root dir, we'll create dummy ones so that goreleaser can complete successfully
if [ ! -e "./observiq-otel-collector.msi" ]; then touch ./observiq-otel-collector.msi; fi
if [ ! -e "./observiq-otel-collector-arm64.msi" ]; then touch ./observiq-otel-collector-arm64.msi; fi
SIGNING_KEY_FILE="fake-file" GORELEASER_CURRENT_TAG=$(VERSION) goreleaser release --parallelism 4 --skip=publish --skip=validate --skip=sign --clean --snapshot
.PHONY: release-containers-test
release-containers-test:
$(MAKE) -j3 agent-linux-amd64 agent-linux-arm64 agent-linux-ppc64le
mkdir -p tmp
mv ./dist/collector_linux_amd64 ./tmp/collector_linux_amd64
mv ./dist/collector_linux_arm64 ./tmp/collector_linux_arm64
mv ./dist/collector_linux_ppc64le ./tmp/collector_linux_ppc64le
GORELEASER_CURRENT_TAG=$(VERSION) goreleaser release --parallelism 4 --skip=publish --skip=validate --skip=sign --clean --snapshot --config .goreleaser-docker.yml
.PHONY: agent-linux-amd64 agent-linux-arm64 agent-linux-ppc64le
agent-linux-amd64:
GOARCH=amd64 GOOS=linux $(MAKE) agent
agent-linux-arm64:
GOARCH=arm64 GOOS=linux $(MAKE) agent
agent-linux-ppc64le:
GOARCH=ppc64le GOOS=linux $(MAKE) agent
build-single:
$(MAKE)
SIGNING_KEY_FILE="fake-file" GORELEASER_CURRENT_TAG=$(VERSION) goreleaser release --skip=publish --skip=sign --clean --skip=validate --snapshot --single-target
.PHONY: release-test-single
release-test-single:
GORELEASER_CURRENT_TAG=$(VERSION) goreleaser release -f .goreleaser.arm64.yml --skip=publish --clean --skip=validate --snapshot
.PHONY: for-all
for-all:
@echo "running $${CMD} in root"
@$${CMD}
@set -e; for dir in $(ALL_MODULES); do \
if [ "$${dir}" = "." ]; then continue; fi; \
SKIP=false; \
for pattern in $(MIGRATED_MODULE_PATTERNS); do \
case "$${dir}" in "./$${pattern}"*) SKIP=true; break;; esac; \
done; \
if [ "$${SKIP}" = "true" ]; then \
echo "skipping migrated module $${dir}"; \
continue; \
fi; \
(cd "$${dir}" && \
echo "running $${CMD} in $${dir}" && \
$${CMD} ); \
done
# Release a new version of the agent. This will also tag all submodules
.PHONY: release
release:
@if [ -z "$(version)" ]; then \
echo "version was not set"; \
exit 1; \
fi
@if ! [[ "$(version)" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$$ ]]; then \
echo "version $(version) is invalid semver"; \
exit 1; \
fi
@git tag $(version)
@git push --tags
@set -e; for dir in $(ALL_MODULES); do \
if [ $${dir} == \. ]; then \
continue; \
fi; \
SKIP=false; \
for pattern in $(MIGRATED_MODULE_PATTERNS); do \
case "$${dir}" in "./$${pattern}"*) SKIP=true; break;; esac; \
done; \
if [ "$${SKIP}" = "true" ]; then \
echo "skipping migrated module $${dir}"; \
continue; \
fi; \
echo "$${dir}" | sed -e "s+^./++" -e 's+$$+/$(version)+' | awk '{print $$1}' | git tag $$(cat); \
done
@git push --tags
.PHONY: clean
clean:
rm -rf $(OUTDIR)
.PHONY: scan-licenses
scan-licenses:
lichen --config=./license.yaml $$(find dist/collector_* dist/updater_*)
.PHONY: generate
generate:
$(MAKE) for-all CMD="go generate ./..."
$(MAKE) fmt
.PHONY: create-plugin-docs
create-plugin-docs:
cd cmd/plugindocgen; go run .