forked from aws-observability/aws-otel-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
189 lines (149 loc) · 6.84 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
-include .env
AOC_IMPORT_PATH=github.com/aws-observability/aws-otel-collector
VERSION := $(shell cat VERSION)
PROJECTNAME := $(shell basename "$(PWD)")
GIT_SHA=$(shell git rev-parse HEAD)
DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
# All source code excluding any third party code and excluding the testbed.
# This is the code that we want to run tests for and lint, staticcheck, etc.
ALL_SRC := $(shell find . -name '*.go' \
-not -path './testbed/*' \
-not -path '*/third_party/*' \
-not -path './.github/*' \
-not -path './pkg/devexporter/*' \
-not -path './pkg/lambdacomponents/*' \
-not -path './bin/*' \
-not -path './build/*' \
-not -path './tools/linters/*' \
-not -path './tools/release/*' \
-not -path './e2etest/clean/*' \
-type f | sort)
# ALL_PKGS is the list of all packages where ALL_SRC files reside.
ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC))))
# ALL_MODULES includes ./* dirs (excludes . dir)
ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort | egrep '^./' )
GOTEST_OPT?= -short -coverprofile coverage.txt -v -race -timeout 180s
GOTEST=go test
BUILD_INFO_IMPORT_PATH=$(AOC_IMPORT_PATH)/tools/version
GOBUILD=GO111MODULE=on CGO_ENABLED=0 installsuffix=cgo go build -trimpath
# Use linker flags to provide version/build settings
LDFLAGS=-ldflags "-s -w -X $(BUILD_INFO_IMPORT_PATH).GitHash=$(GIT_SHA) \
-X github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter.collectorDistribution=aws-otel-collector \
-X github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter.collectorDistribution=aws-otel-collector \
-X $(BUILD_INFO_IMPORT_PATH).Version=$(VERSION) -X $(BUILD_INFO_IMPORT_PATH).Date=$(DATE)"
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
DOCKER_NAMESPACE=amazon
COMPONENT=awscollector
TOOLS_MOD_DIR := $(abspath ./tools/linters)
TOOLS_BIN_DIR := $(abspath ./bin)
GOIMPORTS_OPT?= -w -local $(AOC_IMPORT_PATH)
GOIMPORTS = $(TOOLS_BIN_DIR)/goimports
MULTIMOD = $(TOOLS_BIN_DIR)/multimod
$(TOOLS_BIN_DIR)/multimod: $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum $(TOOLS_MOD_DIR)/tools.go
cd $(TOOLS_MOD_DIR) && \
go build -o $(TOOLS_BIN_DIR)/multimod go.opentelemetry.io/build-tools/multimod
STATIC_CHECK = $(TOOLS_BIN_DIR)/staticcheck
$(TOOLS_BIN_DIR)/staticcheck: $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum $(TOOLS_MOD_DIR)/tools.go
cd $(TOOLS_MOD_DIR) && \
GOBIN=$(TOOLS_BIN_DIR) go install honnef.co/go/tools/cmd/[email protected]
LINT = $(TOOLS_BIN_DIR)/golangci-lint
$(TOOLS_BIN_DIR)/golangci-lint: $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum $(TOOLS_MOD_DIR)/tools.go
cd $(TOOLS_MOD_DIR) && \
GOBIN=$(TOOLS_BIN_DIR) go install github.com/golangci/golangci-lint/cmd/[email protected]
all-modules:
@echo $(ALL_MODULES) | tr ' ' '\n' | sort
all-pkgs:
@echo $(ALL_PKGS) | tr ' ' '\n' | sort
all-srcs:
@echo $(ALL_SRC) | tr ' ' '\n' | sort
.PHONY: build
build: install-tools lint multimod-verify
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o ./build/darwin/aoc_darwin_amd64 ./cmd/awscollector
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o ./build/linux/aoc_linux_x86_64 ./cmd/awscollector
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o ./build/linux/aoc_linux_aarch64 ./cmd/awscollector
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o ./build/windows/aoc_windows_amd64 ./cmd/awscollector
.PHONY: amd64-build
amd64-build: install-tools lint multimod-verify
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o ./build/linux/aoc_linux_x86_64 ./cmd/awscollector
# For building container image during development, no lint nor other platforms
.PHONY: amd64-build-only
amd64-build-only:
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o ./build/linux/aoc_linux_x86_64 ./cmd/awscollector
.PHONY: awscollector
awscollector:
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o ./bin/awscollector_$(GOOS)_$(GOARCH) ./cmd/awscollector
GOOS=windows GOARCH=amd64 EXTENSION=.exe $(GOBUILD) $(LDFLAGS) -o ./bin/windows/aoc_windows_amd64.exe ./cmd/awscollector
.PHONY: package-rpm
package-rpm: build
ARCH=x86_64 DEST=build/packages/linux/amd64 tools/packaging/linux/create_rpm.sh
.PHONY: package-deb
package-deb: build
ARCH=amd64 TARGET_SUPPORTED_ARCH=x86_64 DEST=build/packages/debian/amd64 tools/packaging/debian/create_deb.sh
ARCH=arm64 TARGET_SUPPORTED_ARCH=aarch64 DEST=build/packages/debian/arm64 tools/packaging/debian/create_deb.sh
.PHONY: docker-build
docker-build: amd64-build
docker build -t $(DOCKER_NAMESPACE)/$(COMPONENT):$(VERSION) -f ./cmd/$(COMPONENT)/Dockerfile .
.PHONY: docker-push
docker-push:
docker push $(DOCKER_NAMESPACE)/$(COMPONENT):$(VERSION)
.PHONY: docker-run
docker-run:
docker run --rm -p 4317:4317 -p 55679:55679 -p 8889:8888 \
-v "${PWD}/config.yaml":/otel-local-config.yaml \
--name awscollector $(DOCKER_NAMESPACE)/$(COMPONENT):$(VERSION) \
--config otel-local-config.yaml; \
.PHONY: docker-compose
docker-compose:
cd examples/docker; docker-compose up -d
.PHONY: docker-stop
docker-stop:
docker stop $(shell docker ps -aq)
.PHONY: test
test:
echo $(ALL_PKGS) | xargs -n 10 $(GOTEST) $(GOTEST_OPT)
.PHONY: fmt
fmt:
go fmt ./...
echo $(ALL_SRC) | xargs -n 10 $(GOIMPORTS) $(GOIMPORTS_OPT)
.PHONY: lint-static-check
lint-static-check: | $(LINT) $(STATIC_CHECK)
@STATIC_CHECK_OUT=`$(STATIC_CHECK) $(ALL_PKGS) 2>&1`; \
if [ "$$STATIC_CHECK_OUT" ]; then \
echo "$(STATIC_CHECK) FAILED => static check errors:\n"; \
echo "$$STATIC_CHECK_OUT\n"; \
exit 1; \
else \
echo "Static check finished successfully"; \
fi
.PHONY: lint
lint: lint-static-check
$(LINT) run --timeout 5m
.PHONY: multimod-verify
multimod-verify: | $(MULTIMOD)
@echo "Validating versions.yaml"
$(MULTIMOD) verify
COREPATH ?="../opentelemetry-collector"
.PHONY: multimod-sync-core
multimod-sync-core: multimod-verify
@[ ! -d COREPATH ] || ( echo ">> Path to core repository must be set in COREPATH and must exist"; exit 1 )
$(MULTIMOD) sync -a -o ${COREPATH}
CONTRIBPATH ?="../opentelemetry-collector-contrib"
.PHONY: multimod-sync-contrib
multimod-sync-contrib: multimod-verify
@[ ! -d CONTRIBPATH ] || ( echo ">> Path to contrib repository must be set in CONTRIBPATH and must exist"; exit 1 )
$(MULTIMOD) sync -a -o ${CONTRIBPATH}
COMMIT ?= "HEAD"
.PHONY: multimod-tags
multimod-tags: multimod-verify
@[ "${MODSET}" ] || ( echo ">> env var MODSET is not set"; exit 1 )
$(MULTIMOD) tag -m ${MODSET} -c ${COMMIT}
.PHONY: install-tools
install-tools:
cd $(TOOLS_MOD_DIR) && GOBIN=$(PWD)/bin go install go.opentelemetry.io/build-tools/multimod
cd $(TOOLS_MOD_DIR) && GOBIN=$(PWD)/bin go install golang.org/x/tools/cmd/goimports
cd $(TOOLS_MOD_DIR) && GOBIN=$(PWD)/bin go install github.com/golangci/golangci-lint/cmd/[email protected]
cd $(TOOLS_MOD_DIR) && GOBIN=$(PWD)/bin go install honnef.co/go/tools/cmd/[email protected]
.PHONY: clean
clean:
rm -rf ./build