Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (106 loc) · 4.96 KB
/
Copy pathMakefile
File metadata and controls
117 lines (106 loc) · 4.96 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
# Project: DFE Engine
# File: Makefile
# Purpose: CI targets wrapping hyperi-ci
#
# License: BUSL-1.1
# Copyright: (c) 2026 HYPERI PTY LIMITED
.PHONY: quality test build check dev e2e-server e2e-clean
quality:
hyperi-ci run quality
test:
hyperi-ci run test
build:
hyperi-ci run build
check:
hyperi-ci check
# Local dev API server: docs/local-dev.md. The app does not read .env itself.
dev:
@test -f .env || { echo "Create .env first: cp .env.example .env"; exit 1; }
@echo "Swagger UI -> http://localhost:$${DFE_ENGINE_API_PORT:-8003}/docs"
set -a; . ./.env; set +a; \
: "$${DFE_CONFIG_DIR:=./config}"; export DFE_CONFIG_DIR; \
uv run dfe-engine run
# Host-run API for dfe-ui's Playwright suite, wiped on every start: docs/local-dev.md.
E2E_ENV_FILE ?= ./.env.e2e
E2E_WORKSPACE ?= $(CURDIR)/tmp/e2e
E2E_CH_PREFIX := dfe_e2e
E2E_CH_DATA_DB := $(E2E_CH_PREFIX)
E2E_CH_HUNTS_DB := $(E2E_CH_PREFIX)_hunts
E2E_CH_AUDIT_DB := $(E2E_CH_PREFIX)_audit
E2E_CH_OTEL_DB := $(E2E_CH_PREFIX)_otel
# Drops every database under the e2e prefix, which no shared dfe database matches.
define e2e-ch-wipe
ch_host="$${DFE_ENGINE_CLICKHOUSE_HOST:-localhost}"; \
ch_port="$${DFE_ENGINE_CLICKHOUSE_PORT:-8123}"; \
ch_user="$${DFE_ENGINE_CLICKHOUSE_USERNAME:-default}"; \
ch_pass="$${DFE_ENGINE_CLICKHOUSE_PASSWORD}"; \
echo "Dropping ClickHouse $(E2E_CH_PREFIX)* on $$ch_host:$$ch_port"; \
dbs=$$(curl -sf -u "$$ch_user:$$ch_pass" "http://$$ch_host:$$ch_port/" \
--data-binary "SELECT name FROM system.databases WHERE name LIKE '$(E2E_CH_PREFIX)%'"); \
rc=$$?; \
if [ $$rc -eq 22 ]; then \
echo "error: ClickHouse refused the wipe query (curl 22 -- HTTP 4xx/5xx)."; \
echo "Databases from earlier runs may still exist and cannot be cleared."; \
echo "Check DFE_ENGINE_CLICKHOUSE_USERNAME / DFE_ENGINE_CLICKHOUSE_PASSWORD in .env.e2e against"; \
echo "the running server (dfe-docker/.env CLICKHOUSE_PASSWORD; empty is rejected)."; \
exit 1; \
fi; \
if [ $$rc -ne 0 ]; then \
echo "warning: ClickHouse unreachable (curl $$rc); nothing to sweep"; \
dbs=""; \
fi; \
for db in $$dbs; do \
curl -sf -u "$$ch_user:$$ch_pass" "http://$$ch_host:$$ch_port/" \
--data-binary "DROP DATABASE IF EXISTS $$db" \
&& echo " dropped $$db" \
|| { echo "error: could not drop $$db"; exit 1; }; \
done
endef
# A loopback bind on the API port would silently take this 0.0.0.0 server's traffic.
define e2e-port-guard
if command -v lsof >/dev/null 2>&1 && lsof -nP -iTCP:"$$DFE_ENGINE_API_PORT" -sTCP:LISTEN >/dev/null 2>&1; then \
echo "error: something already listens on port $$DFE_ENGINE_API_PORT:"; \
lsof -nP -iTCP:"$$DFE_ENGINE_API_PORT" -sTCP:LISTEN; \
echo "Stop it (e.g. docker stop dfe-engine) or pick another port:"; \
echo " E2E_PORT=8004 make e2e-server"; \
exit 1; \
fi
endef
# The wipe the next e2e-server would do.
e2e-clean:
@test -f "$(E2E_ENV_FILE)" || { echo "Create $(E2E_ENV_FILE) first (copy .env.e2e.example and set DFE_ENGINE_ENV=test)"; exit 1; }
@echo "Removing $(E2E_WORKSPACE)"
set -a; . "$(E2E_ENV_FILE)"; set +a; \
rm -rf "$(E2E_WORKSPACE)"; \
$(e2e-ch-wipe)
e2e-server:
@test -f "$(E2E_ENV_FILE)" || { echo "Create $(E2E_ENV_FILE) first (copy .env.e2e.example and set DFE_ENGINE_ENV=test)"; exit 1; }
@echo "e2e workspace (fresh) -> $(E2E_WORKSPACE)"
@echo "ClickHouse databases -> $(E2E_CH_PREFIX)* (data + audit archive)"
@echo "Swagger UI -> http://localhost:$${E2E_PORT:-8003}/docs (select API or E2E)"
@echo "Playwright ready URL -> DFE_ENGINE_READY_URL=http://127.0.0.1:$${E2E_PORT:-8003}/readyz"
@echo "e2e seed -> POST http://localhost:$${E2E_PORT:-8003}/api/e2e/seed-static"
set -a; . "$(E2E_ENV_FILE)"; set +a; \
if [ -n "$(E2E_NO_CLICKHOUSE)" ]; then \
export DFE_ENGINE_CLICKHOUSE_BOOTSTRAP_TABLES=false DFE_ENGINE_TENANT_ISOLATION_ENABLED=false; \
fi; \
export DFE_ENGINE_API_PORT="$${E2E_PORT:-$${DFE_ENGINE_API_PORT:-8003}}"; \
$(e2e-port-guard); \
if [ -z "$(E2E_KEEP)" ]; then rm -rf "$(E2E_WORKSPACE)"; fi; \
mkdir -p "$(E2E_WORKSPACE)/config" "$(E2E_WORKSPACE)/schemas" \
"$(E2E_WORKSPACE)/schema-fixtures" "$(E2E_WORKSPACE)/secrets"; \
echo "Seeding schema snapshot from the dfe-schemas package (seeds write to schema-fixtures, not this copy)"; \
uv run python -c "import dfe_schemas, shutil, sys; shutil.copytree(dfe_schemas.schemas_root(), sys.argv[1], dirs_exist_ok=True)" "$(E2E_WORKSPACE)/schemas"; \
if [ -z "$(E2E_KEEP)" ] && [ -z "$(E2E_NO_CLICKHOUSE)" ]; then \
$(e2e-ch-wipe); \
fi; \
export DFE_CONFIG_DIR="$(E2E_WORKSPACE)/config"; \
export DFE_ENGINE_SCHEMAS_DIR="$(E2E_WORKSPACE)/schemas"; \
export DFE_ENGINE_E2E_SCHEMA_FIXTURES_DIR="$(E2E_WORKSPACE)/schema-fixtures"; \
export DFE_ENGINE_SECRETS_PATH="$(E2E_WORKSPACE)/secrets"; \
export DFE_ENGINE_STORAGE_PATH="$(E2E_WORKSPACE)/artifacts"; \
export DFE_ENGINE_GITOPS_LOCAL_PATH="$(E2E_WORKSPACE)/deploy-repo"; \
export DFE_ENGINE_CLICKHOUSE_DATA_DATABASE="$(E2E_CH_DATA_DB)"; \
export DFE_ENGINE_E2E_SERVER=true; \
export DFE_ENGINE_ENV_FILE="$(E2E_ENV_FILE)"; \
uv run dfe-engine run