| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #!/usr/bin/env bash
- # Startup sequence for the bind-mounted repo:
- # 1. install dependencies only when package-lock.json actually changed;
- # 2. regenerate the Prisma client only when the schema actually changed;
- # 3. apply pending migrations;
- # 4. start in dev (watch) or prod (compiled) mode.
- #
- # The stamp files live under node_modules/, so a `git pull` that touches only
- # application code goes straight to step 4.
- set -euo pipefail
- cd /app
- mkdir -p data
- STAMP_DIR="node_modules/.eks-stamps"
- hash_of() { sha256sum "$1" 2>/dev/null | awk '{print $1}'; }
- needs_refresh() {
- local file="$1" stamp="$STAMP_DIR/$2"
- [ -f "$stamp" ] || return 0
- [ "$(cat "$stamp")" = "$(hash_of "$file")" ] && return 1 || return 0
- }
- record() { mkdir -p "$STAMP_DIR"; hash_of "$1" > "$STAMP_DIR/$2"; }
- # --include=dev is required even in prod mode: NODE_ENV=production would
- # otherwise omit typescript/tsx, and both modes compile or watch from source.
- if [ ! -d node_modules/typescript ] || needs_refresh package-lock.json lock; then
- echo "[entrypoint] installing dependencies"
- npm ci --include=dev --no-audit --no-fund
- record package-lock.json lock
- else
- echo "[entrypoint] dependencies up to date"
- fi
- if [ ! -d node_modules/.prisma/client ] || needs_refresh prisma/schema.prisma schema; then
- echo "[entrypoint] generating prisma client"
- npx prisma generate
- record prisma/schema.prisma schema
- fi
- echo "[entrypoint] applying database migrations"
- npx prisma migrate deploy
- if [ "${RELAY_MODE:-prod}" = "dev" ]; then
- echo "[entrypoint] starting in dev mode (tsx watch — no rebuild needed)"
- exec npx tsx watch src/index.ts
- fi
- echo "[entrypoint] building and starting in prod mode"
- npm run build
- exec node dist/index.js
|