-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
292 lines (242 loc) · 7.39 KB
/
justfile
File metadata and controls
292 lines (242 loc) · 7.39 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# Terraform will panic if it encounters `PGSERVICEFILE`.
unexport PGSERVICEFILE
os := "darwin-aarch64"
plan_dir := justfile_directory() / ".terraform-plans"
_default:
@just fmt
@just lint
@just test
@just compile
# ------------------------------------------------------------------------------
# Docs
# Create a new decision record
[group('docs')]
decide +title:
#!/usr/bin/env bash
timestamp=$(date +%Y%m%d%H%M%S)
normalized=$(echo "{{ title }}" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]\+/-/g' | sed 's/^-\|-$//g')
author="$(git config user.name) <$(git config user.email)>"
filename="decisions/${timestamp}-${normalized}.org"
cat > "$filename" <<EOF
#+title: {{ title }}
#+author: ${author}
#+date: $(date +%Y-%m-%d)
EOF
echo "🎯 {{ BOLD }}Created \"$filename\"{{ NORMAL }}."
# ------------------------------------------------------------------------------
# Development
# Create self-signed SSL certificates via mkcert
[group('dev')]
mkcert:
#!/usr/bin/env zsh
set -e
mkcert -install
mkdir -p {{ justfile_directory() }}/certs
cd {{ justfile_directory() }}/certs
# We append .test to all domains during development. The following domains
# need to be supported:
#
# -- usebits.app
# api.usebits.app
# edit.usebits.app
# www.usebits.app
#
# -- bits.page
# bits.page
# jcf.bits.page
domains=(
usebits.app.test
app.test
bits.page.test
page.test
test
)
for domain in $domains; do
if [[ ! -f "_wildcard.${domain}.pem" ]]; then
mkcert "*.${domain}"
fi
done
echo >&2 "🔒 Wildcard certificates ready!"
# Generate cluster keystores
[group('dev')]
cluster-certs:
#!/usr/bin/env zsh
set -e
mkdir -p certs
if [[ ! -f certs/cluster-keystore.p12 ]]; then
keytool -genkeypair \
-alias bits-cluster \
-keyalg EC \
-groupname secp256r1 \
-validity 3650 \
-storetype PKCS12 \
-keystore certs/cluster-keystore.p12 \
-storepass "$CLUSTER_KEYSTORE_PASSWORD" \
-dname "CN=bits-cluster,O=Invetica" \
-ext "SAN=IP:127.0.0.1"
keytool -genkeypair \
-alias rogue \
-keyalg EC \
-groupname secp256r1 \
-validity 1 \
-storetype PKCS12 \
-keystore certs/rogue-keystore.p12 \
-storepass password \
-dname "CN=rogue,O=Evil"
fi
echo >&2 "🔒 Cluster certificates ready!"
# Setup a local development environment
[group('dev')]
setup:
@just mkcert
@just cluster-certs
devenv shell true
@echo -e "\n✅ {{ BOLD }}Setup complete!{{ NORMAL }}"
# Format project files
[group('dev')]
fmt *args:
treefmt {{ args }}
# Clean up generated classes and screenshots
[group('dev')]
clean:
@rm -r target/classes
@rm -r target/screenshots
[group('dev')]
nrepl *args:
#!/usr/bin/env zsh
set -e
echo >&2 \
"{{ BLUE }}{{ BOLD }}==>{{ NORMAL }} {{ BOLD }}Starting nREPL on localhost:9999...{{ NORMAL }}"
exec clojure \
-M:dev:test:logging:otel:nrepl:{{ os }} \
--report stderr \
--main bits.nrepl \
--host localhost \
--port 9999 \
{{ args }}
# Watch source code for Tailwind classes
[group('dev')]
tailwind:
mkdir -p resources/public
tailwindcss \
--watch \
--input resources/tailwind.css \
--output resources/public/app.css
# Regenerate Tailwind CSS from template
[group('dev')]
css:
clojure -M:dev --report stderr -m bits.dev.assets
# Import clj-kondo configs
[group('dev')]
clj-kondo-import:
clj-kondo --lint "$(clojure -Spath)" --dependencies --skip-lint --copy-configs
# ------------------------------------------------------------------------------
# Locales
# Extract translatable strings to .pot file
[group('locales')]
locales-extract:
clojure -T:build --report stderr locales-extract
# Build translation bundles from .po files
[group('locales')]
locales-build:
clojure -T:build --report stderr build-translations
# ------------------------------------------------------------------------------
# Test
# Run all quality checks (format + lint)
[group('test')]
check:
treefmt --fail-on-change
clj-kondo --lint dev src test
# Run lints
[group('test')]
lint:
clj-kondo --lint dev src test
# Compile bits.main
[group('test')]
compile:
clojure -M:dev --report stderr -m bits.dev.compile
# Run tests
[group('test')]
test *args:
clojure -M:dev:test:runner:{{ os }} {{ args }}
# Run tests with performance tracing output
[group('test')]
perf *args:
env \
OTEL_TRACES_EXPORTER=logging-otlp \
clojure \
-M:dev:test:otel:runner:{{ os }} \
{{ args }}
# ------------------------------------------------------------------------------
# Build
# Regenerate deps-lock.json
[group('build')]
deps-lock:
nix run 'git+https://code.invetica.team/jcf/clj-nix?rev=5751969234c45823955a0fd348831068f1107453#deps-lock'
# Build an AOT-compiled uberjar
[group('build')]
build:
nix build .#bits-uberjar
# Build Datomic Pro output
[group('build')]
build-datomic:
nix build .#datomic-pro
# Build the container image and load into local Docker
[group('build')]
container:
nix run .#bits-container-arm64.copyTo -- docker-daemon:bits:latest
# Run the Docker image against the local devenv database
[group('build')]
docker-run tag="bits:latest" *args:
docker run --rm -p 3000:3000 \
-e DATABASE_URL=jdbc:postgresql://host.docker.internal:5432/bits_dev?user=bits\&password=please \
-e CSRF_SECRET=default-csrf-secret-change-in-prod \
--add-host=host.docker.internal:host-gateway \
{{ args }} {{ tag }}
# ------------------------------------------------------------------------------
# PostgreSQL
# Start an interactive psql session connected to the local development database
[group('postgres')]
psql *args:
PGPASSWD=please psql \
--host=localhost \
--port=5432 \
--username=bits \
--dbname=bits_dev \
{{ args }}
# Create a new migration
[group('postgres')]
migration name:
#!/usr/bin/env zsh
set -e
timestamp="$(date +%Y%m%d%H%M%S)"
normalized=$(echo "{{ name }}" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]\+/-/g' | sed 's/^-\|-$//g')
dir="resources/migrations"
mkdir -p "$dir"
for direction in up down; do
path="$dir/${timestamp}-${normalized}.${direction}.sql"
touch "$path" && echo "$path"
done
# ------------------------------------------------------------------------------
# Infrastructure
[group('iac')]
_terraform dir *args:
op run -- terraform -chdir={{ justfile_directory() }}/iac/{{ dir }} {{ args }}
# Initialize one or all Terraform projects
[group('iac')]
init dir *args:
@just _terraform {{ dir }} init {{ args }}
# Plan one or all Terraform projects
[group('iac')]
plan dir:
@mkdir -p {{ plan_dir }}
@just _terraform {{ dir }} plan -out {{ plan_dir }}/{{ replace(dir, '/', '-') }}.tfplan
# Apply one or all Terraform projects
[group('iac')]
apply dir:
@just _terraform {{ dir }} apply {{ plan_dir }}/{{ replace(dir, '/', '-') }}.tfplan
rm {{ plan_dir }}/{{ replace(dir, '/', '-') }}.tfplan
# Interact with outputs one or all Terraform projects
[group('iac')]
output dir *args:
@just _terraform {{ dir }} output {{ args }}