Repository navigation
Expand file tree
/
Copy pathjustfile
More file actions
63 lines (55 loc) · 2.92 KB
/
Copy pathjustfile
File metadata and controls
63 lines (55 loc) · 2.92 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
set dotenv-load
# Cloudflare credentials: per deploy target in .env.<mode>.local (gitignored,
# never shipped to the server), falling back to the environment / .env
dev:
npm run dev
# Static single-page bundle (served by any web server)
build:
PUBLIC_SSR=no npm run build
# Server-rendered bundle (needs Node 22+ on the host, see deploy/production-example.service)
build-ssr:
PUBLIC_SSR=yes npm run build
deploy target: build
rsync -av --delete --progress build/ {{target}}:~/squalk/
@just purge-web-cache
# Ships the Node build plus its runtime deps and env, then restarts the unit.
# `mode` picks the instance: vite bakes .env.<mode> into the build, and
# .env.<mode>.local provides the deployment details (DEPLOY_HOST, DEPLOY_DIR,
# DEPLOY_SERVICE) plus the Cloudflare credentials. The remote step runs in a
# login shell so the user's PATH (npm, nvm…) applies.
deploy-ssr mode:
#!/usr/bin/env bash
set -euo pipefail
[ -f .env.{{mode}}.local ] || { echo "Missing .env.{{mode}}.local"; exit 1; }
set -a; source .env.{{mode}}.local; set +a
: "${DEPLOY_HOST:?DEPLOY_HOST missing in .env.{{mode}}.local}"
: "${DEPLOY_DIR:?DEPLOY_DIR missing in .env.{{mode}}.local}"
: "${DEPLOY_SERVICE:?DEPLOY_SERVICE missing in .env.{{mode}}.local}"
PUBLIC_SSR=yes npm run build -- --mode {{mode}}
rsync -av --delete --progress --exclude node_modules build/ "$DEPLOY_HOST:$DEPLOY_DIR/build/"
rsync -av package.json package-lock.json "$DEPLOY_HOST:$DEPLOY_DIR/"
rsync -av .env.{{mode}} "$DEPLOY_HOST:$DEPLOY_DIR/.env"
ssh "$DEPLOY_HOST" "\$SHELL -l -c 'cd $DEPLOY_DIR && npm ci --omit=dev && sudo systemctl restart $DEPLOY_SERVICE'"
just purge-web-cache {{mode}}
# Ships the static bundle of an instance to a directory served by the web
# server. Same conventions as deploy-ssr: .env.<mode> is baked into the build,
# .env.<mode>.local provides DEPLOY_HOST, DEPLOY_DIR and the Cloudflare credentials.
deploy-static mode:
#!/usr/bin/env bash
set -euo pipefail
[ -f .env.{{mode}}.local ] || { echo "Missing .env.{{mode}}.local"; exit 1; }
set -a; source .env.{{mode}}.local; set +a
: "${DEPLOY_HOST:?DEPLOY_HOST missing in .env.{{mode}}.local}"
: "${DEPLOY_DIR:?DEPLOY_DIR missing in .env.{{mode}}.local}"
PUBLIC_SSR=no npm run build -- --mode {{mode}}
rsync -av --delete --progress build/ "$DEPLOY_HOST:$DEPLOY_DIR/"
just purge-web-cache {{mode}}
purge-web-cache mode="production":
#!/usr/bin/env bash
if [ -f .env.{{mode}}.local ]; then set -a; source .env.{{mode}}.local; set +a; fi
echo -e "\nPurging Cloudflare cache... for zone ${CF_ZONE_ID:-<unset>}"
curl -s -X POST "https://api.cloudflare.com/client/v4/zones/${CF_ZONE_ID:-}/purge_cache" \
-H "Authorization: Bearer ${CF_API_TOKEN:-}" \
-H "Content-Type: application/json" \
--data '{"purge_everything": true}' \
| jq -r 'if .success then "✅ Cache purged successfully" else "‼️ Error: " + (.errors[0].message // "Unknown error") end'