-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (91 loc) · 2.43 KB
/
Copy pathMakefile
File metadata and controls
110 lines (91 loc) · 2.43 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
## --- Versionierung (ENV hat Vorrang, sonst Fallbacks) ---
VERSION ?= "2.0.0"
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
DATE ?= "2026-05-15"
IMAGE ?= bodsch/probe-service
NOCACHE := "--cache"
# ---- config ----
BIN := probe-service
CMD := ./cmd/probe-service
GO ?= go
GOFLAGS ?= -trimpath -buildvcs=true
LDFLAGS := -s -w \
-X 'main.version=$(VERSION)' \
-X 'main.commit=$(COMMIT)' \
-X 'main.date=$(DATE)'
TAGS ?=
# Cross Build (anpassbar)
PLATFORMS ?= linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
# ---- helpers ----
define build_target
@echo ">> build $(1)"
@GOOS=$(word 1,$(subst /, ,$(1))) GOARCH=$(word 2,$(subst /, ,$(1))) \
$(GO) build $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o dist/$(BIN)-$(subst /,-,$(1)) $(CMD)
endef
# ---- default ----
.PHONY: all
all: deps fmt vet build
.PHONY: deps
deps:
$(GO) mod tidy
$(GO) mod download all
# ---- quality ----
.PHONY: fmt
fmt:
$(GO) fmt ./...
.PHONY: vet
vet:
$(GO) vet ./...
.PHONY: tidy
tidy:
$(GO) mod tidy
.PHONY: test
test:
$(GO) test ./...
.PHONY: race
race:
$(GO) test ./... -race
# ---- build/run ----
.PHONY: build
build:
@mkdir -p bin
$(GO) build $(GOFLAGS) -ldflags '$(LDFLAGS)' -o bin/$(BIN) $(CMD)
.PHONY: run
run: build
./bin/$(BIN)
.PHONY: clean
clean:
@rm -rf bin dist
.PHONY: print-version
print-version:
@echo "version=$(VERSION) commit=$(COMMIT) date=$(DATE)"
.PHONY: container
container:
docker buildx build --platform linux/amd64 --tag ${IMAGE}:${VERSION} .
.PHONY: run-container
run-container:
docker run -ti --rm -e DEBUG_ENTRYPOINT="false" -e SERVICE_NAME="caefeeder" ${IMAGE}:${VERSION}
# ---- release ----
.PHONY: release
release:
@set -e
@mkdir -p dist
@for p in $(PLATFORMS); do \
GOOS=$${p%/*}; GOARCH=$${p#*/}; \
echo ">> build $$GOOS/$$GOARCH"; \
BIN="dist/gallery_$${GOOS}_$${GOARCH}"; \
[ "$$GOOS" = "windows" ] && BIN="$${BIN}.exe"; \
CGO_ENABLED=0 GOOS=$$GOOS GOARCH=$$GOARCH \
go build -trimpath -buildvcs=true -ldflags '$(LDFLAGS)' \
-o "$$BIN" ./cmd/gallery; \
done
# ---- help ----
.PHONY: help
help:
@echo "Targets:"
@echo " make build # baut ./bin/$(BIN)"
@echo " make run # startet mit -config $(CONFIG)"
@echo " make test # Unit-Tests"
@echo " make release # Cross-Build in ./dist"
@echo " make fmt vet tidy # Pflege"
@echo " make clean # räumt auf"