106 lines
3.2 KiB
Docker
Raw Normal View History

# 🚀 Frontend (Portal) Dockerfile - Plesk Optimized
# Multi-stage build for Next.js production deployment via Plesk
2025-08-21 15:24:40 +09:00
# =====================================================
# 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
2025-08-21 15:24:40 +09:00
# 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 ./
2025-08-21 15:24:40 +09:00
# Copy package.json files for dependency resolution
COPY packages/shared/package.json ./packages/shared/
COPY apps/portal/package.json ./apps/portal/
2025-08-21 15:24:40 +09:00
# Install dependencies with frozen lockfile
RUN pnpm install --frozen-lockfile --prefer-offline
2025-08-21 15:24:40 +09:00
# =====================================================
# Builder Stage - Build the application
# =====================================================
FROM node:22-alpine AS builder
# Install pnpm
RUN corepack enable && corepack prepare pnpm@10.15.0 --activate
2025-08-21 15:24:40 +09:00
WORKDIR /app
# Copy workspace configuration
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
2025-08-21 15:24:40 +09:00
# 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
2025-08-21 15:24:40 +09:00
WORKDIR /app/packages/shared
RUN rm -f /app/packages/shared/tsconfig.tsbuildinfo && pnpm build
# Build portal with standalone output
2025-08-21 15:24:40 +09:00
WORKDIR /app/apps/portal
RUN pnpm build
2025-08-21 15:24:40 +09:00
# =====================================================
# Production Stage - Final optimized image for Plesk
2025-08-21 15:24:40 +09:00
# =====================================================
FROM node:22-alpine AS production
# Install runtime dependencies including dumb-init for proper signal handling
2025-08-21 15:24:40 +09:00
RUN apk add --no-cache \
wget \
curl \
dumb-init \
libc6-compat \
2025-08-21 15:24:40 +09:00
&& rm -rf /var/cache/apk/*
WORKDIR /app
# Create non-root user for security [[memory:6689308]]
2025-08-21 15:24:40 +09:00
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Copy the Next.js standalone build with proper ownership
2025-08-21 15:24:40 +09:00
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
2025-08-21 15:24:40 +09:00
# Switch to non-root user
USER nextjs
# Expose port (required for Plesk port mapping)
EXPOSE 3000
2025-08-21 15:24:40 +09:00
# 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
2025-08-21 15:24:40 +09:00
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"]