KrishnaCosmic commited on
Commit
e7fbd00
·
1 Parent(s): 1ba9d5e

deployment

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -22
Dockerfile CHANGED
@@ -1,55 +1,56 @@
1
- # ---- Base Stage ----
2
- FROM node:18-alpine AS base
3
 
4
- # ---- Dependencies Stage ----
5
  FROM base AS deps
6
  RUN apk add --no-cache libc6-compat
7
  WORKDIR /app
8
 
9
  # Copy package files
10
- COPY package.json package-lock.json* ./
11
- RUN npm ci --only=production
12
 
13
- # ---- Build Stage ----
 
 
 
 
14
  FROM base AS builder
15
  WORKDIR /app
16
-
17
- # Copy dependencies from deps stage
18
  COPY --from=deps /app/node_modules ./node_modules
19
  COPY . .
20
 
21
- # Build the Next.js application
 
 
 
 
22
  RUN npm run build
23
 
24
- # ---- Production Stage ----
25
  FROM base AS runner
26
  WORKDIR /app
27
 
28
- ENV NODE_ENV=production
29
- ENV PORT=7860
30
- ENV HOSTNAME="0.0.0.0"
31
 
32
- # Create non-root user for security (Hugging Face runs as user 1000)
33
  RUN addgroup --system --gid 1001 nodejs
34
  RUN adduser --system --uid 1001 nextjs
35
 
36
- # Copy public assets
37
  COPY --from=builder /app/public ./public
38
 
39
- # Set up standalone output directory with proper permissions
40
  RUN mkdir .next
41
  RUN chown nextjs:nodejs .next
42
 
43
- # Copy standalone build output
44
  COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
45
  COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
46
 
47
- # Ensure the app directory is writable by user 1000 (Hugging Face requirement)
48
- RUN chown -R nextjs:nodejs /app
49
-
50
  USER nextjs
51
 
 
52
  EXPOSE 7860
 
 
53
 
54
- # Start the Next.js server
55
- CMD ["node", "server.js"]
 
1
+ # FIX 1: Use Node 20 (Required for Next.js 16)
2
+ FROM node:20-alpine AS base
3
 
4
+ # Install dependencies only when needed
5
  FROM base AS deps
6
  RUN apk add --no-cache libc6-compat
7
  WORKDIR /app
8
 
9
  # Copy package files
10
+ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
 
11
 
12
+ # FIX 2: Install ALL dependencies (including devDependencies like TypeScript)
13
+ # We removed "--only=production" so the build command has the tools it needs.
14
+ RUN npm ci
15
+
16
+ # Rebuild the source code only when needed
17
  FROM base AS builder
18
  WORKDIR /app
 
 
19
  COPY --from=deps /app/node_modules ./node_modules
20
  COPY . .
21
 
22
+ # FIX 3: Add dummy environment variables so the build doesn't crash on DB connection
23
+ ENV TURSO_DATABASE_URL="libsql://build-placeholder.turso.io"
24
+ ENV TURSO_AUTH_TOKEN="build-placeholder"
25
+ ENV NEXT_TELEMETRY_DISABLED 1
26
+
27
  RUN npm run build
28
 
29
+ # Production image, copy all the files and run next
30
  FROM base AS runner
31
  WORKDIR /app
32
 
33
+ ENV NODE_ENV production
34
+ ENV NEXT_TELEMETRY_DISABLED 1
 
35
 
 
36
  RUN addgroup --system --gid 1001 nodejs
37
  RUN adduser --system --uid 1001 nextjs
38
 
 
39
  COPY --from=builder /app/public ./public
40
 
41
+ # Set permission for prerender cache
42
  RUN mkdir .next
43
  RUN chown nextjs:nodejs .next
44
 
45
+ # Automatically leverage output traces to reduce image size
46
  COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
47
  COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
48
 
 
 
 
49
  USER nextjs
50
 
51
+ # Expose the correct port for Hugging Face
52
  EXPOSE 7860
53
+ ENV PORT 7860
54
+ ENV HOSTNAME "0.0.0.0"
55
 
56
+ CMD ["node", "server.js"]