Skip to content

Commit 0d31958

Browse files
authored
refactor: mv collector to subpackage (#4424)
Signed-off-by: Krisztian Gacsal <chrisgacsal@users.noreply.github.com>
1 parent 51d616a commit 0d31958

9 files changed

Lines changed: 3073 additions & 2196 deletions

File tree

.github/dependabot.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ version: 2
22

33
updates:
44
- package-ecosystem: gomod
5-
directory: /
5+
directories:
6+
- "/"
7+
- "/collector"
68
open-pull-requests-limit: 10
79
schedule:
810
interval: daily

Makefile

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
22

3+
ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
4+
35
# Docker-local svix secret, only used for testing
46
SVIX_JWT_SECRET = DUMMY_JWT_SECRET
57

@@ -107,29 +109,38 @@ build-dir:
107109
.PHONY: build
108110
build: build-server build-sink-worker build-benthos-collector build-balance-worker build-billing-worker build-notification-service build-jobs ## Build all binaries
109111

112+
COLLECTOR_DIR := $(ROOT_DIR)/collector
113+
COLLECTOR_RELEASE_OUTPUT_DIR := $(ROOT_DIR)/build/release/benthos-collector_$(GOOS)_$(GOARCH)
114+
115+
collector-release-output-dir:
116+
$(if $(GOOS),,$(error GOOS is not set))
117+
$(if $(GOARCH),,$(error GOARCH is not set))
118+
@mkdir -p $(COLLECTOR_RELEASE_OUTPUT_DIR)
119+
110120
# Cross-compile the benthos-collector binary for release archives.
111121
# Usage: make build-benthos-collector-release GOOS=linux GOARCH=amd64 VERSION=v1.2.3
112122
# Produces build/release/benthos-collector_<GOOS>_<GOARCH>/benthos (+ README.md, LICENSE)
113123
.PHONY: build-benthos-collector-release
114-
build-benthos-collector-release: ## Cross-compile benthos-collector for release (set GOOS/GOARCH/VERSION)
124+
build-benthos-collector-release: | collector-release-output-dir ## Cross-compile benthos-collector for release (set GOOS/GOARCH/VERSION)
115125
$(call print-target)
116-
@if [ -z "$(GOOS)" ] || [ -z "$(GOARCH)" ]; then echo "ERROR: GOOS and GOARCH are required"; exit 1; fi
117-
@version="$${VERSION:-unknown}" && \
118-
outdir="build/release/benthos-collector_$(GOOS)_$(GOARCH)" && \
119-
rm -rf "$$outdir" && mkdir -p "$$outdir" && \
126+
$(if $(GOOS),,$(error GOOS is not set))
127+
$(if $(GOARCH),,$(error GOARCH is not set))
128+
@rm -rf "$(COLLECTOR_RELEASE_OUTPUT_DIR)"/* && \
120129
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) \
121-
go build -trimpath \
122-
-ldflags "-s -w -X main.version=$${version}" \
123-
-o "$$outdir/benthos" ./cmd/benthos-collector && \
124-
cp README.md LICENSE "$$outdir/"
130+
go build -C $(COLLECTOR_DIR) -trimpath \
131+
-ldflags "-s -w -X main.version=$(or $(VERSION),unknown)" \
132+
-o "$(COLLECTOR_RELEASE_OUTPUT_DIR)/benthos" ./cmd && \
133+
cp README.md LICENSE "$(COLLECTOR_RELEASE_OUTPUT_DIR)/"
134+
135+
COLLECTOR_RELEASE_NAME := benthos-collector_$(GOOS)_$(GOARCH)
125136

126137
# Produces build/release/benthos-collector_<GOOS>_<GOARCH>.tar.gz from the directory above.
127138
.PHONY: archive-benthos-collector-release
128139
archive-benthos-collector-release: ## Archive the cross-compiled benthos-collector (set GOOS/GOARCH)
129140
$(call print-target)
130-
@if [ -z "$(GOOS)" ] || [ -z "$(GOARCH)" ]; then echo "ERROR: GOOS and GOARCH are required"; exit 1; fi
131-
@name="benthos-collector_$(GOOS)_$(GOARCH)" && \
132-
tar -C build/release -czf "build/release/$${name}.tar.gz" "$$name"
141+
$(if $(GOOS),,$(error GOOS is not set))
142+
$(if $(GOARCH),,$(error GOARCH is not set))
143+
@tar -C build/release -czf "build/release/$(COLLECTOR_RELEASE_NAME).tar.gz" "$(COLLECTOR_RELEASE_NAME)"
133144

134145
.PHONY: build-server
135146
build-server: | build-dir ## Build server binary
@@ -144,7 +155,7 @@ build-sink-worker: | build-dir ## Build sink-worker binary
144155
.PHONY: build-benthos-collector
145156
build-benthos-collector: | build-dir ## Build benthos collector binary
146157
$(call print-target)
147-
go build -o build/benthos-collector ${GO_BUILD_FLAGS} ./cmd/benthos-collector
158+
go build -C $(COLLECTOR_DIR) -o ../build/benthos-collector ${GO_BUILD_FLAGS} ./cmd
148159

149160
.PHONY: build-balance-worker
150161
build-balance-worker: | build-dir ## Build balance-worker binary

benthos-collector.Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ RUN --mount=type=cache,target=/go/pkg/mod \
1919
--mount=type=cache,target=/go/cache \
2020
go mod download -x
2121

22+
COPY --link collector/go.mod collector/go.sum ./collector/
23+
24+
RUN --mount=type=cache,target=/go/pkg/mod \
25+
--mount=type=cache,target=/go/cache \
26+
go mod download -C ./collector -x
27+
2228
ARG VERSION
2329

2430
COPY --link . .
@@ -27,7 +33,7 @@ RUN chmod +x entrypoint.sh
2733

2834
RUN --mount=type=cache,target=/go/pkg/mod \
2935
--mount=type=cache,target=/go/cache \
30-
go build -ldflags "-X main.version=${VERSION}" -o /usr/local/bin/benthos ./cmd/benthos-collector
36+
go build -C ./collector -ldflags "-X main.version=${VERSION}" -o /usr/local/bin/benthos ./cmd
3137

3238
FROM alpine:3.23.4@sha256:5b10f432ef3da1b8d4c7eb6c487f2f5a8f096bc91145e68878dd4a5019afde11
3339

collector/go.mod

Lines changed: 479 additions & 0 deletions
Large diffs are not rendered by default.

collector/go.sum

Lines changed: 2524 additions & 0 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 20 additions & 332 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 16 additions & 1849 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)