-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
211 lines (168 loc) · 7.11 KB
/
Makefile
File metadata and controls
211 lines (168 loc) · 7.11 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
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
.PHONY: all build server agent sign clean test lint run-server run-agent help
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
SERVER_BINARY=./out/gitmdm-server
AGENT_BINARY=./out/gitmdm-agent
SIGN_BINARY=./out/gitmdm-sign
SERVER_PATH=./cmd/server
AGENT_PATH=./cmd/agent
SIGN_PATH=./cmd/sign
BUILD_FLAGS=-ldflags="-s -w" -trimpath
all: build
build: server agent sign
server:
$(GOBUILD) $(BUILD_FLAGS) -o $(SERVER_BINARY) $(SERVER_PATH)
agent:
$(GOBUILD) $(BUILD_FLAGS) -o $(AGENT_BINARY) $(AGENT_PATH)
sign:
$(GOBUILD) $(BUILD_FLAGS) -o $(SIGN_BINARY) $(SIGN_PATH)
clean:
$(GOCLEAN)
rm -f $(SERVER_BINARY)
rm -f $(AGENT_BINARY)
rm -f $(SIGN_BINARY)
test:
$(GOTEST) -v ./...
deps:
$(GOMOD) download
$(GOMOD) tidy
run-server: server
$(SERVER_BINARY) -git=/tmp/gitmdm-repo
run-agent: agent
$(AGENT_BINARY) -server=http://localhost:8080
build-linux:
GOOS=linux GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(SERVER_BINARY)-linux-amd64 $(SERVER_PATH)
GOOS=linux GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(AGENT_BINARY)-linux-amd64 $(AGENT_PATH)
build-darwin:
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(SERVER_BINARY)-darwin-amd64 $(SERVER_PATH)
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(AGENT_BINARY)-darwin-amd64 $(AGENT_PATH)
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(BUILD_FLAGS) -o $(SERVER_BINARY)-darwin-arm64 $(SERVER_PATH)
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(BUILD_FLAGS) -o $(AGENT_BINARY)-darwin-arm64 $(AGENT_PATH)
build-freebsd:
GOOS=freebsd GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(SERVER_BINARY)-freebsd-amd64 $(SERVER_PATH)
GOOS=freebsd GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(AGENT_BINARY)-freebsd-amd64 $(AGENT_PATH)
build-openbsd:
GOOS=openbsd GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(SERVER_BINARY)-openbsd-amd64 $(SERVER_PATH)
GOOS=openbsd GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(AGENT_BINARY)-openbsd-amd64 $(AGENT_PATH)
build-windows:
GOOS=windows GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(SERVER_BINARY)-windows-amd64.exe $(SERVER_PATH)
GOOS=windows GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(AGENT_BINARY)-windows-amd64.exe $(AGENT_PATH)
GOOS=windows GOARCH=arm64 $(GOBUILD) $(BUILD_FLAGS) -o $(SERVER_BINARY)-windows-arm64.exe $(SERVER_PATH)
GOOS=windows GOARCH=arm64 $(GOBUILD) $(BUILD_FLAGS) -o $(AGENT_BINARY)-windows-arm64.exe $(AGENT_PATH)
build-all: build-linux build-darwin build-freebsd build-openbsd build-windows
ko-build:
ko build --bare ./cmd/server
ko-publish:
ko build ./cmd/server
help:
@echo "Available targets:"
@echo " make build - Build both server and agent"
@echo " make server - Build server binary"
@echo " make agent - Build agent binary"
@echo " make clean - Remove binaries"
@echo " make test - Run tests"
@echo " make lint - Run linters"
@echo " make deps - Download dependencies"
@echo " make run-server - Build and run server locally"
@echo " make run-agent - Build and run agent locally"
@echo " make build-all - Build for all platforms"
@echo " make ko-build - Build server container with ko"
@echo " make ko-publish - Publish server container with ko"
# BEGIN: lint-install .
# http://github.com/codeGROOVE-dev/lint-install
.PHONY: lint
lint: _lint
LINT_ARCH := $(shell uname -m)
LINT_OS := $(shell uname)
LINT_OS_LOWER := $(shell echo $(LINT_OS) | tr '[:upper:]' '[:lower:]')
LINT_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# shellcheck and hadolint lack arm64 native binaries: rely on x86-64 emulation
ifeq ($(LINT_OS),Darwin)
ifeq ($(LINT_ARCH),arm64)
LINT_ARCH=x86_64
endif
endif
LINTERS :=
FIXERS :=
SHELLCHECK_VERSION ?= v0.11.0
SHELLCHECK_BIN := $(LINT_ROOT)/out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)
$(SHELLCHECK_BIN):
mkdir -p $(LINT_ROOT)/out/linters
curl -sSfL -o $@.tar.xz http://github.com/koalaman/shellcheck/releases/download/$(SHELLCHECK_VERSION)/shellcheck-$(SHELLCHECK_VERSION).$(LINT_OS_LOWER).$(LINT_ARCH).tar.xz \
|| echo "Unable to fetch shellcheck for $(LINT_OS)/$(LINT_ARCH): falling back to locally install"
test -f $@.tar.xz \
&& tar -C $(LINT_ROOT)/out/linters -xJf $@.tar.xz \
&& mv $(LINT_ROOT)/out/linters/shellcheck-$(SHELLCHECK_VERSION)/shellcheck $@ \
|| printf "#!/usr/bin/env shellcheck\n" > $@
chmod u+x $@
LINTERS += shellcheck-lint
shellcheck-lint: $(SHELLCHECK_BIN)
$(SHELLCHECK_BIN) $(shell find . -name "*.sh")
FIXERS += shellcheck-fix
shellcheck-fix: $(SHELLCHECK_BIN)
$(SHELLCHECK_BIN) $(shell find . -name "*.sh") -f diff | { read -t 1 line || exit 0; { echo "$$line" && cat; } | git apply -p2; }
GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml
GOLANGCI_LINT_VERSION ?= v2.7.2
GOLANGCI_LINT_BIN := $(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH)
$(GOLANGCI_LINT_BIN):
mkdir -p $(LINT_ROOT)/out/linters
rm -rf $(LINT_ROOT)/out/linters/golangci-lint-*
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LINT_ROOT)/out/linters $(GOLANGCI_LINT_VERSION)
mv $(LINT_ROOT)/out/linters/golangci-lint $@
LINTERS += golangci-lint-lint
golangci-lint-lint: $(GOLANGCI_LINT_BIN)
find . -name go.mod -execdir "$(GOLANGCI_LINT_BIN)" run -c "$(GOLANGCI_LINT_CONFIG)" \;
FIXERS += golangci-lint-fix
golangci-lint-fix: $(GOLANGCI_LINT_BIN)
find . -name go.mod -execdir "$(GOLANGCI_LINT_BIN)" run -c "$(GOLANGCI_LINT_CONFIG)" --fix \;
YAMLLINT_VERSION ?= 1.37.1
YAMLLINT_ROOT := $(LINT_ROOT)/out/linters/yamllint-$(YAMLLINT_VERSION)
YAMLLINT_BIN := $(YAMLLINT_ROOT)/dist/bin/yamllint
$(YAMLLINT_BIN):
mkdir -p $(LINT_ROOT)/out/linters
rm -rf $(LINT_ROOT)/out/linters/yamllint-*
curl -sSfL http://github.com/adrienverge/yamllint/archive/refs/tags/v$(YAMLLINT_VERSION).tar.gz | tar -C $(LINT_ROOT)/out/linters -zxf -
cd $(YAMLLINT_ROOT) && pip3 install --target dist . || pip install --target dist .
LINTERS += yamllint-lint
yamllint-lint: $(YAMLLINT_BIN)
PYTHONPATH=$(YAMLLINT_ROOT)/dist $(YAMLLINT_ROOT)/dist/bin/yamllint .
BIOME_VERSION ?= 2.3.8
BIOME_BIN := $(LINT_ROOT)/out/linters/biome-$(BIOME_VERSION)-$(LINT_ARCH)
BIOME_CONFIG := $(LINT_ROOT)/biome.json
# Map architecture names for Biome downloads
BIOME_ARCH := $(LINT_ARCH)
ifeq ($(LINT_ARCH),x86_64)
BIOME_ARCH := x64
endif
$(BIOME_BIN):
mkdir -p $(LINT_ROOT)/out/linters
rm -rf $(LINT_ROOT)/out/linters/biome-*
curl -sSfL -o $@ http://github.com/biomejs/biome/releases/download/%40biomejs%2Fbiome%40$(BIOME_VERSION)/biome-$(LINT_OS_LOWER)-$(BIOME_ARCH) \
|| echo "Unable to fetch biome for $(LINT_OS_LOWER)/$(BIOME_ARCH), falling back to local install"
test -f $@ || printf "#!/usr/bin/env biome\n" > $@
chmod u+x $@
LINTERS += biome-lint
biome-lint: $(BIOME_BIN)
$(BIOME_BIN) check --config-path=$(BIOME_CONFIG) .
FIXERS += biome-fix
biome-fix: $(BIOME_BIN)
$(BIOME_BIN) check --write --config-path=$(BIOME_CONFIG) .
.PHONY: _lint $(LINTERS)
_lint:
@exit_code=0; \
for target in $(LINTERS); do \
$(MAKE) $$target || exit_code=1; \
done; \
exit $$exit_code
.PHONY: fix $(FIXERS)
fix:
@exit_code=0; \
for target in $(FIXERS); do \
$(MAKE) $$target || exit_code=1; \
done; \
exit $$exit_code
# END: lint-install .