forked from SumoLogic/sumologic-otel-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
339 lines (277 loc) · 10.7 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
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
GOLANGCI_LINT_VERSION ?= v1.53.2
SHELL := /usr/bin/env bash
ifeq ($(OS),Windows_NT)
MAKE := "$(shell cygpath '$(MAKE)')"
endif
all: markdownlint yamllint
.PHONY: markdownlint
markdownlint: mdl
MD_FILES := $(shell find . -type f -name "*.md")
ifeq ($(shell go env GOOS),darwin)
SED ?= gsed
else
SED ?= sed
endif
.PHONY: install-gsed
install-gsed:
ifeq ($(shell go env GOOS),darwin)
@which gsed || brew install gsed
endif
.PHONY: mdl
mdl:
mdl --style .markdownlint/style.rb $(MD_FILES)
yamllint:
yamllint -c .yamllint.yaml \
otelcolbuilder/.otelcol-builder.yaml
markdown-links-lint:
./ci/markdown_links_lint.sh
markdown-link-check:
./ci/markdown_link_check.sh
shellcheck:
./ci/shellcheck.sh
# ref: https://pre-commit.com/
.PHONY: pre-commit-check
pre-commit-check:
pre-commit run --all-files
# ALL_MODULES includes ./* dirs (excludes . dir and example with go code)
ALL_MODULES := $(shell find ./pkg -type f -name "go.mod" -exec dirname {} \; | sort | egrep '^./' )
ALL_MODULES += ./otelcolbuilder
ALL_MODULES_WITHOUT_SCRIPT_TESTS := $(filter-out ./pkg/scripts_test,$(ALL_MODULES))
ALL_EXPORTABLE_MODULES += $(shell find ./pkg -type f -name "go.mod" ! -path "*pkg/test/*" -exec dirname {} \; | sort )
.PHONY: list-modules
list-modules:
$(MAKE) for-all CMD=""
.PHONY: gotest
gotest:
@$(MAKE) for-all CMD="make test" ALL_MODULES="$(ALL_MODULES_WITHOUT_SCRIPT_TESTS)"
.PHONY: test-install-script
test-install-script:
cd ./pkg/scripts_test && $(MAKE) test
.PHONY: golint
golint:
@$(MAKE) for-all CMD="make lint"
.PHONY: gomod-download-all
gomod-download-all:
@$(MAKE) for-all CMD="make mod-download-all"
.PHONY: install-golangci-lint
install-golangci-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
.PHONY: print-all-modules
print-all-modules:
echo $(ALL_EXPORTABLE_MODULES)
.PHONY: for-all
for-all:
@echo "running $${CMD} in all modules..."
@set -e; for dir in $(ALL_MODULES); do \
(cd "$${dir}" && \
echo "running $${CMD} in $${dir}" && \
$${CMD} ); \
done
.PHONY: check-uniform-dependencies
check-uniform-dependencies:
./ci/check_uniform_dependencies.sh
OT_CORE_VERSION := $(shell grep "otelcol_version: .*" otelcolbuilder/.otelcol-builder.yaml | cut -f 4 -d " ")
OT_CONTRIB_VERSION := $(shell grep --max-count=1 '^ - gomod: github\.com/open-telemetry/opentelemetry-collector-contrib/' otelcolbuilder/.otelcol-builder.yaml | cut --delimiter=" " --fields=6 | $(SED) "s/v//")
# usage: make update-ot OT_CORE_NEW=x.x.x OT_CONTRIB_NEW=y.y.y
.PHONY: update-ot
update-ot: install-gsed
@test $(OT_CORE_NEW) || (echo "usage: make update-ot OT_CORE_NEW=x.x.x OT_CONTRIB_NEW=y.y.y"; exit 1);
@test $(OT_CONTRIB_NEW) || (echo "usage: make update-ot OT_CORE_NEW=x.x.x OT_CONTRIB_NEW=y.y.y"; exit 1);
@echo "Updating OT core from $(OT_CORE_VERSION) to $(OT_CORE_NEW) and OT contrib from $(OT_CONTRIB_VERSION) to $(OT_CONTRIB_NEW)"
$(SED) -i "s/\(otelcol_version:\) $(OT_CORE_VERSION)$$/\1 $(OT_CORE_NEW)/" otelcolbuilder/.otelcol-builder.yaml
$(SED) -i "s/\(go\.opentelemetry\.io\/collector\/.*\) v$(OT_CORE_VERSION)$$/\1 v$(OT_CORE_NEW)/" otelcolbuilder/.otelcol-builder.yaml
$(SED) -i "s/\(github\.com\/open-telemetry\/opentelemetry-collector-contrib\/.*\) v$(OT_CONTRIB_VERSION)$$/\1 v$(OT_CONTRIB_NEW)/" otelcolbuilder/.otelcol-builder.yaml
$(SED) -i "s/$(OT_CORE_VERSION)/$(OT_CORE_NEW)/" otelcolbuilder/Makefile
$(SED) -i "s/\(collector\/\(blob\|tree\)\/v\)$(OT_CORE_VERSION)/\1$(OT_CORE_NEW)/" \
README.md \
docs/configuration.md \
docs/migration.md \
pkg/exporter/sumologicexporter/README.md
$(SED) -i "s/\(contrib\/\(blob\|tree\)\/v\)$(OT_CONTRIB_VERSION)/\1$(OT_CONTRIB_NEW)/" \
README.md \
docs/configuration.md \
docs/migration.md \
pkg/receiver/telegrafreceiver/README.md
@find . -type f -name "go.mod" -exec $(SED) -i "s/\(go\.opentelemetry\.io\/collector.*\) v$(OT_CORE_VERSION)$$/\1 v$(OT_CORE_NEW)/" {} \;
@find . -type f -name "go.mod" -exec $(SED) -i "s/\(github\.com\/open-telemetry\/opentelemetry-collector-contrib\/.*\) v$(OT_CONTRIB_VERSION)$$/\1 v$(OT_CONTRIB_NEW)/" {} \;
@echo "building OT distro to check for breakage"
make gomod-download-all
pushd otelcolbuilder \
&& make install-builder \
&& make build \
&& popd
.PHONY: update-journalctl
update-journalctl: install-gsed
$(SED) -i "s/FROM debian.*/FROM debian:${DEBIAN_VERSION} as systemd/" Dockerfile*
LATEST_OT_VERSION := $(shell git describe --match 'v*' --abbrev=0 | cut -c2-)
PREVIOUS_OT_VERSION := $(shell git describe --match 'v*' --abbrev=0 `git describe --match 'v*' --abbrev=0`^ | cut -c2-)
PREVIOUS_CORE_VERSION := $(shell echo ${PREVIOUS_OT_VERSION} | sed -e 's/-sumo-.*//')
.PHONY: update-docs
update-docs: install-gsed
@find docs/ -type f \( -name "*.md" ! -name "upgrading.md" \) -exec $(SED) -i 's#$(PREVIOUS_CORE_VERSION)#$(OT_CORE_VERSION)#g' {} \;
@find docs/ -type f \( -name "*.md" ! -name "upgrading.md" \) -exec $(SED) -i 's#$(PREVIOUS_OT_VERSION)#$(LATEST_OT_VERSION)#g' {} \;
################################################################################
# Release
################################################################################
#
# These targets should be used for the release process in order to make the modules
# contained within this repo importable.
# This is required because as of now Go doesn't allow importing modules being
# defined in repository's sub directories without having this directory name set
# as prefix for the tag
#
# So when we want to make pkg/exporter/sumologicexporter with version v0.0.43-beta.0
# importable then we need to create the following tag:
# `pkg/exporter/sumologicexporter/v0.0.43-beta.0`
# in order for it to be importable.
#
# Related issue: https://github.com/golang/go/issues/34055
# Exemplar usage for the release:
#
# export TAG=v0.0.43-beta.0
# make add-tag push-tag
.PHONY: add-tag
add-tag:
@[ "${TAG}" ] || ( echo ">> env var TAG is not set"; exit 1 )
@echo "Adding tag ${TAG}"
@git tag -a ${TAG} -s -m "${TAG}"
@set -e; for dir in $(ALL_EXPORTABLE_MODULES); do \
(echo Adding tag "$${dir:2}/$${TAG}" && \
git tag -a "$${dir:2}/$${TAG}" -s -m "${dir:2}/${TAG}" ); \
done
.PHONY: push-tag
push-tag:
@[ "${TAG}" ] || ( echo ">> env var TAG is not set"; exit 1 )
@echo "Pushing tag ${TAG}"
@git push origin ${TAG}
@set -e; for dir in $(ALL_EXPORTABLE_MODULES); do \
(echo Pushing tag "$${dir:2}/$${TAG}" && \
git push origin "$${dir:2}/$${TAG}"); \
done
.PHONY: delete-tag
delete-tag:
@[ "${TAG}" ] || ( echo ">> env var TAG is not set"; exit 1 )
@echo "Deleting tag ${TAG}"
@git tag -d ${TAG}
@set -e; for dir in $(ALL_EXPORTABLE_MODULES); do \
(echo Deleting tag "$${dir:2}/$${TAG}" && \
git tag -d "$${dir:2}/$${TAG}" ); \
done
.PHONY: delete-remote-tag
delete-remote-tag:
@[ "${TAG}" ] || ( echo ">> env var TAG is not set"; exit 1 )
@echo "Deleting remote tag ${TAG}"
@git push --delete origin ${TAG}
@set -e; for dir in $(ALL_EXPORTABLE_MODULES); do \
(echo Deleting remote tag "$${dir:2}/$${TAG}" && \
git push --delete origin "$${dir:2}/$${TAG}"); \
done
.PHONY: prepare-tag
prepare-tag: install-gsed
@[ "${TAG}" ] || ( echo ">> env var TAG is not set"; exit 1 )
$(SED) -i 's#\(gomod: "github.com/SumoLogic/sumologic-otel-collector/.*\) v0.0.0-00010101000000-000000000000#\1 ${TAG}#g' \
otelcolbuilder/.otelcol-builder.yaml
# Make sure to work with both tags starting not starting with v.
$(SED) -i 's#\(gomod: "github.com/SumoLogic/sumologic-otel-collector/.*\) \([^v].*\)#\1 v\2#g' \
otelcolbuilder/.otelcol-builder.yaml
################################################################################
# Build
################################################################################
.PHONY: build
build:
@$(MAKE) -C ./otelcolbuilder/ build
.PHONY: install-builder
install-builder:
@$(MAKE) -C ./otelcolbuilder/ install-builder
BUILD_TAG ?= latest
BUILD_CACHE_TAG = latest-builder-cache
IMAGE_NAME = sumologic-otel-collector
IMAGE_NAME_DEV = sumologic-otel-collector-dev
OPENSOURCE_ECR_URL = public.ecr.aws/sumologic
OPENSOURCE_REPO_URL = $(OPENSOURCE_ECR_URL)/$(IMAGE_NAME)
OPENSOURCE_REPO_URL_DEV = $(OPENSOURCE_ECR_URL)/$(IMAGE_NAME_DEV)
.PHONY: _build
_build:
DOCKER_BUILDKIT=1 docker build \
--file $(DOCKERFILE) \
--build-arg BUILD_TAG=$(TAG) \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--tag $(IMG):$(TAG) \
.
.PHONY: build-container-local
build-container-local:
$(MAKE) _build \
IMG="$(IMAGE_NAME)-local" \
DOCKERFILE="Dockerfile_local" \
TAG="$(BUILD_TAG)"
.PHONY: build-container-dev
build-container-dev:
$(MAKE) _build \
IMG="$(IMAGE_NAME)-dev" \
DOCKERFILE="Dockerfile_dev" \
TAG="$(BUILD_TAG)"
#-------------------------------------------------------------------------------
# dev
.PHONY: _build-container-multiplatform-dev
_build-container-multiplatform-dev:
BUILD_TAG="$(BUILD_TAG)" \
REPO_URL="$(OPENSOURCE_REPO_URL_DEV)" \
DOCKERFILE="Dockerfile_dev" \
PLATFORM="$(PLATFORM)" \
./ci/build-push-multiplatform.sh $(PUSH)
.PHONY: build-container-multiplatform-dev
build-container-multiplatform-dev:
$(MAKE) _build-container-multiplatform-dev PUSH=
.PHONY: build-container-multiplatform-dev
build-push-container-multiplatform-dev:
$(MAKE) _build-container-multiplatform-dev PUSH=--push
.PHONY: push-container-manifest-dev
push-container-manifest-dev:
BUILD_TAG="$(BUILD_TAG)" \
REPO_URL="$(OPENSOURCE_REPO_URL_DEV)" \
./ci/push_docker_multiplatform_manifest.sh $(PLATFORMS)
# release
.PHONY: _build-container-multiplatform
_build-container-multiplatform:
BUILD_TAG="$(BUILD_TAG)" \
REPO_URL="$(OPENSOURCE_REPO_URL)" \
DOCKERFILE="Dockerfile" \
PLATFORM="$(PLATFORM)" \
./ci/build-push-multiplatform.sh $(PUSH)
.PHONY: build-container-multiplatform
build-container-multiplatform:
$(MAKE) _build-container-multiplatform PUSH=
.PHONY: build-push-container-multiplatform
build-push-container-multiplatform:
$(MAKE) _build-container-multiplatform PUSH=--push
.PHONY: test-built-image
test-built-image:
docker run --rm "$(OPENSOURCE_REPO_URL):$(BUILD_TAG)" --version
.PHONY: push-container-manifest
push-container-manifest:
BUILD_TAG="$(BUILD_TAG)" \
REPO_URL="$(OPENSOURCE_REPO_URL)" \
./ci/push_docker_multiplatform_manifest.sh $(PLATFORMS)
#-------------------------------------------------------------------------------
.PHONY: _login
_login:
aws ecr-public get-login-password --region us-east-1 \
| docker login --username AWS --password-stdin $(ECR_URL)
.PHONY: login
login:
$(MAKE) _login \
ECR_URL="$(OPENSOURCE_ECR_URL)"
#-------------------------------------------------------------------------------
# vagrant
.PHONY: vagrant-up
vagrant-up:
vagrant up
.PHONY: vagrant-ssh
vagrant-ssh:
vagrant ssh -c 'cd /sumologic; exec "$$SHELL"'
.PHONY: vagrant-destroy
vagrant-destroy:
vagrant destroy -f
.PHONY: vagrant-halt
vagrant-halt:
vagrant halt