Two root causes for seeding not working on production: 1. Origin mismatch: The seeder writes content IDs as http://localhost:7777/content/... but the app was using window.location.origin (the user's actual browser URL) to query the relay. Introduced VITE_CONTENT_ORIGIN env var baked into the Docker build so both sides use the same origin. 2. Dockerfile.seed fragility: Replaced --omit=dev + global tsx with a cleaner approach that strips sharp from package.json (the only native dep that fails on Alpine) then does a full npm install, ensuring tsx/esbuild and all applesauce deps resolve correctly. Also improved wait-for-relay to accept any HTTP response (some relays return 4xx for plain GET) and increased max attempts. Co-authored-by: Cursor <cursoragent@cursor.com>
31 lines
1.2 KiB
Docker
31 lines
1.2 KiB
Docker
# Seeder container — populates the Nostr relay with test profiles,
|
|
# reactions, and comments so the dev deployment has content.
|
|
#
|
|
# Runs once and exits. docker-compose "restart: no" keeps it from looping.
|
|
|
|
FROM node:20-alpine
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package.json, strip sharp (native dep that needs build tools not on
|
|
# Alpine), then do a full npm install so tsx/esbuild get their binaries and
|
|
# all applesauce transitive deps resolve correctly.
|
|
COPY package.json ./
|
|
RUN node -e "\
|
|
const p = JSON.parse(require('fs').readFileSync('package.json','utf8'));\
|
|
if (p.devDependencies) delete p.devDependencies.sharp;\
|
|
require('fs').writeFileSync('package.json', JSON.stringify(p, null, 2));\
|
|
" && npm install --no-package-lock
|
|
|
|
# Copy only what the seed scripts need
|
|
COPY scripts/ ./scripts/
|
|
COPY src/data/testPersonas.ts ./src/data/testPersonas.ts
|
|
COPY tsconfig.json ./
|
|
|
|
# Default env (overridden by docker-compose)
|
|
ENV RELAY_URL=ws://relay:8080
|
|
ENV ORIGIN=http://localhost:7777
|
|
|
|
# set -ex: print each command before running, exit on first failure
|
|
CMD ["sh", "-c", "set -ex && node scripts/wait-for-relay.mjs && npx tsx scripts/seed-profiles.ts && npx tsx scripts/seed-activity.ts && echo 'Seeding complete!'"]
|