65 lines
2.2 KiB
Bash
Executable File
65 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Produce the deployable artifact for a non-Docker deploy.
|
|
#
|
|
# Copying .next/ wholesale is what filled the production disk: a working tree's
|
|
# .next/ reaches 2+ GB, but only three paths are read at runtime —
|
|
# .next/standalone the server + its traced node_modules
|
|
# .next/static hashed client assets (served by nginx at /_next/static/)
|
|
# public unhashed public assets
|
|
# Everything else (.next/cache, .next/dev, .next/server, .next/types) is
|
|
# build-host state and must never be shipped.
|
|
#
|
|
# Usage: npm run bundle -> dist/loyaly-mer-login.tar.gz
|
|
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "$ROOT"
|
|
|
|
OUT="dist"
|
|
STAGE="$OUT/bundle"
|
|
|
|
for p in .next/standalone .next/static public; do
|
|
if [ ! -d "$p" ]; then
|
|
echo "error: $p missing — run 'npm run build' first" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# .env is the production environment, not a secret — LOYALY_API_BASE lives in
|
|
# it and the server reads it at boot. It is tracked in git, so a missing one
|
|
# means the tree is wrong, not that this deploy opted out.
|
|
if [ ! -f .env ]; then
|
|
echo "error: .env missing — it is committed; restore it with 'git checkout .env'" >&2
|
|
exit 1
|
|
fi
|
|
|
|
rm -rf "$STAGE"
|
|
mkdir -p "$STAGE"
|
|
|
|
# standalone already contains server.js, package.json and traced node_modules,
|
|
# and expects static/ and public/ to sit beside it in the same layout.
|
|
cp -R .next/standalone/. "$STAGE/"
|
|
mkdir -p "$STAGE/.next"
|
|
cp -R .next/static "$STAGE/.next/static"
|
|
cp -R public "$STAGE/public"
|
|
|
|
# Beside server.js, which is where Next's loadEnvConfig looks. NOT .env.local —
|
|
# that is the dev override and would point the deployed server at 127.0.0.1.
|
|
cp .env "$STAGE/.env"
|
|
|
|
TARBALL="$OUT/loyaly-mer-login.tar.gz"
|
|
rm -f "$TARBALL"
|
|
tar -czf "$TARBALL" -C "$STAGE" .
|
|
|
|
echo
|
|
echo "bundle: $(du -sh "$STAGE" | cut -f1) ($STAGE)"
|
|
echo "tarball: $(du -sh "$TARBALL" | cut -f1) ($TARBALL)"
|
|
echo
|
|
echo "deploy: scp $TARBALL <host>:/srv/ && tar -xzf loyaly-mer-login.tar.gz -C /srv/app"
|
|
echo "run: AUTH_SECRET=... PORT=3000 HOSTNAME=0.0.0.0 NODE_ENV=production node server.js"
|
|
echo
|
|
echo "note: LOYALY_API_BASE ships in the bundled .env. AUTH_SECRET does not —"
|
|
echo " it signs sessions and must come from the host's environment."
|