diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..8981597a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,49 @@ +# Dependencies +node_modules +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Next.js build output +.next/ +out/ + +# Environment variables +.env* +!.env.example + +# Development files +.git/ +.gitignore +README.md +CHANGELOG.md +*.md + +# IDE files +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Docker files +Dockerfile* +docker-compose* +.dockerignore + +# Testing +coverage/ +.nyc_output + +# Misc +*.log +.eslintcache \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..9c1cead0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +# Use multi-stage build for optimization +FROM node:20-alpine AS base + +# Install dependencies only when needed +FROM base AS deps +RUN apk add --no-cache libc6-compat +WORKDIR /app + +# Copy package files and install dependencies +COPY package.json package-lock.json ./ +RUN npm ci --only=production && npm cache clean --force + +# Rebuild the source code only when needed +FROM base AS builder +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci + +COPY . . +RUN npm run build + +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +# Set the correct permission for prerender cache +RUN mkdir .next +RUN chown nextjs:nodejs .next + +# Automatically leverage output traces to reduce image size +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +EXPOSE 3000 + +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" + +CMD ["node", "server.js"] \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 00000000..13b75821 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,25 @@ +FROM node:20-alpine + +# Install dependencies needed for development +RUN apk add --no-cache libc6-compat + +WORKDIR /app + +# Copy package files +COPY package.json package-lock.json ./ + +# Install all dependencies (including dev dependencies) +RUN npm ci + +# Copy source code +COPY . . + +# Expose port +EXPOSE 3000 + +# Set environment variables +ENV NODE_ENV=development +ENV NEXT_TELEMETRY_DISABLED=1 + +# Start development server with hot reload +CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..4fc62c8e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +services: + waidrin: + build: + context: . + dockerfile: Dockerfile + ports: + - "3000:3000" + environment: + - NODE_ENV=production + - NEXT_TELEMETRY_DISABLED=1 + volumes: + - ./plugins:/app/plugins:ro + - ./public:/app/public:ro + restart: unless-stopped + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + + waidrin-dev: + build: + context: . + dockerfile: Dockerfile.dev + ports: + - "3001:3000" + environment: + - NODE_ENV=development + - NEXT_TELEMETRY_DISABLED=1 + volumes: + - .:/app + - /app/node_modules + - /app/.next + restart: unless-stopped + profiles: + - dev \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index ca6c9392..ead555b5 100644 --- a/next.config.ts +++ b/next.config.ts @@ -2,6 +2,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { devIndicators: false, + output: "standalone", }; export default nextConfig;