40 lines
943 B
Bash
40 lines
943 B
Bash
#!/usr/bin/env bash
|
|
# Assemble a Next.js standalone tree ready for Dockerfile.prebuilt (runtime-only image).
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
OUT="${1:-$ROOT/prebuilt}"
|
|
|
|
test -f "$ROOT/.next/standalone/server.js"
|
|
test -f "$ROOT/.next/BUILD_ID"
|
|
|
|
rm -rf "$OUT"
|
|
mkdir -p "$OUT"
|
|
|
|
cp -a "$ROOT/.next/standalone/." "$OUT/"
|
|
|
|
rm -rf "$OUT/static" "$OUT/.next/static"
|
|
mkdir -p "$OUT/.next"
|
|
cp -a "$ROOT/.next/static/." "$OUT/.next/static/"
|
|
|
|
if [ -d "$ROOT/public" ]; then
|
|
rm -rf "$OUT/public"
|
|
cp -a "$ROOT/public" "$OUT/public"
|
|
else
|
|
mkdir -p "$OUT/public"
|
|
fi
|
|
|
|
cp "$ROOT/Dockerfile.prebuilt" "$OUT/Dockerfile"
|
|
printf '%s\n' 'Dockerfile' '.dockerignore' > "$OUT/.dockerignore"
|
|
|
|
test -f "$OUT/server.js"
|
|
test -f "$OUT/.next/BUILD_ID"
|
|
test -d "$OUT/.next/static"
|
|
test -d "$OUT/node_modules"
|
|
if [ -e "$OUT/static" ]; then
|
|
echo "ERROR: root-level static/ must not exist" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Prebuilt tree ready at $OUT"
|