-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (114 loc) · 5.05 KB
/
Makefile
File metadata and controls
138 lines (114 loc) · 5.05 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
.PHONY: help install build test lint check clean container-image \
integration nagios-integration nagios-image nagios-clean \
host-install host-build host-test host-lint \
host-check host-integration
.DEFAULT_GOAL := help
include vars.mk
PODMAN_EXTRA := $(if $(findstring podman,$(CONTAINER_ENGINE)),--userns=keep-id,)
CONTAINER_RUN := $(CONTAINER_ENGINE) run --rm $(PODMAN_EXTRA) -v $(CURDIR):/app -w /app $(IMAGE_NAME)
NAGIOS_CONTAINER := nagdash-nagios-test-run
NAGIOS_PORT := 8888
help: ## Show this help
@echo "Usage: make <target>"
@echo ""
@echo "Container targets (requires Podman or Docker):"
@echo " install Install Composer dev dependencies"
@echo " build Check extensions and syntax-check PHP files"
@echo " test Run PHPUnit unit tests"
@echo " integration Run PHPUnit integration tests (stub server)"
@echo " nagios-integration Run integration tests against real Nagios + nagios-api"
@echo " lint Run PHP_CodeSniffer"
@echo " check Run build + lint + test + integration"
@echo " nagios-image Build the Nagios test container"
@echo " nagios-clean Stop and remove the Nagios test container"
@echo " clean Remove vendor/ and composer.lock"
@echo ""
@echo "Host targets (no container, requires PHP + Composer on host):"
@echo " host-install Install Composer dev dependencies"
@echo " host-build Check extensions, config, and syntax-check PHP files"
@echo " host-test Run PHPUnit unit tests"
@echo " host-integration Run PHPUnit integration tests (stub server)"
@echo " host-lint Run PHP_CodeSniffer"
@echo " host-check Run host-build + host-lint + host-test + host-integration"
# --- Container targets ---
container-image:
@$(CONTAINER_ENGINE) build -q --build-arg PHP_VERSION=$(PHP_VERSION) -t $(IMAGE_NAME) -f Dockerfile.dev . > /dev/null
install: container-image
$(CONTAINER_RUN) composer install
build: container-image
$(CONTAINER_RUN) sh -c '\
echo "==> Checking PHP extensions..." && \
php -m | grep -q curl && \
php -m | grep -q json && \
echo "==> Syntax-checking PHP files..." && \
find phplib htdocs -name "*.php" -exec php -l {} \; | grep -v "No syntax errors" || true && \
echo "==> Build OK"'
test: build
$(CONTAINER_RUN) sh -c 'composer install --quiet && vendor/bin/phpunit --testsuite Unit'
integration: build
$(CONTAINER_RUN) sh -c 'composer install --quiet && vendor/bin/phpunit --testsuite Integration'
lint: build
$(CONTAINER_RUN) sh -c 'composer install --quiet && vendor/bin/phpcs'
check: build lint test integration
@echo "==> All checks passed"
clean:
rm -rf vendor composer.lock
# --- Nagios integration test targets ---
nagios-image:
@echo "==> Building Nagios test container (Nagios $(NAGIOS_VERSION))..."
$(CONTAINER_ENGINE) build \
--build-arg NAGIOS_VERSION=$(NAGIOS_VERSION) \
--build-arg NAGIOS_API_REPO=$(NAGIOS_API_REPO) \
--build-arg NAGIOS_API_BRANCH=$(NAGIOS_API_BRANCH) \
-t $(NAGIOS_IMAGE) \
-f tests/nagios-container/Dockerfile \
tests/nagios-container/
nagios-integration: build nagios-image
@echo "==> Starting Nagios container..."
@$(CONTAINER_ENGINE) rm -f $(NAGIOS_CONTAINER) 2>/dev/null || true
$(CONTAINER_ENGINE) run -d --name $(NAGIOS_CONTAINER) -p $(NAGIOS_PORT):8080 $(NAGIOS_IMAGE)
@echo "==> Waiting for nagios-api to be ready..."
@DEADLINE=$$((SECONDS + 180)); \
while true; do \
if [ $$SECONDS -ge $$DEADLINE ]; then \
echo "ERROR: nagios-api did not start within 180 seconds"; \
$(CONTAINER_ENGINE) logs $(NAGIOS_CONTAINER); \
$(CONTAINER_ENGINE) rm -f $(NAGIOS_CONTAINER); \
exit 1; \
fi; \
if curl -sf http://127.0.0.1:$(NAGIOS_PORT)/state > /dev/null 2>&1; then \
break; \
fi; \
sleep 2; \
done
@echo "==> nagios-api is ready, running tests..."
$(CONTAINER_RUN) sh -c '\
composer install --quiet && \
NAGIOS_API_HOST=host.containers.internal NAGIOS_API_PORT=$(NAGIOS_PORT) \
vendor/bin/phpunit --testsuite NagiosIntegration' ; \
rc=$$?; \
$(CONTAINER_ENGINE) rm -f $(NAGIOS_CONTAINER); \
exit $$rc
nagios-clean:
@$(CONTAINER_ENGINE) rm -f $(NAGIOS_CONTAINER) 2>/dev/null || true
@$(CONTAINER_ENGINE) rmi $(NAGIOS_IMAGE) 2>/dev/null || true
# --- Host targets (no container) ---
host-install:
composer install
host-build:
@echo "==> Checking PHP extensions..."
@php -m | grep -q curl || (echo "ERROR: curl extension not found" && exit 1)
@php -m | grep -q json || (echo "ERROR: json extension not found" && exit 1)
@echo "==> Checking config.php..."
@test -f config.php || (echo "WARNING: config.php not found. Copy config.php.example to config.php" && exit 1)
@echo "==> Syntax-checking PHP files..."
@find phplib htdocs -name '*.php' -exec php -l {} \; | grep -v "No syntax errors" || true
@echo "==> Build OK"
host-test: host-build
vendor/bin/phpunit --testsuite Unit
host-integration: host-build
vendor/bin/phpunit --testsuite Integration
host-lint: host-build
vendor/bin/phpcs
host-check: host-build host-lint host-test host-integration
@echo "==> All checks passed"