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
|
FROM node:18-alpine AS deps
|
||||||
|
RUN apk add --no-cache libc6-compat
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
COPY package.json package-lock.json* ./
|
COPY webapp/package.json webapp/package-lock.json ./
|
||||||
RUN if [ -f package-lock.json ]; then npm ci; \
|
RUN npm ci
|
||||||
else echo "package-lock.json not found, running npm install" && npm install --production; fi
|
|
||||||
|
|
||||||
# Copy source code
|
# Copy the rest of the application
|
||||||
COPY . .
|
COPY webapp/ .
|
||||||
|
|
||||||
# Stage 2: Builder
|
# Set environment variables for build
|
||||||
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
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
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
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 3: Runner
|
# Stage 2: Create the runner image
|
||||||
FROM node:18-alpine AS runner
|
FROM node:18-alpine AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install runtime dependencies
|
# Install dependencies only needed for production
|
||||||
RUN apk add --no-cache dumb-init
|
RUN apk add --no-cache dumb-init
|
||||||
|
|
||||||
# Create non-root user
|
# Create a non-root user
|
||||||
RUN addgroup -S nodejs && adduser -S nextjs -G nodejs
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
|
RUN adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
# Copy necessary files from builder
|
# Copy the built application from the builder stage
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
COPY --from=deps /app/next.config.js ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
COPY --from=deps /app/public ./public
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
COPY --from=deps /app/package.json ./
|
||||||
|
|
||||||
# Set environment variables
|
# Copy the standalone server and static files
|
||||||
ENV NODE_ENV=production
|
COPY --from=deps --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
ENV PORT=3000
|
COPY --from=deps --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
# Use non-root user
|
# Set the user to non-root
|
||||||
USER nextjs
|
USER nextjs
|
||||||
|
|
||||||
# Expose port
|
# Expose the port the app runs on
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Set the environment variable for the port
|
||||||
|
ENV PORT 3000
|
||||||
|
|
||||||
# Use dumb-init to handle signals properly
|
# Use dumb-init to handle signals properly
|
||||||
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
|
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
|
||||||
|
|
||||||
# Start the application
|
# Set the command to run the application
|
||||||
CMD ["node", "server.js"]
|
CMD ["node", "server.js"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user