♻️ refactor(core): Restructure project for better module separation

This commit is contained in:
web@ppanel
2024-12-26 02:53:28 +07:00
parent 17ce96a423
commit 9d0cb8b869
368 changed files with 152606 additions and 47239 deletions
+14 -37
View File
@@ -1,46 +1,23 @@
FROM node:20-alpine AS base
# Step 1. Rebuild the source code only when needed
FROM base AS builder
# Use the official lightweight Bun image
FROM oven/bun:latest AS base
# Set working directory
WORKDIR /app
COPY . .
# Create a non-root user for running the production application
RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs
# Install dependencies based on the preferred package manager
# Omit --production flag for TypeScript devDependencies
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --ignore-scripts; \
# Allow install without lockfile, so example works even without Node.js installed locally
else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \
fi
RUN npx turbo telemetry disable
RUN npx turbo build --filter=ppanel-admin-web
# Note: It is not necessary to add an intermediate step that does a full copy of `node_modules` here
# Step 2. Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Change to non-root user
USER nextjs
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/apps/admin/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/apps/admin/.next/static ./apps/admin/.next/static
COPY --from=builder --chown=nextjs:nodejs /app/apps/admin/public ./apps/admin/public
# Copy necessary files for production
COPY ./apps/admin/.next/standalone ./
COPY ./apps/admin/.next/static ./apps/admin/.next/static
COPY ./apps/admin/public ./apps/admin/public
# Environment variables must be redefined at run time
# Uncomment the following line to disable telemetry at run time
# Disable Next.js telemetry at runtime
ENV NEXT_TELEMETRY_DISABLED=1
# Note: Don't expose ports here, Compose will handle that for us
CMD ["node", "apps/admin/server.js"]
# Set default command
CMD ["bun", "apps/admin/server.js"]
+15 -36
View File
@@ -1,46 +1,25 @@
FROM node:20-alpine AS base
# Step 1. Rebuild the source code only when needed
FROM base AS builder
# Use the official lightweight Bun image
FROM oven/bun:latest AS base
# Set working directory
WORKDIR /app
COPY . .
# Create non-root user and set permissions
RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs
# Install dependencies based on the preferred package manager
# Omit --production flag for TypeScript devDependencies
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --ignore-scripts; \
# Allow install without lockfile, so example works even without Node.js installed locally
else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \
fi
# Copy build output and static files
COPY ./apps/user/.next/standalone ./
COPY ./apps/user/.next/static ./apps/user/.next/static
COPY ./apps/user/public ./apps/user/public
RUN npx turbo telemetry disable
RUN npx turbo build --filter=ppanel-user-web
# Change ownership to non-root user
RUN chown -R nextjs:nodejs /app
# Note: It is not necessary to add an intermediate step that does a full copy of `node_modules` here
# Step 2. Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/apps/user/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/apps/user/.next/static ./apps/user/.next/static
COPY --from=builder --chown=nextjs:nodejs /app/apps/user/public ./apps/user/public
# Environment variables must be redefined at run time
# Uncomment the following line to disable telemetry at run time
# Disable Next.js telemetry
ENV NEXT_TELEMETRY_DISABLED=1
# Note: Don't expose ports here, Compose will handle that for us
CMD ["node", "apps/user/server.js"]
# Default command to start the server
CMD ["bun", "apps/user/server.js"]