fix: improve docker deployment stability and ensure prisma migrations run in production
This commit is contained in:
22
Dockerfile
22
Dockerfile
@@ -17,30 +17,36 @@ RUN npm run build
|
|||||||
FROM node:20-alpine AS runner
|
FROM node:20-alpine AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Set production environment
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
ENV DATABASE_URL="file:/app/data/dev.db"
|
ENV DATABASE_URL="file:/app/data/dev.db"
|
||||||
|
|
||||||
# Install production dependencies only
|
# Install production dependencies only
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
COPY prisma ./prisma/
|
|
||||||
RUN npm install --omit=dev
|
RUN npm install --omit=dev
|
||||||
|
|
||||||
# Copy build artifacts and necessary files
|
# Copy build artifacts and necessary files
|
||||||
COPY --from=builder /app/.next ./.next
|
COPY --from=builder /app/.next ./.next
|
||||||
COPY --from=builder /app/public ./public
|
COPY --from=builder /app/public ./public
|
||||||
COPY --from=builder /app/next.config.mjs ./
|
COPY --from=builder /app/next.config.mjs ./
|
||||||
COPY --from=builder /app/next.config.ts ./
|
COPY --from=builder /app/prisma ./prisma
|
||||||
# Optional: if you have next-pwa and custom worker files
|
|
||||||
# COPY --from=builder /app/public/sw.js ./public/
|
|
||||||
|
|
||||||
# Copy prisma for migrations at runtime
|
|
||||||
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
||||||
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
|
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
|
||||||
|
|
||||||
# Script to run migrations and start the app
|
# Ensure data directory exists
|
||||||
RUN mkdir -p /app/data
|
RUN mkdir -p /app/data
|
||||||
RUN printf "#!/bin/sh\nnpx prisma migrate deploy\nnpm start" > /app/start.sh
|
|
||||||
|
# Script to run migrations and start the app
|
||||||
|
RUN printf "#!/bin/sh\n\
|
||||||
|
set -e\n\
|
||||||
|
echo \"Starting initialization...\"\n\
|
||||||
|
echo \"Database URL: \$DATABASE_URL\"\n\
|
||||||
|
echo \"Running migrations...\"\n\
|
||||||
|
npx prisma migrate deploy\n\
|
||||||
|
echo \"Starting application...\"\n\
|
||||||
|
npm start" > /app/start.sh
|
||||||
|
|
||||||
RUN chmod +x /app/start.sh
|
RUN chmod +x /app/start.sh
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ services:
|
|||||||
build: .
|
build: .
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
|
environment:
|
||||||
|
- DATABASE_URL=file:/app/data/dev.db
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/app/data
|
- ./data:/app/data
|
||||||
restart: always
|
restart: always
|
||||||
|
|||||||
@@ -30,7 +30,8 @@
|
|||||||
"react-hook-form": "^7.71.0",
|
"react-hook-form": "^7.71.0",
|
||||||
"sonner": "^2.0.7",
|
"sonner": "^2.0.7",
|
||||||
"tailwind-merge": "^3.4.0",
|
"tailwind-merge": "^3.4.0",
|
||||||
"zod": "^4.3.5"
|
"zod": "^4.3.5",
|
||||||
|
"prisma": "^6.19.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/postcss": "^4",
|
"@tailwindcss/postcss": "^4",
|
||||||
@@ -40,7 +41,6 @@
|
|||||||
"babel-plugin-react-compiler": "1.0.0",
|
"babel-plugin-react-compiler": "1.0.0",
|
||||||
"eslint": "^9",
|
"eslint": "^9",
|
||||||
"eslint-config-next": "16.1.1",
|
"eslint-config-next": "16.1.1",
|
||||||
"prisma": "^6.19.1",
|
|
||||||
"tailwindcss": "^4",
|
"tailwindcss": "^4",
|
||||||
"tw-animate-css": "^1.4.0",
|
"tw-animate-css": "^1.4.0",
|
||||||
"typescript": "^5"
|
"typescript": "^5"
|
||||||
|
|||||||
Reference in New Issue
Block a user