diff --git a/docker-compose.yaml b/docker-compose.yaml index 0c9f7f60..094db576 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -88,9 +88,6 @@ services: - "3000:3000" volumes: - ./frontend/.env.local:/app/.env.local:ro - environment: - - NODE_ENV=production - command: ["npm", "run", "start"] depends_on: - backend diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 00000000..3d68d349 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,13 @@ +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.next +.git + +.prettierrc +.prettierignore +*.env +env.* +README.md \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 56809ba5..69cea002 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,34 +1,65 @@ -FROM node:20-slim +# syntax=docker.io/docker/dockerfile:1 +# ---- Base Stage ---- +FROM node:22-slim AS base + +# Install dependencies only when needed +FROM base AS deps WORKDIR /app -# Copy package files first for better layer caching -COPY package*.json ./ +# Install dependencies based on the preferred package manager +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./ +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \ + else echo "Lockfile not found." && exit 1; \ + fi -# Install build dependencies for node-gyp -RUN apt-get update && apt-get install -y --no-install-recommends \ - python3 \ - make \ - g++ \ - build-essential \ - pkg-config \ - libcairo2-dev \ - libpango1.0-dev \ - libjpeg-dev \ - libgif-dev \ - librsvg2-dev \ - && rm -rf /var/lib/apt/lists/* -RUN npm install - -# Copy the frontend code +# ---- Builder Stage ---- +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules COPY . . -ENV NEXT_PUBLIC_VERCEL_ENV production +# Next.js collects completely anonymous telemetry data about general usage. +# Learn more here: https://nextjs.org/telemetry +ENV NEXT_TELEMETRY_DISABLED=1 +ENV NEXT_OUTPUT=standalone -RUN npm run build +RUN \ + if [ -f yarn.lock ]; then yarn run build; \ + elif [ -f package-lock.json ]; then npm run build; \ + elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \ + else echo "Lockfile not found." && exit 1; \ + fi + +# ---- Runner Stage ---- +FROM base AS runner +WORKDIR /app + +ENV NEXT_PUBLIC_VERCEL_ENV=production +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 + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs EXPOSE 3000 -# Default command is dev, but can be overridden in docker-compose -CMD ["npm", "start"] \ No newline at end of file +ENV PORT=3000 + +# server.js is created by next build from the standalone output +# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output +ENV HOSTNAME="0.0.0.0" +CMD ["node", "server.js"] \ No newline at end of file diff --git a/frontend/dump.rdb b/frontend/dump.rdb deleted file mode 100644 index 4c222cf1..00000000 Binary files a/frontend/dump.rdb and /dev/null differ diff --git a/frontend/next.config.ts b/frontend/next.config.ts index 77c86ad1..efd187d5 100644 --- a/frontend/next.config.ts +++ b/frontend/next.config.ts @@ -1,6 +1,7 @@ import type { NextConfig } from 'next'; -const nextConfig: NextConfig = { -}; +const nextConfig = (): NextConfig => ({ + output: (process.env.NEXT_OUTPUT as 'standalone') || undefined, +}); export default nextConfig;