Files
rack-planner/Dockerfile
jason 128b43e43d Fix database not initializing in Docker (no db file created)
Root cause: DATABASE_URL used a relative path (file:./data/rackmapper.db).
Prisma CLI (migrate deploy) resolves relative SQLite paths from the
prisma/ schema directory -> /app/prisma/data/rackmapper.db, while the
Prisma Client at runtime resolves from CWD -> /app/data/rackmapper.db.
The migration ran against a different path than the bind mount, so no
database file ever appeared in /app/data (the mounted volume).

Fixes:
- Change DATABASE_URL to absolute path: file:/app/data/rackmapper.db
  everywhere (docker-compose, .env.example, UNRAID.md)
- Replace inline CMD with docker-entrypoint.sh:
    mkdir -p /app/data before migrating (safety net)
    npx prisma migrate deploy with set -e so failures are visible
    exec node dist/server/index.js
  This surfaces migration errors in docker logs instead of silently
  exiting, and ensures the data dir always exists before SQLite opens it
- Update .env.example to reflect plain ADMIN_PASSWORD and COOKIE_SECURE

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 22:52:16 -05:00

35 lines
810 B
Docker

FROM node:20-alpine
WORKDIR /app
# Install build tools + OpenSSL (required by Prisma query engine on Alpine)
RUN apk add --no-cache python3 make g++ openssl openssl-dev
# Copy package manifests
COPY package*.json ./
COPY client/package*.json ./client/
# Install all dependencies (dev deps needed for prisma CLI + tsc build)
RUN npm install
RUN cd client && npm install
# Copy source
COPY . .
# Generate Prisma client for target platform (must happen before tsc)
RUN npx prisma generate
# Build server (tsc) + client (vite)
RUN npm run build
# Ensure data directory exists for SQLite bind mount
RUN mkdir -p /app/data
# Copy and make entrypoint executable
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh
EXPOSE 3001
ENTRYPOINT ["/app/docker-entrypoint.sh"]