Add v1 12d20g 2123
This commit is contained in:
parent
b47c7b1c67
commit
73a63801a3
@ -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"]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user