Spaces:
Sleeping
Sleeping
File size: 1,583 Bytes
8412386 693eb13 8e23875 8412386 8e23875 1ba9d5e 8412386 9f638d2 e7fbd00 8412386 8e23875 8412386 8e23875 8412386 8e23875 9f638d2 8412386 8e23875 8412386 8e23875 8412386 8e23875 8412386 8e23875 8412386 8e23875 8412386 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | # ---- Base Stage ----
FROM node:20-alpine AS base
# ---- Dependencies Stage ----
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Copy package files
COPY package.json package-lock.json* ./
# Install ALL dependencies (including devDependencies like typescript)
# needed for the build step
RUN npm ci
# ---- Build Stage ----
FROM base AS builder
WORKDIR /app
# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build the Next.js application
RUN npm run build
# Remove devDependencies after build
RUN npm prune --omit=dev
# ---- Production Stage ----
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=7860
ENV HOSTNAME="0.0.0.0"
# Create non-root user for security (Hugging Face runs as user 1000)
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy public assets
COPY --from=builder /app/public ./public
# Set up standalone output directory with proper permissions
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Copy build output, node_modules, and custom server
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
COPY --from=builder --chown=nextjs:nodejs /app/server.js ./server.js
# Ensure the app directory is writable by user 1000 (Hugging Face requirement)
RUN chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 7860
# Start the custom server (Next.js + Socket.io)
CMD ["node", "server.js"]
|