Rewritten to use drizzle instead of prisma
commit c0894548dac5133bd89da5b68684443748fa2559 Author: fuomag9 <1580624+fuomag9@users.noreply.github.com> Date: Fri Nov 7 18:38:30 2025 +0100 Update config.ts commit 5a4f1159d2123ada0f698a10011c24720bf6ea6f Author: fuomag9 <1580624+fuomag9@users.noreply.github.com> Date: Fri Nov 7 15:58:13 2025 +0100 first drizzle rewrite
This commit is contained in:
@@ -13,14 +13,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
COPY package.json package-lock.json* ./
|
||||
# Copy prisma schema before npm ci so postinstall can generate
|
||||
COPY prisma ./prisma
|
||||
# Set temporary DATABASE_URL for Prisma CLI
|
||||
ENV DATABASE_URL=file:/tmp/dev.db
|
||||
# Install dependencies (postinstall will run prisma generate)
|
||||
# Install dependencies
|
||||
RUN if [ -f package-lock.json ]; then npm ci; else npm install; fi
|
||||
# Explicitly verify Prisma client is generated
|
||||
RUN npx prisma generate
|
||||
|
||||
FROM base AS builder
|
||||
ENV NODE_ENV=production
|
||||
@@ -28,16 +22,8 @@ ENV NEXT_TELEMETRY_DISABLED=1
|
||||
# Set a temporary database path for build
|
||||
ENV DATABASE_PATH=/tmp/build.db
|
||||
ENV DATABASE_URL=file:/tmp/build.db
|
||||
# Install openssl for Prisma query engine
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
openssl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
# Generate Prisma client (ensures it's available in this stage)
|
||||
RUN npx prisma generate
|
||||
# Push schema to temporary database for build-time data access
|
||||
RUN npx prisma db push
|
||||
# Build the Next.js application
|
||||
RUN npm run build && rm -f /tmp/build.db
|
||||
|
||||
@@ -46,10 +32,9 @@ ENV NODE_ENV=production
|
||||
ENV PORT=3000
|
||||
WORKDIR /app
|
||||
|
||||
# Install gosu for privilege dropping and openssl for Prisma
|
||||
# Install gosu for privilege dropping
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
gosu \
|
||||
openssl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN groupadd -g 1001 nodejs && useradd -r -u 1001 -g nodejs nextjs
|
||||
@@ -63,11 +48,8 @@ COPY --from=builder /app/package.json ./package.json
|
||||
COPY --from=builder /app/.next/server/instrumentation.js ./.next/server/instrumentation.js
|
||||
COPY --from=builder /app/.next/server/instrumentation ./.next/server/instrumentation
|
||||
COPY --from=builder /app/.next/server/chunks/ ./.next/server/chunks/
|
||||
|
||||
# Copy Prisma client
|
||||
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
||||
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
|
||||
COPY --from=builder /app/prisma ./prisma
|
||||
# Copy Drizzle migrations for runtime schema management
|
||||
COPY --from=builder /app/drizzle ./drizzle
|
||||
|
||||
# Create data directory for SQLite database
|
||||
RUN mkdir -p /app/data && chown -R nextjs:nodejs /app/data
|
||||
|
||||
46
docker/web/entrypoint.sh
Executable file → Normal file
46
docker/web/entrypoint.sh
Executable file → Normal file
@@ -1,50 +1,12 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# This script runs as root first to fix permissions, then switches to nextjs user
|
||||
|
||||
DB_PATH="${DATABASE_PATH:-/app/data/caddy-proxy-manager.db}"
|
||||
DB_DIR=$(dirname "$DB_PATH")
|
||||
|
||||
echo "Setting up database directory permissions..."
|
||||
|
||||
# Ensure the data directory is owned by nextjs user
|
||||
echo "Ensuring database directory exists..."
|
||||
mkdir -p "$DB_DIR"
|
||||
chown -R nextjs:nodejs "$DB_DIR"
|
||||
|
||||
# Ensure node_modules is owned by nextjs user for Prisma client generation
|
||||
chown -R nextjs:nodejs /app/node_modules
|
||||
|
||||
# Remove old Prisma client to avoid permission issues during regeneration
|
||||
echo "Cleaning old Prisma client..."
|
||||
rm -rf /app/node_modules/.prisma/client
|
||||
|
||||
# Switch to nextjs user and initialize database if needed
|
||||
gosu nextjs sh -c '
|
||||
DB_PATH="'"$DB_PATH"'"
|
||||
|
||||
# Set npm cache to writable directory
|
||||
export NPM_CONFIG_CACHE=/tmp/.npm
|
||||
|
||||
# Generate real Prisma client at runtime (replaces build-time stub)
|
||||
echo "Generating Prisma client..."
|
||||
npx prisma generate || {
|
||||
echo "Warning: Prisma generate failed, attempting with checksum ignore..."
|
||||
PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING=1 npx prisma generate || {
|
||||
echo "Error: Failed to generate Prisma client"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
if [ ! -f "$DB_PATH" ]; then
|
||||
echo "Database not found, initializing..."
|
||||
npx prisma db push --skip-generate
|
||||
echo "Database initialized successfully"
|
||||
else
|
||||
echo "Database exists, applying any schema changes..."
|
||||
npx prisma db push --skip-generate --accept-data-loss 2>/dev/null || true
|
||||
fi
|
||||
|
||||
echo "Starting application..."
|
||||
export HOSTNAME="0.0.0.0"
|
||||
exec node server.js
|
||||
'
|
||||
echo "Starting application..."
|
||||
exec gosu nextjs env HOSTNAME=0.0.0.0 node server.js
|
||||
|
||||
Reference in New Issue
Block a user