From 6c0aef1d88d6b88cf935d1f2e097c9e0effad2fd Mon Sep 17 00:00:00 2001 From: R0m1k3 Date: Fri, 10 Apr 2026 10:01:55 +0200 Subject: [PATCH] feat: add Docker support with multi-stage build, compose configuration, and standalone output mode --- .dockerignore | 13 ++++++++++++ Dockerfile | 52 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 26 +++++++++++++++++++++++ entrypoint.sh | 16 ++++++++++++++ next.config.ts | 2 +- 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..38f3819 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +node_modules +.next +.git +.env +*.db +*.db-journal +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.dockerignore +Dockerfile +docker-compose.yml +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..55e1bda --- /dev/null +++ b/Dockerfile @@ -0,0 +1,52 @@ +# Stage 1: Build +FROM node:20-bookworm-slim AS builder + +WORKDIR /app + +# Install build dependencies for better-sqlite3 and bcrypt +RUN apt-get update && apt-get install -y \ + python3 \ + make \ + g++ \ + && rm -rf /var/lib/apt/lists/* + +COPY package*.json ./ +COPY prisma ./prisma/ + +RUN npm install + +COPY . . + +# Generate Prisma Client (crucial for standalone) +RUN npx prisma generate + +# Build Next.js app +RUN npm run build + +# Stage 2: Runner +FROM node:20-bookworm-slim AS runner + +WORKDIR /app + +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 + +# Install runtime dependencies for SQLite +RUN apt-get update && apt-get install -y \ + openssl \ + && rm -rf /var/lib/apt/lists/* + +# Copy standalone build and static files +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +COPY --from=builder /app/prisma ./prisma + +# Expose port +EXPOSE 3214 + +# Set up entrypoint script +COPY entrypoint.sh ./ +RUN chmod +x entrypoint.sh + +ENTRYPOINT ["./entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..93aada5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +services: + menu-app: + build: + context: . + dockerfile: Dockerfile + container_name: menu-professional + ports: + - "3214:3214" + volumes: + - ./.env:/app/.env + - menu_db:/app/prisma + environment: + - NODE_ENV=production + - DATABASE_URL=file:/app/prisma/dev.db + - PORT=3214 + networks: + - nginx_default + restart: always + +networks: + nginx_default: + external: true + +volumes: + menu_db: + driver: local diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..c517fe9 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Exit immediately if a command exits with a non-zero status +set -e + +echo "Starting Menu Professional..." + +# Run database synchronization +# Note: In a production environment with persistent data, +# 'prisma db push' ensures the schema matches the code. +echo "Synchronizing database schema..." +npx prisma db push --accept-data-loss || echo "Database sync failed, but proceeding..." + +# Start the application using node as Next.js is in standalone mode +echo "Launching server..." +exec node server.js diff --git a/next.config.ts b/next.config.ts index e9ffa30..225e495 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + output: 'standalone', }; export default nextConfig;