Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
166 lines (142 loc) · 6.1 KB
/
Copy pathMakefile
File metadata and controls
166 lines (142 loc) · 6.1 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
# Needs to be defined before including Makefile.common to auto-generate targets
DOCKER_ARCHS ?= amd64 arm64 ppc64le s390x
UI_PATH = web/ui
GOLANGCI_LINT_OPTS ?= --timeout 4m
include Makefile.common
DOCKER_IMAGE_NAME ?= argus
.PHONY: go-build
go-build: commit-prereqs common-build
.PHONY: go-test
go-test:
go test --tags unit,integration ./...
.PHONY: go-test-coverage
go-test-coverage:
go test ./... -coverpkg=./... -coverprofile ./coverage.out --tags unit,integration
go tool cover -func ./coverage.out
.PHONY: web-install
web-install:
cd "$(UI_PATH)" && { \
npx --yes update-browserslist-db@latest || true; \
npm ci; \
}
.PHONY: web-build
web-build:
cd $(UI_PATH) && npm run build
.PHONY: web-test
web-test:
cd $(UI_PATH) && npm run test:coverage
.PHONY: web-lint
web-lint:
cd $(UI_PATH) && npm run lint
.PHONY: web
web: web-install web-build
.PHONY: build
build: web common-build
.PHONY: build-all
build-all: web-build compress-web build-darwin build-freebsd build-linux build-openbsd build-windows
PLAYWRIGHT_DIR = $(UI_PATH)/react-app
PLAYWRIGHT_TESTS_DIR = $(PLAYWRIGHT_DIR)/tests
PLAYWRIGHT_CONFIG_FILE = $(PLAYWRIGHT_TESTS_DIR)/playwright-test-config.yml
PLAYWRIGHT_DB_FILE = $(PLAYWRIGHT_TESTS_DIR)/playwright-tests.db
PLAYWRIGHT_PID_FILE = $(PLAYWRIGHT_TESTS_DIR)/playwright-argus.pid
PLAYWRIGHT_LOG_FILE = $(PLAYWRIGHT_TESTS_DIR)/playwright-test.log
# Port the Makefile-managed Argus server listens on.
PLAYWRIGHT_PORT ?= 8080
# URL the Playwright tests run against; defaults to the managed server.
BASE_URL ?= http://localhost:$(PLAYWRIGHT_PORT)
# Second, auth-enabled instance for the auth e2e specs.
PLAYWRIGHT_CONFIG_SRC = $(PLAYWRIGHT_TESTS_DIR)/fixtures/noauth-config.yml
PLAYWRIGHT_AUTH_CONFIG_SRC = $(PLAYWRIGHT_TESTS_DIR)/fixtures/auth-config.yml
PLAYWRIGHT_AUTH_CONFIG_FILE = $(PLAYWRIGHT_TESTS_DIR)/playwright-auth-config.yml
PLAYWRIGHT_AUTH_DB_FILE = $(PLAYWRIGHT_TESTS_DIR)/playwright-auth-tests.db
PLAYWRIGHT_AUTH_PID_FILE = $(PLAYWRIGHT_TESTS_DIR)/playwright-auth-argus.pid
PLAYWRIGHT_AUTH_LOG_FILE = $(PLAYWRIGHT_TESTS_DIR)/playwright-auth-test.log
PLAYWRIGHT_AUTH_PORT ?= 8081
AUTH_BASE_URL ?= http://localhost:$(PLAYWRIGHT_AUTH_PORT)
# Bootstrap admin password for the auth-enabled instance
PLAYWRIGHT_AUTH_PASSWORD ?= playwright-admin-pw
# wait_for_argus,<base-url>,<log-file>: poll the healthcheck endpoint until it answers (max 60s).
define wait_for_argus
i=0; until curl -sf $(1)/api/v1/healthcheck >/dev/null; do \
i=$$((i+1)); \
if [ $$i -ge 30 ]; then \
echo "Argus not reachable at $(1) after 60s" >&2; \
if [ -f $(2) ]; then cat $(2) >&2; fi; \
exit 1; \
fi; \
sleep 2; \
done
endef
# start_argus,<config>,<db>,<port>,<log>,<pid-file>: launch a background Argus instance.
define start_argus
./$(OUTPUT_BINARY) -config.file $(1) -data.database-file $(2) -web.listen-port $(3) -log.level DEBUG > $(4) 2>&1 & echo $$! > $(5)
endef
# stop_argus,<pid-file>: kill the pid-file's process (if running) and remove it.
define stop_argus
if [ -f $(1) ]; then kill $$(cat $(1)) 2>/dev/null || true; rm -f $(1); fi
endef
# require_port_free,<port>: fail unless <port> is free.
define require_port_free
i=0; while curl -s -o /dev/null --max-time 2 http://localhost:$(1)/; do \
i=$$((i+1)); \
if [ $$i -ge 5 ]; then \
echo "ERROR: port $(1) is already in use." >&2; \
echo " Playwright would test that instance instead of the fixture." >&2; \
echo " Stop it, or re-run with PLAYWRIGHT_PORT/PLAYWRIGHT_AUTH_PORT set to free ports." >&2; \
exit 1; \
fi; \
sleep 1; \
done
endef
.PHONY: playwright-tests-setup
playwright-tests-setup:
@if [ -n "$(FRESH)" ]; then \
$(MAKE) playwright-tests-teardown; \
rm -f ./$(OUTPUT_BINARY); \
else \
$(call stop_argus,$(PLAYWRIGHT_PID_FILE)); \
fi
@$(call stop_argus,$(PLAYWRIGHT_AUTH_PID_FILE))
@$(call require_port_free,$(PLAYWRIGHT_PORT))
@$(call require_port_free,$(PLAYWRIGHT_AUTH_PORT))
cp $(PLAYWRIGHT_CONFIG_SRC) $(PLAYWRIGHT_CONFIG_FILE)
cp $(PLAYWRIGHT_AUTH_CONFIG_SRC) $(PLAYWRIGHT_AUTH_CONFIG_FILE)
rm -f $(PLAYWRIGHT_AUTH_DB_FILE)*
@if [ ! -x ./$(OUTPUT_BINARY) ] || [ -n "$(FORCE)" ]; then $(MAKE) build; fi
$(call start_argus,$(PLAYWRIGHT_CONFIG_FILE),$(PLAYWRIGHT_DB_FILE),$(PLAYWRIGHT_PORT),$(PLAYWRIGHT_LOG_FILE),$(PLAYWRIGHT_PID_FILE))
$(call start_argus,$(PLAYWRIGHT_AUTH_CONFIG_FILE),$(PLAYWRIGHT_AUTH_DB_FILE),$(PLAYWRIGHT_AUTH_PORT),$(PLAYWRIGHT_AUTH_LOG_FILE),$(PLAYWRIGHT_AUTH_PID_FILE))
@$(call wait_for_argus,http://localhost:$(PLAYWRIGHT_PORT),$(PLAYWRIGHT_LOG_FILE))
@$(call wait_for_argus,http://localhost:$(PLAYWRIGHT_AUTH_PORT),$(PLAYWRIGHT_AUTH_LOG_FILE))
@echo "Creating the bootstrap admin via first-run setup..."
@curl -sf -X POST "http://localhost:$(PLAYWRIGHT_AUTH_PORT)/api/v1/auth/setup" \
-H "Content-Type: application/json" \
-d '{"username":"admin","display_name":"Administrator","password":"$(PLAYWRIGHT_AUTH_PASSWORD)"}' \
> /dev/null
.PHONY: playwright-tests-teardown
playwright-tests-teardown:
@if [ -f $(PLAYWRIGHT_PID_FILE) ]; then \
kill $$(cat $(PLAYWRIGHT_PID_FILE)) 2>/dev/null || true; \
rm -f $(PLAYWRIGHT_PID_FILE); \
else \
echo "No playwright Argus instance found running ($(PLAYWRIGHT_PID_FILE) missing)"; \
fi
@$(call stop_argus,$(PLAYWRIGHT_AUTH_PID_FILE))
rm -f $(PLAYWRIGHT_CONFIG_FILE) $(PLAYWRIGHT_DB_FILE)* $(PLAYWRIGHT_LOG_FILE)
rm -f $(PLAYWRIGHT_AUTH_CONFIG_FILE) $(PLAYWRIGHT_AUTH_DB_FILE)* $(PLAYWRIGHT_AUTH_LOG_FILE)
.PHONY: playwright-tests
playwright-tests:
@echo "Waiting for Argus to be ready at $(BASE_URL)..."
@$(call wait_for_argus,$(BASE_URL),$(PLAYWRIGHT_LOG_FILE))
@echo "Waiting for Argus to be ready at $(AUTH_BASE_URL)..."
@$(call wait_for_argus,$(AUTH_BASE_URL),$(PLAYWRIGHT_AUTH_LOG_FILE))
cd $(PLAYWRIGHT_DIR) && \
BASE_URL=$(BASE_URL) \
AUTH_BASE_URL=$(AUTH_BASE_URL) \
PLAYWRIGHT_AUTH_PASSWORD=$(PLAYWRIGHT_AUTH_PASSWORD) \
PWTEST_CHILD_PROCESS_TIMEOUT=30000 \
npx playwright test $(if $(HEADED),--headed,)
.PHONY: playwright-full
playwright-full: playwright-tests-setup
@$(MAKE) playwright-tests; status=$$?; \
$(MAKE) playwright-tests-teardown; \
exit $$status