Spaces:
Build error
Build error
Add Docker deployment support for Railway
Browse files- Dockerfile with multi-stage build (standalone output)
- .dockerignore to keep image lean
- Enable standalone output in next.config.ts
- Auto-runs prisma db push on container start
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- .dockerignore +7 -0
- Dockerfile +57 -0
- next.config.ts +3 -1
- public/.gitkeep +0 -0
.dockerignore
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node_modules
|
| 2 |
+
.next
|
| 3 |
+
.git
|
| 4 |
+
*.db
|
| 5 |
+
*.db-journal
|
| 6 |
+
.env
|
| 7 |
+
generated
|
Dockerfile
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:22-slim AS base
|
| 2 |
+
|
| 3 |
+
# Install OpenSSL for Prisma
|
| 4 |
+
RUN apt-get update && apt-get install -y openssl python3 make g++ && rm -rf /var/lib/apt/lists/*
|
| 5 |
+
|
| 6 |
+
WORKDIR /app
|
| 7 |
+
|
| 8 |
+
# Install dependencies
|
| 9 |
+
FROM base AS deps
|
| 10 |
+
COPY package.json package-lock.json ./
|
| 11 |
+
RUN npm ci
|
| 12 |
+
|
| 13 |
+
# Build the application
|
| 14 |
+
FROM base AS builder
|
| 15 |
+
WORKDIR /app
|
| 16 |
+
COPY --from=deps /app/node_modules ./node_modules
|
| 17 |
+
COPY . .
|
| 18 |
+
|
| 19 |
+
# Generate Prisma client
|
| 20 |
+
RUN npx prisma generate
|
| 21 |
+
|
| 22 |
+
# Build Next.js
|
| 23 |
+
RUN npm run build
|
| 24 |
+
|
| 25 |
+
# Production image
|
| 26 |
+
FROM base AS runner
|
| 27 |
+
WORKDIR /app
|
| 28 |
+
|
| 29 |
+
ENV NODE_ENV=production
|
| 30 |
+
|
| 31 |
+
# Create a non-root user
|
| 32 |
+
RUN addgroup --system --gid 1001 nodejs && \
|
| 33 |
+
adduser --system --uid 1001 nextjs
|
| 34 |
+
|
| 35 |
+
# Copy necessary files
|
| 36 |
+
COPY --from=builder /app/public ./public
|
| 37 |
+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
| 38 |
+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
| 39 |
+
COPY --from=builder /app/prisma ./prisma
|
| 40 |
+
COPY --from=builder /app/prisma.config.ts ./prisma.config.ts
|
| 41 |
+
COPY --from=builder /app/generated ./generated
|
| 42 |
+
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
| 43 |
+
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
|
| 44 |
+
COPY --from=builder /app/node_modules/better-sqlite3 ./node_modules/better-sqlite3
|
| 45 |
+
|
| 46 |
+
# Create data directory for SQLite with correct permissions
|
| 47 |
+
RUN mkdir -p /app/data && chown nextjs:nodejs /app/data
|
| 48 |
+
|
| 49 |
+
USER nextjs
|
| 50 |
+
|
| 51 |
+
EXPOSE 3000
|
| 52 |
+
|
| 53 |
+
ENV PORT=3000
|
| 54 |
+
ENV HOSTNAME="0.0.0.0"
|
| 55 |
+
ENV DATABASE_URL="file:/app/data/prod.db"
|
| 56 |
+
|
| 57 |
+
CMD ["sh", "-c", "npx prisma db push --skip-generate && node server.js"]
|
next.config.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import type { NextConfig } from "next";
|
| 2 |
|
| 3 |
-
const nextConfig: NextConfig = {
|
|
|
|
|
|
|
| 4 |
|
| 5 |
export default nextConfig;
|
|
|
|
| 1 |
import type { NextConfig } from "next";
|
| 2 |
|
| 3 |
+
const nextConfig: NextConfig = {
|
| 4 |
+
output: "standalone",
|
| 5 |
+
};
|
| 6 |
|
| 7 |
export default nextConfig;
|
public/.gitkeep
ADDED
|
File without changes
|