Skip to content

Commit ea6e32a

Browse files
authored
Switch to new tools management from Go 1.24+ (#48)
Go 1.24 [added](https://go.dev/doc/go1.14#tools) pretty net feature that simplify Go-based tools management in projects. The best intro I read so far is https://www.alexedwards.net/blog/how-to-manage-tool-dependencies-in-go-1.24-plus
1 parent 969195e commit ea6e32a

6 files changed

Lines changed: 1057 additions & 119 deletions

File tree

Makefile

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,52 @@ SERVICE_NAME := otel-collector
55
SERVICE_VERSION := 0.5-$(shell git rev-parse --short HEAD)
66
SERVICE_IMAGE := $(BASE_IMAGE_NAME)/$(SERVICE_NAME):$(SERVICE_VERSION)
77

8-
OTELCOL_VERSION := 0.120.0
9-
108
KO_DOCKER_REPO := ghcr.io/zmoog/otel-collector-contrib
119

1210
# ==============================================================================
1311
# Define targets
1412

15-
BUILD_DIR ?= _build
16-
export GOBIN = $(shell realpath $(BUILD_DIR))/_bin
13+
# BUILD_DIR ?= _build
14+
# export GOBIN = $(shell realpath $(BUILD_DIR))/_bin
1715

18-
$(BUILD_DIR):
19-
@mkdir -p $(BUILD_DIR)
16+
# $(BUILD_DIR):
17+
# @mkdir -p $(BUILD_DIR)
2018

21-
$(GOBIN): tools/go.mod
22-
cd tools && go install go.opentelemetry.io/collector/cmd/mdatagen
23-
cd tools && go install go.opentelemetry.io/collector/cmd/builder
24-
cd tools && go install golang.org/x/tools/cmd/goimports
25-
cd tools && go install honnef.co/go/tools/cmd/staticcheck
19+
# $(GOBIN): tools/go.mod
20+
# cd tools && go install go.opentelemetry.io/collector/cmd/mdatagen
21+
# cd tools && go install go.opentelemetry.io/collector/cmd/builder
22+
# cd tools && go install golang.org/x/tools/cmd/goimports
23+
# cd tools && go install honnef.co/go/tools/cmd/staticcheck
2624

2725

2826
.PHONY: generate
29-
generate: $(GOBIN)
27+
generate:
3028
# look inside the receiver directory
3129
# and run mdatagen against the metadata.yaml
3230
# found there
33-
find receiver -name go.mod -execdir $(GOBIN)/mdatagen metadata.yaml \;
31+
find receiver -name go.mod -execdir go tool mdatagen metadata.yaml \;
3432

3533
.PHONY: staticcheck
36-
staticcheck: $(GOBIN)
34+
staticcheck:
3735
# run staticcheck for all go
3836
# directories that have a go.mod
3937
# file present
40-
find . -name go.mod -execdir $(GOBIN)/staticcheck ./... \;
38+
find . -name go.mod -execdir go tool staticcheck ./... \;
4139

4240
.PHONY: fmt
43-
fmt: $(GOBIN)
44-
$(GOBIN)/goimports -local github.com/zmoog/ -w .
41+
fmt:
42+
go tool goimports -local github.com/zmoog/ -w .
4543

4644
.PHONY: generate-otelcol
47-
generate-otelcol: $(GOBIN)
48-
cd collector && $(GOBIN)/builder --config builder-config.yaml
45+
generate-otelcol:
46+
cd collector && go tool builder --config builder-config.yaml
4947

5048
.PHONY: run
5149
run:
5250
cd collector/otelcol && ./otelcol --config ../../config.yaml
5351

5452
.PHONY: service
55-
service: $(GOBIN)
56-
cd collector/otelcol && KO_DOCKER_REPO=$(KO_DOCKER_REPO) $(GOBIN)/ko build . \
53+
service:
54+
cd collector/otelcol && KO_DOCKER_REPO=$(KO_DOCKER_REPO) go tool ko build . \
5755
--platform=linux/amd64,linux/arm64 \
5856
--bare

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ use (
55
./receiver/toggltrackreceiver
66
./receiver/wavinsentioreceiver
77
./receiver/zcsazzurroreceiver
8+
./tools
89
)

0 commit comments

Comments
 (0)