Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
193 lines (142 loc) · 7.87 KB
/
Copy pathMakefile
File metadata and controls
193 lines (142 loc) · 7.87 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# ══════════════════════════════════════════════════════════════════════════════
# Apollo Billing — Makefile
# ══════════════════════════════════════════════════════════════════════════════
SHELL := /bin/bash
.DELETE_ON_ERROR:
.DEFAULT_GOAL := help
# ── Configuration ─────────────────────────────────────────────────────────────
export JAVA_HOME ?= /opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home
BILLING_PORT ?= 3040
DEV ?= 1
TEST ?= *
SDK_VERSION ?=
IMAGE_TAG ?= latest
BILLING_MAIN_CLASS := com.apollodeploy.billing.BillingApplicationKt
# Load .env, then .env.local for per-developer overrides (later wins).
-include .env
-include .env.local
export
# ── Build ─────────────────────────────────────────────────────────────────────
.PHONY: build shadow clean
## build — Compile and assemble the project
build:
./gradlew build
## shadow — Build a fat JAR for deployment
shadow:
./gradlew shadowJar
## clean — Delete all build artifacts
clean:
./gradlew clean
# ── Run ───────────────────────────────────────────────────────────────────────
.PHONY: stop run dev run-prod
## stop — Kill running Billing JVM and free port $(BILLING_PORT)
stop:
@pids=$$(pgrep -f '$(BILLING_MAIN_CLASS)' 2>/dev/null || true); \
if [ -n "$$pids" ]; then \
echo "Stopping: $$pids"; kill $$pids 2>/dev/null || true; sleep 1; \
pids=$$(pgrep -f '$(BILLING_MAIN_CLASS)' 2>/dev/null || true); \
[ -n "$$pids" ] && kill -9 $$pids 2>/dev/null || true; \
fi
@pids=$$(lsof -tiTCP:$(BILLING_PORT) -sTCP:LISTEN 2>/dev/null || true); \
[ -n "$$pids" ] && kill $$pids 2>/dev/null || true
## run — Start locally (DEV=1 for dev mode, DEV=0 for prod)
run: stop
@if [ "$(DEV)" = "1" ]; then \
echo "→ development mode"; \
APOLLO_BILLING_ENV=development ./gradlew clean run -Dio.ktor.development=true; \
else \
echo "→ production mode"; \
APOLLO_BILLING_ENV=production ./gradlew clean run -Dio.ktor.development=false; \
fi
## dev — Start with hot-reload (Gradle continuous)
dev: stop
APOLLO_BILLING_ENV=development ./gradlew run --continuous -Dio.ktor.development=true
## run-prod — Start in production mode
run-prod: stop
APOLLO_BILLING_ENV=production ./gradlew clean run -Dio.ktor.development=false
# ── Test ──────────────────────────────────────────────────────────────────────
.PHONY: test test-unit test-watch
## test — Run the full test suite
test:
./gradlew test
## test-unit — Run a specific test (TEST=com.apollodeploy.billing.*)
test-unit:
./gradlew test --tests "$(TEST)"
## test-watch — Re-run tests on source changes
test-watch:
./gradlew test --continuous
# ── Terraform (local dev) ─────────────────────────────────────────────────────
#
# The full local stack (infra + platform + billing + signal) is managed by
# Terraform under APIs/infra/terraform/local/.
.PHONY: tf-up tf-down tf-logs
## tf-up — Apply Terraform to start/update the local stack
tf-up:
@cd ../infra/terraform/local && terraform apply -auto-approve
## tf-down — Destroy the local Terraform stack
tf-down:
@cd ../infra/terraform/local && terraform destroy -auto-approve
## tf-logs — Tail billing container logs
tf-logs:
docker logs -f apollo-billing
# ── Database ──────────────────────────────────────────────────────────────────
.PHONY: migrate db-connect provision-reader
## migrate — Apply pending SQL migrations
migrate:
./scripts/migrate.sh
## db-connect — Open psql shell to platform database
db-connect:
PGPASSWORD="$$(grep -E '^PLATFORM_DB_PASSWORD=' .env | cut -d= -f2-)" \
psql -h 127.0.0.1 -p "$${PLATFORM_DB_PORT:-5432}" \
-U "$${PLATFORM_DB_USER:-billing_app}" \
-d "$${PLATFORM_DB_NAME:-apollo_deploy_platform}"
## provision-reader — Create read-only billing reader role
provision-reader:
scripts/provision/provision-billing-reader.sh
# ── Code Quality ──────────────────────────────────────────────────────────────
.PHONY: lint lint-fix check
## lint — Run ktlint checks
lint:
./gradlew ktlintCheck
## lint-fix — Auto-fix ktlint violations
lint-fix:
./gradlew ktlintFormat
## check — lint + test
check: lint test
# ── SDK ───────────────────────────────────────────────────────────────────────
.PHONY: sdk sdk-publish sdk-publish-kotlin sdk-publish-typescript require-sdk-version
## sdk — Export OpenAPI and generate all SDKs locally
sdk:
TESSERACT_PACKAGE_VERSION="$(SDK_VERSION)" scripts/generate-sdk.sh
## sdk-publish — Export OpenAPI, generate all SDKs, and publish them (SDK_VERSION required)
sdk-publish: require-sdk-version
TESSERACT_PUBLISH=1 TESSERACT_PACKAGE_VERSION="$(SDK_VERSION)" scripts/generate-sdk.sh
## sdk-publish-kotlin — Publish only the Kotlin/JVM SDK to Maven Central (SDK_VERSION required)
sdk-publish-kotlin: require-sdk-version
TESSERACT_PUBLISH=1 TESSERACT_PUBLISH_TARGETS=kotlin TESSERACT_PACKAGE_VERSION="$(SDK_VERSION)" scripts/generate-sdk.sh
## sdk-publish-typescript — Publish only the TypeScript SDK to npm (SDK_VERSION required)
sdk-publish-typescript: require-sdk-version
TESSERACT_PUBLISH=1 TESSERACT_PUBLISH_TARGETS=typescript TESSERACT_PACKAGE_VERSION="$(SDK_VERSION)" scripts/generate-sdk.sh
require-sdk-version:
@[ -n "$(SDK_VERSION)" ] || { echo "Set SDK_VERSION: make sdk-publish SDK_VERSION=1.0.8"; exit 1; }
# ── Misc ──────────────────────────────────────────────────────────────────────
.PHONY: openapi polar-sandbox polar-production
## openapi — Export OpenAPI spec to docs/openapi.json
openapi:
@mkdir -p docs
@curl -fsS http://127.0.0.1:$(BILLING_PORT)/docs/openapi.json > docs/openapi.json
@echo "→ docs/openapi.json"
## polar-sandbox — Setup Signal products in Polar sandbox
polar-sandbox:
bash scripts/polar/setup-signal.sh --env sandbox
## polar-production — Setup Signal products in Polar production
polar-production:
bash scripts/polar/setup-signal.sh --env production
# ── Help ──────────────────────────────────────────────────────────────────────
.PHONY: help
## help — Show this help
help:
@printf '\nUsage: make \033[36m<target>\033[0m\n\n'
@grep -hE '^## ' $(MAKEFILE_LIST) | sed 's/^## //' \
| awk -F ' — ' '{printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}'
@printf '\n'