From 73a63801a358801ca426d5f3d74d4f6e8564f1f8 Mon Sep 17 00:00:00 2001 From: yznahmad Date: Thu, 3 Jul 2025 01:58:32 +0300 Subject: [PATCH] Add v1 12d20g 2123 --- webapp/Dockerfile | 58 +++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/webapp/Dockerfile b/webapp/Dockerfile index 8b407fd..ef38766 100644 --- a/webapp/Dockerfile +++ b/webapp/Dockerfile @@ -1,55 +1,55 @@ -# Stage 1: Dependencies +# Stage 1: Build the application FROM node:18-alpine AS deps +RUN apk add --no-cache libc6-compat WORKDIR /app # Install dependencies -COPY package.json package-lock.json* ./ -RUN if [ -f package-lock.json ]; then npm ci; \ - else echo "package-lock.json not found, running npm install" && npm install --production; fi +COPY webapp/package.json webapp/package-lock.json ./ +RUN npm ci -# Copy source code -COPY . . +# Copy the rest of the application +COPY webapp/ . -# Stage 2: Builder -FROM node:18-alpine AS builder -WORKDIR /app - -# Copy dependencies and source code -COPY --from=deps /app/node_modules ./node_modules -COPY . . - -# Build the application +# Set environment variables for build ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 +# Use a dummy DB_URI during build to prevent connection attempts +ENV DB_URI=mongodb://dummy:password@localhost:27017/dummy + +# Build the application RUN npm run build -# Stage 3: Runner +# Stage 2: Create the runner image FROM node:18-alpine AS runner WORKDIR /app -# Install runtime dependencies +# Install dependencies only needed for production RUN apk add --no-cache dumb-init -# Create non-root user -RUN addgroup -S nodejs && adduser -S nextjs -G nodejs +# Create a non-root user +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs -# Copy necessary files from builder -COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ -COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static -COPY --from=builder --chown=nextjs:nodejs /app/public ./public +# Copy the built application from the builder stage +COPY --from=deps /app/next.config.js ./ +COPY --from=deps /app/public ./public +COPY --from=deps /app/package.json ./ -# Set environment variables -ENV NODE_ENV=production -ENV PORT=3000 +# Copy the standalone server and static files +COPY --from=deps --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=deps --chown=nextjs:nodejs /app/.next/static ./.next/static -# Use non-root user +# Set the user to non-root USER nextjs -# Expose port +# Expose the port the app runs on EXPOSE 3000 +# Set the environment variable for the port +ENV PORT 3000 + # Use dumb-init to handle signals properly ENTRYPOINT ["/usr/bin/dumb-init", "--"] -# Start the application +# Set the command to run the application CMD ["node", "server.js"]