T. Narantuya 4d0baed4b2 Update Plesk environment configuration and enhance Docker setup
- 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.
2025-09-01 15:11:42 +09:00

106 lines
3.2 KiB
Docker

# 🚀 Frontend (Portal) Dockerfile - Plesk Optimized
# Multi-stage build for Next.js production deployment via Plesk
# =====================================================
# Dependencies Stage - Install all dependencies
# =====================================================
FROM node:22-alpine AS deps
# Install system dependencies for building
RUN apk add --no-cache libc6-compat dumb-init
# Install pnpm
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 package.json files for dependency resolution
COPY packages/shared/package.json ./packages/shared/
COPY apps/portal/package.json ./apps/portal/
# Install dependencies with frozen lockfile
RUN pnpm install --frozen-lockfile --prefer-offline
# =====================================================
# Builder Stage - Build the application
# =====================================================
FROM node:22-alpine AS builder
# Install pnpm
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 source code
COPY packages/shared/ ./packages/shared/
COPY apps/portal/ ./apps/portal/
COPY tsconfig.json ./
# Ensure public directory exists even if the repo doesn't have one
RUN mkdir -p /app/apps/portal/public
# Copy node_modules from deps stage
COPY --from=deps /app/node_modules ./node_modules
# Build shared package first
WORKDIR /app/packages/shared
RUN rm -f /app/packages/shared/tsconfig.tsbuildinfo && pnpm build
# Build portal with standalone output
WORKDIR /app/apps/portal
RUN pnpm 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 \
libc6-compat \
&& rm -rf /var/cache/apk/*
WORKDIR /app
# Create non-root user for security [[memory:6689308]]
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Copy the Next.js standalone build with proper ownership
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
# Create necessary directories and set permissions
RUN mkdir -p /app/logs && \
chown -R nextjs:nodejs /app
# Switch to non-root user
USER nextjs
# Expose port (required for Plesk port mapping)
EXPOSE 3000
# Environment variables
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Health check for container monitoring
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1
# Use dumb-init for proper signal handling in containers
ENTRYPOINT ["dumb-init", "--"]
CMD ["node", "apps/portal/server.js"]