-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
305 lines (262 loc) · 12.5 KB
/
Copy pathMakefile
File metadata and controls
305 lines (262 loc) · 12.5 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
.DEFAULT_GOAL := help
.PHONY: api build build-agent-binary build-agent-tools build-binary business-docx install-agent uninstall-agent test test-help test-doctor test-unit test-functional test-detection test-performance test-distribution test-release test-opensearch-lifecycle test-business-docx up deploy down status reset clean clean-bin pki auth-init doctor release release-rc release-stable check-github-release-inputs web-install web-dev web-up web-build web-preview web-status web-stop help
PROTO_FILES := $(shell find api/proto -name '*.proto' | sort)
GOCACHE ?= /tmp/sysarmor-go-cache
GOBIN_PATH := $(shell go env GOPATH)/bin
BIN_DIR ?= dist/bin
RELEASE_DIR ?= dist/release
BUSINESS_DOCX_SOURCE ?= docs/business/sysarmor-project-proposal.zh-CN.md
BUSINESS_DOCX_OUTPUT ?= dist/docs/sysarmor-project-proposal.zh-CN.docx
PACKAGE_BASE_URL ?= http://packages
RELEASE_VERSION ?= dev
RELEASE_OS ?= linux
RELEASE_ARCH ?= amd64
RELEASE_CHANNELS ?= dev-agent linux-systemd-dev linux-container-dev
RELEASE_AGENT_BIN ?= $(BIN_DIR)/sysarmor-agent
RELEASE_SIGNING_KEY ?= $(PKI_RUNTIME_DIR)/artifact-signing-key.pem
RELEASE_PUBLIC_KEY ?= $(PKI_RUNTIME_DIR)/artifact-public.pem
TETRAGON_ARCHIVE_CANDIDATE := $(firstword $(wildcard .cache/tetragon-v1.7.0-amd64.tar.gz .scratchpad/.cache/tetragon-v1.7.0-amd64.tar.gz))
TETRAGON_ARCHIVE ?= $(or $(SYSARMOR_TETRAGON_ARCHIVE),$(if $(TETRAGON_ARCHIVE_CANDIDATE),$(abspath $(TETRAGON_ARCHIVE_CANDIDATE))))
# Preserve release inputs as data instead of recursively expanding Make syntax.
override VERSION := $(value VERSION)
override RC := $(value RC)
export VERSION RC
FUNCTIONAL_TARGET_endpoint := functional-endpoint
FUNCTIONAL_TARGET_platform := functional-platform
FUNCTIONAL_TARGET_topology := functional-topology
FUNCTIONAL_TARGET_all := functional-core
FUNCTIONAL_TARGET := $(FUNCTIONAL_TARGET_$(DOMAIN))
PERFORMANCE_TARGET_endpoint := performance-endpoint
PERFORMANCE_TARGET_platform := performance-platform
PERFORMANCE_TARGET_modules := performance-modules
PERFORMANCE_TARGET_all := performance-endpoint performance-platform performance-modules
PERFORMANCE_TARGET := $(PERFORMANCE_TARGET_$(DOMAIN))
DISTRIBUTION_TARGET_local := distribution-package
DISTRIBUTION_TARGET_published := distribution-published
DISTRIBUTION_TARGET := $(DISTRIBUTION_TARGET_$(SOURCE))
RELEASE_TARGET_pre-publish := release-candidate
RELEASE_TARGET_post-publish := release-published
RELEASE_TARGET := $(RELEASE_TARGET_$(STAGE))
PROFILE ?= quick
WORKLOAD ?= business-normal
SCENARIO ?=
POLICIES ?=
COMPOSE ?= docker compose
PLATFORM_COMPOSE ?= deployments/compose.platform.yaml
PKI_RUNTIME_DIR ?= deployments/pki/agent-plane-mtls/runtime
WEB_DIR ?= web/manager
WEB_HOST ?= 127.0.0.1
WEB_DEV_PORT ?= 5173
WEB_PREVIEW_PORT ?= 4173
WEB_DEV_FLAGS ?= --webpack
WEB_RUN_DIR ?= .run
WEB_LOG ?= $(WEB_RUN_DIR)/manager-console.log
WEB_PID ?= $(WEB_RUN_DIR)/manager-console.pid
api:
PATH="$(GOBIN_PATH):$$PATH" protoc --go_out=. --go_opt=paths=source_relative $(PROTO_FILES)
PATH="$(GOBIN_PATH):$$PATH" protoc --go-grpc_out=. --go-grpc_opt=paths=source_relative $(PROTO_FILES)
build:
@if [ -z "$(SERVICE)" ]; then \
echo "usage: make build SERVICE=manager"; \
exit 2; \
elif [ "$(SERVICE)" = "packages" ]; then \
echo "service packages uses image nginx:alpine; no build needed"; \
else \
$(COMPOSE) -f $(PLATFORM_COMPOSE) build $(SERVICE); \
fi
build-agent-binary:
mkdir -p $(BIN_DIR)
CGO_ENABLED=0 GOCACHE=$(GOCACHE) go build -o $(BIN_DIR)/sysarmor-agent ./cmd/sysarmor-agent
build-agent-tools: build-agent-binary
CGO_ENABLED=0 GOCACHE=$(GOCACHE) go build -o $(BIN_DIR)/sysarmorctl ./cmd/sysarmorctl
CGO_ENABLED=0 GOCACHE=$(GOCACHE) go build -o $(BIN_DIR)/sysarmor-content-sign ./cmd/sysarmor-content-sign
install-agent: build-agent-tools
sudo SYSARMOR_AGENT_BIN=$(BIN_DIR)/sysarmor-agent SYSARMOR_CTL_BIN=$(BIN_DIR)/sysarmorctl SYSARMOR_CONTENT_SIGN_BIN=$(BIN_DIR)/sysarmor-content-sign deployments/agent/install-agent.sh
uninstall-agent:
sudo systemctl disable --now sysarmor-agent 2>/dev/null || true
sudo rm -f /etc/systemd/system/sysarmor-agent.service /usr/local/bin/sysarmorctl
sudo rm -rf /opt/sysarmor/agent /run/sysarmor/agent
@if [ "$(PURGE)" = "1" ]; then sudo rm -rf /etc/sysarmor/agent /var/lib/sysarmor/agent; fi
sudo systemctl daemon-reload
build-binary: build-agent-binary
CGO_ENABLED=0 GOCACHE=$(GOCACHE) go build -o $(BIN_DIR)/sysarmor-gateway ./cmd/sysarmor-gateway
CGO_ENABLED=0 GOCACHE=$(GOCACHE) go build -o $(BIN_DIR)/sysarmor-manager ./cmd/sysarmor-manager
CGO_ENABLED=0 GOCACHE=$(GOCACHE) go build -o $(BIN_DIR)/sysarmor-worker ./cmd/sysarmor-worker
CGO_ENABLED=0 GOCACHE=$(GOCACHE) go build -o $(BIN_DIR)/sysarmorctl ./cmd/sysarmorctl
CGO_ENABLED=0 GOCACHE=$(GOCACHE) go build -o $(BIN_DIR)/sysarmor-content-sign ./cmd/sysarmor-content-sign
business-docx:
bash tools/docs/build-business-docx.sh "$(BUSINESS_DOCX_SOURCE)" "$(BUSINESS_DOCX_OUTPUT)"
test:
CGO_ENABLED=0 GOCACHE=$(GOCACHE) go test ./...
test-help:
$(MAKE) -C test help
test-doctor:
$(MAKE) -C test doctor SYSARMOR_TETRAGON_ARCHIVE="$(TETRAGON_ARCHIVE)"
test-unit:
$(MAKE) -C test test-unit
test-functional:
ifeq ($(FUNCTIONAL_TARGET),)
@echo "usage: make test-functional DOMAIN=endpoint|platform|topology|all" >&2
@exit 2
else
$(MAKE) -C test $(FUNCTIONAL_TARGET) SYSARMOR_TETRAGON_ARCHIVE="$(TETRAGON_ARCHIVE)"
endif
test-detection:
$(MAKE) -C test detection-topology SYSARMOR_TETRAGON_ARCHIVE="$(TETRAGON_ARCHIVE)"
test-performance:
ifeq ($(PERFORMANCE_TARGET),)
@echo "usage: make test-performance DOMAIN=endpoint|platform|modules|all" >&2
@exit 2
else
$(MAKE) -C test $(PERFORMANCE_TARGET) \
SYSARMOR_TETRAGON_ARCHIVE="$(TETRAGON_ARCHIVE)" \
SYSARMOR_BENCH_PROFILE=$(PROFILE) \
SYSARMOR_BENCH_WORKLOAD=$(WORKLOAD) \
SYSARMOR_BENCH_SCENARIO=$(SCENARIO) \
SYSARMOR_BENCH_POLICIES="$(POLICIES)"
endif
test-distribution:
ifeq ($(DISTRIBUTION_TARGET),)
@echo "usage: make test-distribution SOURCE=local|published" >&2
@exit 2
else
$(MAKE) -C test $(DISTRIBUTION_TARGET)
endif
test-release:
ifeq ($(RELEASE_TARGET),)
@echo "usage: make test-release STAGE=pre-publish|post-publish" >&2
@exit 2
else
$(MAKE) -C test $(RELEASE_TARGET) SYSARMOR_TETRAGON_ARCHIVE="$(TETRAGON_ARCHIVE)"
endif
test-opensearch-lifecycle:
bash test/suites/functional/platform/opensearch-alias-lifecycle.sh
test-business-docx:
bash test/suites/docs/business-docx.sh
pki:
@if [ ! -f "$(PKI_RUNTIME_DIR)/gateway.pem" ] || [ ! -f "$(PKI_RUNTIME_DIR)/gateway-key.pem" ] || [ ! -f "$(PKI_RUNTIME_DIR)/ca.pem" ]; then \
echo "Generating local agent-plane mTLS material in $(PKI_RUNTIME_DIR)"; \
SYSARMOR_GATEWAY_IPS=127.0.0.1 tools/pki/gen-agent-plane-mtls.sh "$(PKI_RUNTIME_DIR)" default agent-prod-001 localhost; \
fi
@bash tools/pki/gen-manager-jwt.sh "$(PKI_RUNTIME_DIR)"
auth-init: pki
@bash tools/auth/init-bootstrap-admin.sh "$(PKI_RUNTIME_DIR)"
doctor:
@PLATFORM_COMPOSE="$(PLATFORM_COMPOSE)" PKI_RUNTIME_DIR="$(PKI_RUNTIME_DIR)" bash tools/doctor.sh
release: build-agent-tools pki
bash deployments/packages/build-release.sh \
--version "$(RELEASE_VERSION)" \
--os "$(RELEASE_OS)" \
--arch "$(RELEASE_ARCH)" \
--output-dir "$(RELEASE_DIR)" \
--base-url "$(PACKAGE_BASE_URL)" \
--channels "$(RELEASE_CHANNELS)" \
--agent-bin "$(RELEASE_AGENT_BIN)" \
--tetragon-archive "$(TETRAGON_ARCHIVE)" \
--signing-key "$(RELEASE_SIGNING_KEY)" \
--public-key "$(RELEASE_PUBLIC_KEY)"
check-github-release-inputs:
@if ! printf '%s\n' "$${VERSION:-}" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$$'; then \
echo "VERSION must use MAJOR.MINOR.PATCH, for example VERSION=1.0.0" >&2; \
exit 2; \
fi
@if ! printf '%s\n' "$${RC:-}" | grep -Eq '^[1-9][0-9]*$$'; then \
echo "RC must be a positive integer, for example RC=1" >&2; \
exit 2; \
fi
@command -v gh >/dev/null 2>&1 || { \
echo "GitHub CLI is required; install gh before publishing" >&2; \
exit 2; \
}
@gh auth status >/dev/null 2>&1 || { \
echo "GitHub CLI is not authenticated; run gh auth login" >&2; \
exit 2; \
}
release-rc: check-github-release-inputs
gh workflow run release-candidate.yml --ref "release/v$${VERSION}" -f "rc_number=$${RC}"
release-stable: check-github-release-inputs
gh workflow run release-stable.yml --ref main -f "version=$${VERSION}" -f "accepted_rc_tag=v$${VERSION}-rc.$${RC}"
up: release auth-init
@if [ -n "$(SERVICE)" ]; then \
$(COMPOSE) -f $(PLATFORM_COMPOSE) up -d --remove-orphans $(SERVICE); \
else \
$(COMPOSE) -f $(PLATFORM_COMPOSE) up -d --remove-orphans; \
fi
deploy: build-binary release auth-init
$(COMPOSE) -f $(PLATFORM_COMPOSE) up -d --build --remove-orphans
down:
@if [ -n "$(SERVICE)" ]; then \
$(COMPOSE) -f $(PLATFORM_COMPOSE) stop $(SERVICE); \
$(COMPOSE) -f $(PLATFORM_COMPOSE) rm -f $(SERVICE); \
else \
$(COMPOSE) -f $(PLATFORM_COMPOSE) down --remove-orphans; \
fi
status:
@if [ -n "$(SERVICE)" ]; then \
$(COMPOSE) -f $(PLATFORM_COMPOSE) ps $(SERVICE); \
else \
$(COMPOSE) -f $(PLATFORM_COMPOSE) ps; \
fi
clean:
$(COMPOSE) -f $(PLATFORM_COMPOSE) down -v --remove-orphans
reset: clean up status
clean-bin:
rm -rf $(BIN_DIR)
web-install:
cd $(WEB_DIR) && pnpm install
web-dev:
cd $(WEB_DIR) && pnpm exec next dev $(WEB_DEV_FLAGS) --hostname $(WEB_HOST) --port $(WEB_DEV_PORT)
web-up: web-build
@WEB_DIR="$(CURDIR)/$(WEB_DIR)" WEB_HOST="$(WEB_HOST)" WEB_DEV_PORT="$(WEB_DEV_PORT)" WEB_PREVIEW_PORT="$(WEB_PREVIEW_PORT)" WEB_MODE=preview WEB_RUN_DIR="$(CURDIR)/$(WEB_RUN_DIR)" bash tools/web-console.sh up
web-build:
cd $(WEB_DIR) && pnpm build
web-preview: web-build
cd $(WEB_DIR) && pnpm start --hostname $(WEB_HOST) --port $(WEB_PREVIEW_PORT)
web-status:
@WEB_HOST="$(WEB_HOST)" WEB_DEV_PORT="$(WEB_DEV_PORT)" WEB_PREVIEW_PORT="$(WEB_PREVIEW_PORT)" WEB_RUN_DIR="$(CURDIR)/$(WEB_RUN_DIR)" bash tools/web-console.sh status
web-stop:
@WEB_HOST="$(WEB_HOST)" WEB_DEV_PORT="$(WEB_DEV_PORT)" WEB_PREVIEW_PORT="$(WEB_PREVIEW_PORT)" WEB_RUN_DIR="$(CURDIR)/$(WEB_RUN_DIR)" bash tools/web-console.sh stop
help:
@echo "SysArmor project commands:"
@echo " make api generate protobuf code"
@echo " make build SERVICE=manager build a compose service image"
@echo " make build-binary build agent/gateway/manager/worker/sysarmorctl"
@echo " make business-docx build formal proposal DOCX under dist/docs/"
@echo " make install-agent build and install a standalone Agent plus sysarmorctl"
@echo " make uninstall-agent remove binaries; add PURGE=1 to remove config and local data"
@echo " make test run Go tests"
@echo " make release build a local signed agent package and index"
@echo " make release-rc VERSION=1.0.0 RC=1 publish v1.0.0-rc.1"
@echo " make release-stable VERSION=1.0.0 RC=1 publish v1.0.0 from the accepted RC"
@echo " make up build release and start local platform"
@echo " make up SERVICE=packages build release and start one service"
@echo " make deploy build release, build images, and start local platform"
@echo " make down stop local platform"
@echo " make down SERVICE=packages stop and remove one service"
@echo " make status show local platform service status"
@echo " make reset DESTRUCTIVE: recreate data volumes and platform; preserve PKI"
@echo " make auth-init create bootstrap admin and BFF secrets once"
@echo " make doctor verify secrets, services, login, BFF, and Manager"
@echo " make clean stop local platform and remove volumes/orphans"
@echo " make clean-bin remove built binaries"
@echo ""
@echo "Web console:"
@echo " make web-install install web dependencies"
@echo " make web-dev start manager console dev server"
@echo " make web-up build and start manager console preview in background"
@echo " make web-build build manager console"
@echo " make web-preview build and preview manager console"
@echo " make web-status show manager console dev/preview status"
@echo " make web-stop stop manager console dev/preview server"
@echo " WEB_DEV_FLAGS= make web-dev use Next.js default dev bundler"
@echo ""
@echo "Test suites:"
@echo " make test-help show all test suite commands"
@echo " make test-doctor verify the complete test environment"
@echo " make test-unit run local Go tests"
@echo " make test-functional DOMAIN=endpoint|platform|topology|all"
@echo " make test-detection run truth-labeled detection tests"
@echo " make test-performance DOMAIN=endpoint|platform|modules|all PROFILE=medium"
@echo " make test-distribution SOURCE=local|published URL=https://..."
@echo " make test-release STAGE=pre-publish|post-publish URL=https://..."
@echo " make test-business-docx validate the formal proposal DOCX build"