-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
157 lines (123 loc) · 5.08 KB
/
Makefile
File metadata and controls
157 lines (123 loc) · 5.08 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
# ============================================================================
# Chronicle Makefile
# ============================================================================
# All development commands for the Chronicle project.
# Run `make help` for a list of available targets.
# ============================================================================
# --- Variables ---
APP_NAME := chronicle
BUILD_DIR := ./bin
MAIN_PKG := ./cmd/server
MIGRATIONS := ./db/migrations
DOCKER_COMP := docker-compose.yml
# Database URL for migrations (override via env or .env file)
DATABASE_URL ?= mysql://chronicle:chronicle@tcp(localhost:3306)/chronicle
# --- Help ---
.PHONY: help
help: ## Show this help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
# --- Development ---
.PHONY: dev
dev: ## Start dev server with hot reload (air)
air
.PHONY: run
run: ## Run the server directly (no hot reload)
go run $(MAIN_PKG)
# --- Build ---
.PHONY: build
build: ## Build production binary
CGO_ENABLED=0 go build -o $(BUILD_DIR)/$(APP_NAME) $(MAIN_PKG)
.PHONY: clean
clean: ## Remove built artifacts
rm -rf $(BUILD_DIR) tmp/
# --- Code Generation ---
.PHONY: templ
templ: ## Regenerate Templ .go files from .templ sources
templ generate
.PHONY: tailwind
tailwind: ## Regenerate Tailwind CSS
tailwindcss -i static/css/input.css -o static/css/app.css --minify
.PHONY: tailwind-watch
tailwind-watch: ## Watch mode for Tailwind CSS
tailwindcss -i static/css/input.css -o static/css/app.css --watch
.PHONY: tiptap-bundle
tiptap-bundle: ## Rebuild TipTap editor bundle (table extensions, etc.)
npx esbuild static/vendor/tiptap-bundle.src.js --bundle --minify --outfile=static/vendor/tiptap-bundle.min.js --format=iife --global-name=__TipTapInternal
.PHONY: generate
generate: templ tailwind ## Run all code generation (templ + tailwind)
# --- Testing ---
.PHONY: test
test: ## Run all tests
go test ./... -v
.PHONY: test-unit
test-unit: ## Run unit tests only (skip integration)
go test ./... -v -short
.PHONY: test-int
test-int: ## Run integration tests (requires running DB)
go test ./... -v -run Integration
.PHONY: test-cover
test-cover: ## Run tests with coverage report
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.html
# --- Linting & Security ---
.PHONY: lint
lint: ## Run golangci-lint
golangci-lint run ./...
.PHONY: security
security: ## Run gosec security scanner
gosec ./...
.PHONY: vuln
vuln: ## Run govulncheck dependency vulnerability scanner
govulncheck ./...
# --- Database Migrations ---
.PHONY: migrate-up
migrate-up: ## Apply all pending migrations
migrate -path $(MIGRATIONS) -database "$(DATABASE_URL)" up
.PHONY: migrate-down
migrate-down: ## Rollback last migration
migrate -path $(MIGRATIONS) -database "$(DATABASE_URL)" down 1
.PHONY: migrate-create
migrate-create: ## Create new migration (usage: make migrate-create NAME=description)
migrate create -ext sql -dir $(MIGRATIONS) -seq $(NAME)
.PHONY: migrate-status
migrate-status: ## Show current migration version
migrate -path $(MIGRATIONS) -database "$(DATABASE_URL)" version
.PHONY: seed
seed: ## Seed dev database with sample data (TODO: implement cmd/seed)
@echo "cmd/seed not yet implemented. Default entity types are seeded automatically when creating a campaign."
# --- Docker ---
.PHONY: docker-up
docker-up: ## Start MariaDB + Redis containers
docker compose -f $(DOCKER_COMP) up -d chronicle-db chronicle-redis
.PHONY: docker-down
docker-down: ## Stop all containers
docker compose -f $(DOCKER_COMP) down
.PHONY: docker-logs
docker-logs: ## Tail container logs
docker compose -f $(DOCKER_COMP) logs -f
.PHONY: docker-build
docker-build: ## Build the Chronicle Docker image
docker compose -f $(DOCKER_COMP) build chronicle
.PHONY: docker-all
docker-all: ## Start full stack (app + db + redis)
docker compose -f $(DOCKER_COMP) up -d
# ============================================================================
# Backup & Restore
# ============================================================================
# Operator-facing wrappers around scripts/backup.sh and scripts/restore.sh.
# All targets invoke the script inside the chronicle container, where
# mariadb-client and the data volume are already in place. See
# docs/deployment.md for the full operator runbook.
.PHONY: backup
backup: ## Snapshot DB + media to $$BACKUP_DIR (pass BACKUP_ARGS for flags)
docker compose -f $(DOCKER_COMP) exec -T chronicle /app/scripts/backup.sh $(BACKUP_ARGS)
.PHONY: backup-check
backup-check: ## Validate backup environment without writing anything
docker compose -f $(DOCKER_COMP) exec -T chronicle /app/scripts/backup.sh --check
.PHONY: backup-list
backup-list: ## List backup artifacts in the chronicle-data volume
docker compose -f $(DOCKER_COMP) exec -T chronicle ls -lh /app/data/backups
.PHONY: restore
restore: ## Restore from a manifest (usage: make restore RESTORE_ARGS="--manifest=/app/data/backups/chronicle_manifest_TS.txt")
docker compose -f $(DOCKER_COMP) exec chronicle /app/scripts/restore.sh $(RESTORE_ARGS)