From ae3daf783e2a2374c3fad7fffeabf9ff1d886822 Mon Sep 17 00:00:00 2001 From: Foohoo Date: Sun, 17 Aug 2025 13:34:08 +0100 Subject: [PATCH] add docker --- .dockerignore | 23 +++++++++++++++++++++++ Dockerfile | 41 +++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 22 ++++++++++++++++++++++ next.config.ts | 1 + 4 files changed, 87 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..317e9ea --- /dev/null +++ b/.dockerignore @@ -0,0 +1,23 @@ +# Ignore everything not necessary for Docker build context +node_modules +.next +.git +.gitignore +.vscode +.idea +coverage +.turbo +.cache +.eslintcache +.vercel +dist + +# Local env files (compose can pass env) +.env +.env.* + +# Local caches +data/*.json + +# OS files +.DS_Store diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..29952a1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +# Multi-stage Dockerfile for Next.js (standalone output) + +# 1) Install dependencies +FROM node:20-alpine AS deps +WORKDIR /app +# Install libc6-compat for some native deps if needed +RUN apk add --no-cache libc6-compat +COPY package*.json ./ +RUN npm ci + +# 2) Build +FROM node:20-alpine AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +ENV NEXT_TELEMETRY_DISABLED=1 +RUN npm run build + +# 3) Runtime (slim) +FROM node:20-alpine AS runner +WORKDIR /app +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 +# Default internal port Next.js server listens to +ENV PORT=3000 + +# Copy standalone build output +# This copies the compiled server and minimal node_modules +COPY --from=builder /app/.next/standalone ./ +# Static assets +COPY --from=builder /app/.next/static ./.next/static +# Public assets +COPY --from=builder /app/public ./public + +# Ensure data directory exists for caching JSON (mounted as a volume in compose) +RUN mkdir -p /app/data + +EXPOSE 3000 + +# Start the standalone server produced by Next.js +CMD ["node", "server.js"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1217299 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: "3.9" + +services: + app: + build: + context: . + dockerfile: Dockerfile + image: magikarp-collection:latest + environment: + - NODE_ENV=production + # Internal Next.js port (container). Do not change unless you change Dockerfile. + - PORT=3000 + # Forward any API keys if needed + - NEXT_PUBLIC_POKEMON_TCG_API_KEY=${NEXT_PUBLIC_POKEMON_TCG_API_KEY} + - POKEMON_TCG_API_KEY=${POKEMON_TCG_API_KEY} + ports: + # Select host port via APP_PORT env var; default 3000 + - "${APP_PORT:-3000}:3000" + volumes: + # Persist local cache JSON files + - ./data:/app/data + restart: unless-stopped diff --git a/next.config.ts b/next.config.ts index 98ae83e..3b17475 100644 --- a/next.config.ts +++ b/next.config.ts @@ -7,6 +7,7 @@ const nextConfig: NextConfig = { { protocol: 'https', hostname: 'api.pokemontcg.io' }, ], }, + output: 'standalone', experimental: { turbo: { rules: {},