- Enabled workspace package injection in pnpm-lock.yaml for improved dependency management. - Removed outdated SHA256 files for backend and frontend tarballs. - Refactored Dockerfile for BFF to streamline the build process and optimize production image size. - Updated Prisma client configuration to specify binary targets for Alpine compatibility. - Enhanced error handling in WhmcsLinkWorkflowService to use BadRequestException for clearer client feedback. - Adjusted entrypoint script to ensure proper database migration execution.
95 lines
3.1 KiB
Docker
95 lines
3.1 KiB
Docker
# 🚀 Frontend (Portal) Dockerfile - Plesk Optimized
|
|
# Multi-stage build for Next.js production deployment via Plesk
|
|
|
|
# =====================================================
|
|
# Stage 1: Dependencies - Install all dependencies
|
|
# =====================================================
|
|
FROM node:22-alpine AS deps
|
|
|
|
RUN apk add --no-cache libc6-compat dumb-init \
|
|
&& corepack enable && corepack prepare pnpm@10.15.0 --activate
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy workspace configuration
|
|
COPY .npmrc pnpm-workspace.yaml package.json pnpm-lock.yaml ./
|
|
COPY packages/domain/package.json ./packages/domain/
|
|
COPY packages/validation/package.json ./packages/validation/
|
|
COPY apps/portal/package.json ./apps/portal/
|
|
|
|
# Install all dependencies with scripts enabled (esbuild, sharp, etc.)
|
|
RUN pnpm install --frozen-lockfile --prefer-offline --config.ignore-scripts=false
|
|
|
|
# =====================================================
|
|
# Stage 2: Builder - Compile and build Next.js
|
|
# =====================================================
|
|
FROM node:22-alpine AS builder
|
|
|
|
RUN corepack enable && corepack prepare pnpm@10.15.0 --activate
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy workspace configuration and source
|
|
COPY .npmrc pnpm-workspace.yaml package.json pnpm-lock.yaml tsconfig.json tsconfig.base.json ./
|
|
COPY packages/ ./packages/
|
|
COPY apps/portal/ ./apps/portal/
|
|
|
|
# Ensure public directory exists
|
|
RUN mkdir -p /app/apps/portal/public
|
|
|
|
# Copy pre-installed node_modules from deps
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
|
|
# Build shared packages
|
|
RUN pnpm --filter @customer-portal/domain build && \
|
|
pnpm --filter @customer-portal/validation build
|
|
|
|
# Build-time environment variables (baked into Next.js client bundle)
|
|
ARG NEXT_PUBLIC_API_BASE=/api
|
|
ARG NEXT_PUBLIC_APP_NAME="Customer Portal"
|
|
ARG NEXT_PUBLIC_APP_VERSION=1.0.0
|
|
|
|
ENV NODE_ENV=production \
|
|
NEXT_PUBLIC_API_BASE=${NEXT_PUBLIC_API_BASE} \
|
|
NEXT_PUBLIC_APP_NAME=${NEXT_PUBLIC_APP_NAME} \
|
|
NEXT_PUBLIC_APP_VERSION=${NEXT_PUBLIC_APP_VERSION}
|
|
|
|
WORKDIR /app/apps/portal
|
|
RUN pnpm build
|
|
|
|
# =====================================================
|
|
# Stage 3: Production - Minimal Alpine runtime image
|
|
# =====================================================
|
|
FROM node:22-alpine AS production
|
|
|
|
RUN apk add --no-cache wget curl dumb-init libc6-compat \
|
|
&& rm -rf /var/cache/apk/*
|
|
|
|
WORKDIR /app
|
|
|
|
# Create non-root user
|
|
RUN addgroup --system --gid 1001 nodejs && \
|
|
adduser --system --uid 1001 nextjs
|
|
|
|
# Copy Next.js standalone build
|
|
COPY --from=builder --chown=nextjs:nodejs /app/apps/portal/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:nodejs /app/apps/portal/.next/static ./apps/portal/.next/static
|
|
COPY --from=builder --chown=nextjs:nodejs /app/apps/portal/public ./apps/portal/public
|
|
|
|
RUN mkdir -p /app/logs && chown -R nextjs:nodejs /app
|
|
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV NODE_ENV=production \
|
|
NEXT_TELEMETRY_DISABLED=1 \
|
|
PORT=3000 \
|
|
HOSTNAME="0.0.0.0"
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1
|
|
|
|
ENTRYPOINT ["dumb-init", "--"]
|
|
CMD ["node", "apps/portal/server.js"]
|