diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8a9efa0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +node_modules +.next +dist +.git +.gitignore +tests +coverage +.env +.env.* +*.md +LICENSE +vitest.config.ts +eslint.config.mjs +prettier.config.mjs +postcss.config.mjs +commitlint.config.mjs +lint-staged.config.mjs +pnpm-lock.yaml +pnpm-workspace.yaml diff --git a/Dockerfile b/Dockerfile index 33edb86..67c0d0b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,55 +1,74 @@ -# Multi-stage build for production -# Stage 1: Dependencies +# Multi-stage build for barazo-web (Next.js standalone) +# Build context: monorepo root (docker build -f barazo-web/Dockerfile .) + +# --------------------------------------------------------------------------- +# Stage 1: Install dependencies +# --------------------------------------------------------------------------- FROM node:24-alpine AS deps RUN apk add --no-cache libc6-compat -WORKDIR /app +WORKDIR /workspace + +# Enable pnpm via corepack +RUN corepack enable && corepack prepare pnpm@10.29.2 --activate + +# Copy workspace root config +COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ -# Install pnpm -RUN corepack enable && corepack prepare pnpm@9.0.0 --activate +# Copy all workspace package.json files (needed for pnpm install) +COPY barazo-lexicons/package.json ./barazo-lexicons/ +COPY barazo-api/package.json ./barazo-api/ +COPY barazo-web/package.json ./barazo-web/ -# Copy package files -COPY package.json pnpm-lock.yaml ./ +# Install all dependencies RUN pnpm install --frozen-lockfile -# Stage 2: Builder +# --------------------------------------------------------------------------- +# Stage 2: Build +# --------------------------------------------------------------------------- FROM node:24-alpine AS builder -WORKDIR /app +WORKDIR /workspace + +RUN corepack enable && corepack prepare pnpm@10.29.2 --activate -# Install pnpm -RUN corepack enable && corepack prepare pnpm@9.0.0 --activate +# Copy installed dependencies +COPY --from=deps /workspace/ ./ -# Copy dependencies from deps stage -COPY --from=deps /app/node_modules ./node_modules -COPY . . +# Copy web source +COPY barazo-web/ ./barazo-web/ -# Build application +# Build Next.js (produces .next/standalone via output: 'standalone') ENV NEXT_TELEMETRY_DISABLED=1 -RUN pnpm build +RUN pnpm --filter @barazo-forum/web build -# Stage 3: Production +# --------------------------------------------------------------------------- +# Stage 3: Production runner +# --------------------------------------------------------------------------- FROM node:24-alpine AS runner WORKDIR /app ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 +# docker-compose healthcheck expects port 3001 +ENV PORT=3001 +# Bind to all interfaces (default binds to container hostname only) +ENV HOSTNAME=0.0.0.0 # Create non-root user -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs +RUN addgroup --system --gid 1001 nodejs && \ + adduser --system --uid 1001 nextjs + +# Copy standalone server (includes node_modules and server.js) +COPY --from=builder --chown=nextjs:nodejs /workspace/barazo-web/.next/standalone/ ./ -# Copy static files from builder -COPY --from=builder /app/dist ./dist -COPY --from=builder /app/package.json ./package.json +# Copy static assets into the standalone output (must be relative to server.js) +COPY --from=builder --chown=nextjs:nodejs /workspace/barazo-web/.next/static/ ./barazo-web/.next/static/ +COPY --from=builder --chown=nextjs:nodejs /workspace/barazo-web/public/ ./barazo-web/public/ -# Change ownership USER nextjs -# Expose port -EXPOSE 3000 +EXPOSE 3001 -# Health check -HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ - CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => r.statusCode === 200 ? process.exit(0) : process.exit(1))" +HEALTHCHECK --interval=30s --timeout=10s --start-period=20s --retries=3 \ + CMD wget -qO- http://127.0.0.1:3001/api/health || exit 1 -# Start static server -CMD ["npx", "serve", "dist", "-l", "3000"] +CMD ["node", "barazo-web/server.js"]