diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..9a4349d1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,52 @@ +# Build stage +FROM node:20-alpine AS builder + +WORKDIR /app + +# Install dependencies first (for better caching) +COPY package.json package-lock.json* ./ +RUN npm ci + +# Copy source files +COPY . . + +# Build arguments for environment variables (needed at build time for Next.js) +ARG NEXT_PUBLIC_BACKEND_HOST=http://host.docker.internal +ARG NEXT_PUBLIC_BACKEND_PORT=8023 +ARG NEXT_PUBLIC_METRICS_HOST + +# Set environment variables for build +ENV NEXT_PUBLIC_BACKEND_HOST=$NEXT_PUBLIC_BACKEND_HOST +ENV NEXT_PUBLIC_BACKEND_PORT=$NEXT_PUBLIC_BACKEND_PORT +ENV NEXT_PUBLIC_METRICS_HOST=$NEXT_PUBLIC_METRICS_HOST + +# Build the application +RUN npm run build +RUN npm run build:embed + +# Production stage +FROM node:20-alpine AS runner + +WORKDIR /app + +ENV NODE_ENV=production + +# Create non-root user for security +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +# Copy necessary files from builder +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static + +# Set correct permissions +RUN chown -R nextjs:nodejs /app +USER nextjs + +EXPOSE 3000 + +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" + +CMD ["node", "server.js"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..479d94d2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,33 @@ +services: + frontend: + build: + context: . + dockerfile: Dockerfile + args: + NEXT_PUBLIC_BACKEND_HOST: ${NEXT_PUBLIC_BACKEND_HOST:-http://host.docker.internal} + NEXT_PUBLIC_BACKEND_PORT: ${NEXT_PUBLIC_BACKEND_PORT:-8023} + NEXT_PUBLIC_METRICS_HOST: ${NEXT_PUBLIC_METRICS_HOST:-} + container_name: plateerag_frontend + ports: + - "${FRONTEND_PORT:-3000}:3000" + environment: + - NODE_ENV=production + - NEXT_PUBLIC_BACKEND_HOST=${NEXT_PUBLIC_BACKEND_HOST:-http://host.docker.internal} + - NEXT_PUBLIC_BACKEND_PORT=${NEXT_PUBLIC_BACKEND_PORT:-8023} + - NEXT_PUBLIC_METRICS_HOST=${NEXT_PUBLIC_METRICS_HOST:-} + extra_hosts: + - "host.docker.internal:host-gateway" + networks: + - plateer_network + restart: unless-stopped + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + +networks: + plateer_network: + external: true + name: plateer_network diff --git a/next.config.ts b/next.config.ts index 8e70feba..073e4515 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,6 +1,7 @@ import type { NextConfig } from 'next'; const nextConfig: NextConfig = { + output: 'standalone', experimental: { proxyTimeout: 600000, },