Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
176 lines (136 loc) · 8.04 KB
/
Copy pathMakefile
File metadata and controls
176 lines (136 loc) · 8.04 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
167
168
169
170
171
172
173
174
175
176
.DEFAULT_GOAL := help
SHELL := /bin/sh
LISTEN ?= 127.0.0.1:8717
DATA ?= ./data
PROD_DIR := deploy/prod
C_SECTION := \033[1;33m
C_TARGET := \033[36m
C_OK := \033[32m
C_WARN := \033[33m
C_ERR := \033[31m
C_RESET := \033[0m
.PHONY: help install seed reset dev server web-dev site-dev build image web-build site-build fmt vet test typecheck lint ts-test check deploy-dry-run deploy-prod clean
# ─── Install / Setup ──────────────────────────────────────────────────────────
install: ## Check the toolchain, then install and verify the locked Go modules and web packages
@missing=""; for tool in go gofmt bun; do \
command -v $$tool >/dev/null 2>&1 || missing="$$missing $$tool"; \
done; \
if [ -n "$$missing" ]; then \
printf "$(C_ERR)[make] missing tools:%s$(C_RESET)\n" "$$missing"; exit 1; \
fi
@command -v shuttle >/dev/null 2>&1 || \
printf "$(C_WARN)[make] shuttle not found: only the deploy targets need it$(C_RESET)\n"
@go version
@printf "bun version %s\n" "$$(bun --version)"
@go mod download
@go mod verify
@bun install --frozen-lockfile
@printf "$(C_OK)[make] dependencies installed and verified$(C_RESET)\n"
seed reset: export KEYFOLD_DEV_DATA = $(DATA)
seed: ## Create a local demo vault with fake entries (DATA; offers to stop a running make dev)
@go run ./tools/dev-vault seed
@printf "$(C_OK)[make] demo vault ready$(C_RESET)\n"
reset: ## Empty the local vault after confirmation (DATA; offers to stop a running make dev)
@go run ./tools/dev-vault reset
# ─── Run ──────────────────────────────────────────────────────────────────────
dev: ## Start the vault server and the web UI dev server together (Ctrl-C stops both)
@go build -o bin/keyfold-server ./apps/keyfold-server
@printf "$(C_OK)[make] vault server on http://$(LISTEN), web UI on the URL printed below$(C_RESET)\n"
@KEYFOLD_ENV=development ./bin/keyfold-server -listen $(LISTEN) -data $(DATA) & pid=$$!; \
trap 'kill $$pid 2>/dev/null' EXIT INT TERM; \
cd apps/web && bun run dev
server: ## Start the vault server (LISTEN, DATA), serving apps/web/dist if built
@go run ./apps/keyfold-server -listen $(LISTEN) -data $(DATA) -web apps/web/dist
web-dev: ## Start the web UI dev server (proxies /api to the vault server)
@cd apps/web && bun run dev
site-dev: ## Start the public product site dev server (apps/site, Next.js)
@cd apps/site && bun run dev
# ─── Build ────────────────────────────────────────────────────────────────────
COMMIT ?= $(shell git rev-parse --short=7 HEAD 2>/dev/null)
ifeq ($(origin VERSION),undefined)
VERSION := $(shell git describe --tags --exact-match --match 'v*' HEAD 2>/dev/null || printf '%s\n' dev)
else
# Keep overrides literal before make can expand them in a recipe or export.
override VERSION := $(value VERSION)
endif
override define version_newline
endef
# Reject newlines before make passes the validation command to the shell.
override version_valid := $(if $(findstring $(version_newline),$(VERSION)),,$(shell LC_ALL=C; export LC_ALL; \
case '$(subst ','"'"',$(VERSION))' in \
(dev) printf yes ;; \
(*[!A-Za-z0-9.+-]*|v) ;; \
(v*) printf yes ;; \
esac))
ifeq ($(version_valid),yes)
build: ## Build the kf and keyfold-server binaries into bin/
@ldflags="-X keyfold/internal/version.Version=$(VERSION) -X keyfold/internal/version.Commit=$(COMMIT)"; \
go build -ldflags "$$ldflags" -o bin/kf ./apps/kf && \
go build -ldflags "$$ldflags" -o bin/keyfold-server ./apps/keyfold-server
@printf "$(C_OK)[make] built bin/kf and bin/keyfold-server$(C_RESET)\n"
image: ## Build the vault container image tagged keyfold:$(VERSION)
@docker build --file packaging/Dockerfile --build-arg VERSION="$(VERSION)" \
--build-arg COMMIT="$(COMMIT)" --tag "keyfold:$(VERSION)" .
@printf "$(C_OK)[make] built image %s$(C_RESET)\n" "keyfold:$(VERSION)"
else
build image:
@printf "$(C_ERR)[make] invalid VERSION: expected dev or v followed by letters, digits, dots, hyphens or plus signs$(C_RESET)\n"; exit 1
endif
web-build: ## Build the web UI into apps/web/dist
@cd apps/web && bun run build
@printf "$(C_OK)[make] web UI built in apps/web/dist$(C_RESET)\n"
site-build: ## Build the public product site (apps/site, static export) into apps/site/out
@cd apps/site && bun run build
@printf "$(C_OK)[make] product site built in apps/site/out$(C_RESET)\n"
# ─── Check ────────────────────────────────────────────────────────────────────
fmt: ## Fail if a Go file is not gofmt formatted
@out=$$(gofmt -l .); if [ -n "$$out" ]; then \
printf "$(C_ERR)[make] not formatted:$(C_RESET)\n%s\n" "$$out"; exit 1; \
fi
@printf "$(C_OK)[make] gofmt ok$(C_RESET)\n"
vet: ## Run go vet
@go vet ./...
@printf "$(C_OK)[make] go vet ok$(C_RESET)\n"
test: ## Run the Go tests
@go test -count=1 ./...
@printf "$(C_OK)[make] go tests ok$(C_RESET)\n"
typecheck: ## Typecheck the web UI, the product site and the shared TypeScript package
@cd apps/web && bunx tsc --noEmit
@cd apps/site && bun run typecheck
@cd packages/vault-core && bunx tsc --noEmit
@printf "$(C_OK)[make] typecheck ok$(C_RESET)\n"
lint: ## Lint the TypeScript code with Biome
@bunx biome check apps packages
@printf "$(C_OK)[make] lint ok$(C_RESET)\n"
ts-test: ## Run the TypeScript tests: vault statistics, and Go/TypeScript vault interop
@cd packages/vault-core && bun test
@printf "$(C_OK)[make] TypeScript tests ok$(C_RESET)\n"
check: fmt vet test typecheck lint ts-test ## Run every check
@printf "$(C_OK)[make] all checks passed$(C_RESET)\n"
# ─── Deploy ───────────────────────────────────────────────────────────────────
deploy-dry-run: ## Preview the production deployment of the public site (changes nothing)
@cd $(PROD_DIR) && shuttle deploy --config config.json --dry-run
deploy-prod: ## Deploy the public site (keyfold.pulseview.app) to production with Shuttle
@git diff --quiet && git diff --cached --quiet || { \
printf "$(C_ERR)[make] uncommitted changes: commit before deploying$(C_RESET)\n"; exit 1; }
@[ -z "$$(git log @{u}.. --oneline 2>/dev/null)" ] || { \
printf "$(C_ERR)[make] local commits not pushed: push before deploying$(C_RESET)\n"; exit 1; }
@cd $(PROD_DIR) && shuttle deploy --config config.json
@printf "$(C_OK)[make] public site deployed to https://keyfold.pulseview.app$(C_RESET)\n"
# ─── Clean ────────────────────────────────────────────────────────────────────
clean: ## Remove built binaries, apps/web/dist and the apps/site build (never the vault data)
@if [ -e bin ] || [ -e apps/web/dist ] || [ -e apps/site/.next ] || [ -e apps/site/out ]; then \
rm -rf bin apps/web/dist apps/site/.next apps/site/out; \
printf "$(C_OK)[make] build outputs removed$(C_RESET)\n"; \
else \
printf "$(C_WARN)[make] nothing to clean$(C_RESET)\n"; \
fi
# ─── Help ─────────────────────────────────────────────────────────────────────
help: ## Show this help
@awk -v s="$(C_SECTION)" -v t="$(C_TARGET)" -v r="$(C_RESET)" ' \
/^# ─── / { name = $$0; sub(/^# ─── /, "", name); sub(/ ─.*$$/, "", name); \
printf "\n%s%s%s\n", s, name, r; next } \
/^[a-zA-Z0-9_-]+:.*## / { target = $$1; sub(/:.*/, "", target); \
desc = $$0; sub(/^.*## /, "", desc); \
printf " %s%-14s%s %s\n", t, target, r, desc } \
' $(MAKEFILE_LIST)