-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
121 lines (87 loc) · 3.69 KB
/
Copy pathMakefile
File metadata and controls
121 lines (87 loc) · 3.69 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
SHELL := /bin/bash
.DEFAULT_GOAL := help
# Validate JAVA_HOME; if the path doesn't have bin/java, fall back to
# /usr/libexec/java_home on macOS. Override per-invocation with `make JAVA_HOME=...`.
ifeq ($(wildcard $(JAVA_HOME)/bin/java),)
ifeq ($(shell uname),Darwin)
JAVA_HOME := $(shell /usr/libexec/java_home 2>/dev/null)
endif
endif
export JAVA_HOME
COMPOSE := docker compose -f docker/docker-compose.yml
MVN := ./mvnw
.PHONY: help \
up down down-v logs logs-db ps psql \
build run \
openapi-generate openapi-lint \
spotbugs spotbugs-report checkstyle lint \
test test-it verify verify-no-it \
db-reset fixtures \
ci
##@ General
help: ## Show this help (targets grouped by section)
@awk ' \
BEGIN { FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n" } \
/^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } \
/^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) }' \
$(MAKEFILE_LIST)
##@ Docker stack
up: ## Start the docker stack (postgres + app)
$(COMPOSE) up -d
down: ## Stop the stack, keep volumes
$(COMPOSE) down
down-v: ## Stop the stack and DELETE the data volume
$(COMPOSE) down -v
logs: ## Tail logs of the app
$(COMPOSE) logs -f app
logs-db: ## Tail logs of postgres
$(COMPOSE) logs -f postgres
ps: ## List the stack containers
$(COMPOSE) ps
psql: ## Open psql inside the postgres container
$(COMPOSE) exec postgres psql -U postgres -d productdb
##@ Build & run
build: ## Compile and package the app jar (mvnw clean package)
$(MVN) clean package
run: ## Run the app from the host (Mode A; requires postgres up)
$(MVN) spring-boot:run
##@ OpenAPI
openapi-generate: ## Regenerate ProductsApi from docs/api/openapi.yaml
$(MVN) generate-sources
# The openapi-generator plugin validates the spec as part of generation.
# There is no standalone `validate` goal, so lint = generate. We use
# `generate-sources` (lifecycle phase) so all plugin executions run.
openapi-lint: openapi-generate ## Validate the OpenAPI spec (alias of openapi-generate)
##@ Static analysis
spotbugs: ## Run SpotBugs + FindSecBugs (fails the build on findings)
$(MVN) -DskipTests compile spotbugs:check
spotbugs-report: ## Generate SpotBugs HTML report (target/spotbugs.html)
$(MVN) -DskipTests compile spotbugs:spotbugs
@echo "Open target/spotbugs.html in a browser."
checkstyle: ## Run Checkstyle (fails the build on findings)
$(MVN) checkstyle:check
lint: spotbugs checkstyle ## Run all static-analysis tools
##@ Tests
test: ## Run unit tests (surefire, no Docker required)
$(MVN) test
# Invokes failsafe goals directly so the lifecycle's `test` phase (surefire,
# unit tests) is skipped. `test-compile` ensures the *IT.java sources are
# compiled before failsafe looks for them.
test-it: ## Run integration tests only (failsafe; requires Docker)
$(MVN) test-compile failsafe:integration-test failsafe:verify
verify: ## Compile + unit + integration (Docker) + lint — full pre-CI gate
$(MVN) clean verify
verify-no-it: ## Compile + unit + lint, skipping integration tests (no Docker)
$(MVN) clean verify -DskipITs
##@ Database
db-reset: ## Destroy and recreate the postgres volume (clean slate)
$(COMPOSE) down -v
$(COMPOSE) up -d postgres
# Loads docker/fixtures.sql via psql. The product table is created by Hibernate
# at app boot, so `make up` must have run at least once before this works.
fixtures: ## Reset products table and load 5 sample rows (requires `make up`)
@$(COMPOSE) exec -T postgres psql -U postgres -d productdb -v ON_ERROR_STOP=1 < docker/fixtures.sql
@echo "Loaded 5 fixtures. Try: curl -s http://localhost:8080/api/products"
##@ CI
ci: verify ## verify + build the docker image
$(COMPOSE) build app