- Added detailed instructions for Plesk deployment in `.env.plesk` and `compose-plesk.yaml`. - Updated `.gitignore` to exclude Docker-related files. - Enhanced Dockerfiles for both frontend and backend to optimize for Plesk deployment. - Refined TypeScript configurations across various files for improved module resolution and compatibility. - Removed obsolete logger fixes summary file to streamline documentation.
133 lines
4.1 KiB
Docker
133 lines
4.1 KiB
Docker
# 🚀 Backend (BFF) Dockerfile - Plesk Optimized
|
|
# Multi-stage build for NestJS production deployment via Plesk
|
|
|
|
# =====================================================
|
|
# Dependencies Stage - Install all dependencies
|
|
# =====================================================
|
|
FROM node:22-bookworm-slim AS deps
|
|
|
|
# Install system dependencies for building
|
|
RUN apt-get update && apt-get install -y dumb-init ca-certificates && rm -rf /var/lib/apt/lists/* \
|
|
&& corepack enable && corepack prepare pnpm@10.15.0 --activate
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy workspace configuration
|
|
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
|
|
|
|
# Copy package.json files for dependency resolution
|
|
COPY packages/shared/package.json ./packages/shared/
|
|
COPY apps/bff/package.json ./apps/bff/
|
|
|
|
# Install ALL dependencies (needed for build)
|
|
RUN pnpm install --frozen-lockfile --prefer-offline
|
|
|
|
# =====================================================
|
|
# Builder Stage - Build the application
|
|
# =====================================================
|
|
FROM node:22-bookworm-slim AS builder
|
|
|
|
# Install pnpm
|
|
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* \
|
|
&& corepack enable && corepack prepare pnpm@10.15.0 --activate
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy workspace configuration
|
|
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
|
|
|
|
# Copy source code
|
|
COPY packages/shared/ ./packages/shared/
|
|
COPY apps/bff/ ./apps/bff/
|
|
COPY tsconfig.json ./
|
|
|
|
# Copy node_modules from deps stage
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
|
|
WORKDIR /app/packages/shared
|
|
RUN pnpm build
|
|
|
|
WORKDIR /app
|
|
# Align workspace modules in builder (ensures proper symlinks and resolution)
|
|
RUN pnpm install --frozen-lockfile --prefer-offline
|
|
# Build BFF (generate Prisma client then compile)
|
|
RUN pnpm --filter @customer-portal/bff exec prisma generate && \
|
|
pnpm --filter @customer-portal/bff build
|
|
|
|
# =====================================================
|
|
# Production Stage - Final optimized image for Plesk
|
|
# =====================================================
|
|
FROM node:22-alpine AS production
|
|
|
|
# Install runtime dependencies including dumb-init for proper signal handling
|
|
RUN apk add --no-cache \
|
|
wget \
|
|
curl \
|
|
dumb-init \
|
|
# Toolchain for native rebuilds (bcrypt) and Prisma (openssl), and nc for wait-for
|
|
python3 \
|
|
make \
|
|
g++ \
|
|
pkgconfig \
|
|
openssl \
|
|
netcat-openbsd \
|
|
&& rm -rf /var/cache/apk/*
|
|
|
|
# Install pnpm for production dependencies
|
|
RUN corepack enable && corepack prepare pnpm@10.15.0 --activate
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy workspace configuration
|
|
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
|
|
COPY packages/shared/package.json ./packages/shared/
|
|
COPY apps/bff/package.json ./apps/bff/
|
|
|
|
# Install ONLY production dependencies (lightweight)
|
|
ENV HUSKY=0
|
|
RUN pnpm install --frozen-lockfile --prod --ignore-scripts
|
|
|
|
# Rebuild only critical native module(s)
|
|
RUN pnpm rebuild bcrypt
|
|
|
|
# Copy built applications and shared package from builder
|
|
COPY --from=builder /app/packages/shared/dist ./packages/shared/dist
|
|
COPY --from=builder /app/apps/bff/dist ./apps/bff/dist
|
|
COPY --from=builder /app/apps/bff/prisma ./apps/bff/prisma
|
|
|
|
# Generate Prisma client in the production image (ensures engines and client are present)
|
|
WORKDIR /app/apps/bff
|
|
RUN pnpm prisma generate
|
|
|
|
# Strip build toolchain to shrink image
|
|
RUN apk del --no-cache python3 make g++ pkgconfig && rm -rf /root/.cache /var/cache/apk/*
|
|
|
|
# Create non-root user for security [[memory:6689308]]
|
|
RUN addgroup --system --gid 1001 nodejs && \
|
|
adduser --system --uid 1001 nestjs
|
|
|
|
# Create necessary directories and set permissions
|
|
RUN mkdir -p /app/secrets /app/logs && \
|
|
chown -R nestjs:nodejs /app
|
|
|
|
# Switch to non-root user
|
|
USER nestjs
|
|
|
|
# Expose port (required for Plesk port mapping)
|
|
EXPOSE 4000
|
|
|
|
# Environment variables
|
|
ENV NODE_ENV=production
|
|
ENV PORT=4000
|
|
|
|
# Set working directory for the app
|
|
WORKDIR /app/apps/bff
|
|
|
|
# Health check for container monitoring
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:4000/health || exit 1
|
|
|
|
# Use dumb-init for proper signal handling in containers
|
|
ENTRYPOINT ["dumb-init", "--"]
|
|
CMD ["node", "dist/main"]
|