entrypoint.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env bash
  2. # Startup sequence for the bind-mounted repo:
  3. # 1. install dependencies only when package-lock.json actually changed;
  4. # 2. regenerate the Prisma client only when the schema actually changed;
  5. # 3. apply pending migrations;
  6. # 4. start in dev (watch) or prod (compiled) mode.
  7. #
  8. # The stamp files live under node_modules/, so a `git pull` that touches only
  9. # application code goes straight to step 4.
  10. set -euo pipefail
  11. cd /app
  12. mkdir -p data
  13. STAMP_DIR="node_modules/.eks-stamps"
  14. hash_of() { sha256sum "$1" 2>/dev/null | awk '{print $1}'; }
  15. needs_refresh() {
  16. local file="$1" stamp="$STAMP_DIR/$2"
  17. [ -f "$stamp" ] || return 0
  18. [ "$(cat "$stamp")" = "$(hash_of "$file")" ] && return 1 || return 0
  19. }
  20. record() { mkdir -p "$STAMP_DIR"; hash_of "$1" > "$STAMP_DIR/$2"; }
  21. if [ ! -d node_modules/express ] || needs_refresh package-lock.json lock; then
  22. echo "[entrypoint] installing dependencies"
  23. npm ci --no-audit --no-fund
  24. record package-lock.json lock
  25. else
  26. echo "[entrypoint] dependencies up to date"
  27. fi
  28. if [ ! -d node_modules/.prisma/client ] || needs_refresh prisma/schema.prisma schema; then
  29. echo "[entrypoint] generating prisma client"
  30. npx prisma generate
  31. record prisma/schema.prisma schema
  32. fi
  33. echo "[entrypoint] applying database migrations"
  34. npx prisma migrate deploy
  35. if [ "${RELAY_MODE:-prod}" = "dev" ]; then
  36. echo "[entrypoint] starting in dev mode (tsx watch — no rebuild needed)"
  37. exec npx tsx watch src/index.ts
  38. fi
  39. echo "[entrypoint] building and starting in prod mode"
  40. npm run build
  41. exec node dist/index.js