| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #!/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"; }
- if [ ! -d node_modules/express ] || needs_refresh package-lock.json lock; then
- echo "[entrypoint] installing dependencies"
- npm ci --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
|