Update and generalize the deploy workflow
This commit is contained in:
parent
17f53946f1
commit
39d8d920b6
4 changed files with 59 additions and 18 deletions
43
justfile
43
justfile
|
|
@ -1,9 +1,7 @@
|
|||
set dotenv-load
|
||||
|
||||
# Cloudflare credentials (set these as environment variables)
|
||||
CF_ZONE_ID := env_var_or_default("CF_ZONE_ID", "")
|
||||
CF_API_TOKEN := env_var_or_default("CF_API_TOKEN", "")
|
||||
CF_HOST := env_var_or_default("CF_HOST", "")
|
||||
# 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
|
||||
|
|
@ -12,7 +10,7 @@ dev:
|
|||
build:
|
||||
PUBLIC_SSR=no npm run build
|
||||
|
||||
# Server-rendered bundle (needs Node 22+ on the host, see deploy/squalk.service)
|
||||
# Server-rendered bundle (needs Node 22+ on the host, see deploy/production-example.service)
|
||||
build-ssr:
|
||||
PUBLIC_SSR=yes npm run build
|
||||
|
||||
|
|
@ -21,18 +19,31 @@ deploy target: build
|
|||
@just purge-web-cache
|
||||
|
||||
# Ships the Node build plus its runtime deps and env, then restarts the unit.
|
||||
# The remote step runs in a login shell so the user's PATH (npm, nvm…) applies.
|
||||
deploy-ssr target: build-ssr
|
||||
rsync -av --delete --progress --exclude node_modules build/ {{target}}:~/squalk/build/
|
||||
rsync -av package.json package-lock.json {{target}}:~/squalk/
|
||||
rsync -av .env.production {{target}}:~/squalk/.env
|
||||
ssh {{target}} '$SHELL -l -c "cd ~/squalk && npm ci --omit=dev && sudo systemctl restart squalk"'
|
||||
@just purge-web-cache
|
||||
# `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}}
|
||||
|
||||
purge-web-cache:
|
||||
@echo "\nPurging Cloudflare cache... for zone {{CF_ZONE_ID}}"
|
||||
@curl -s -X POST "https://api.cloudflare.com/client/v4/zones/{{CF_ZONE_ID}}/purge_cache" \
|
||||
-H "Authorization: Bearer {{CF_API_TOKEN}}" \
|
||||
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'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue