Leon4gr45 commited on
Commit
9537f47
·
verified ·
1 Parent(s): 28bf6c6

Fix Dockerfile and ensure mandatory endpoints

Browse files
Files changed (1) hide show
  1. Dockerfile +12 -32
Dockerfile CHANGED
@@ -1,51 +1,31 @@
1
- FROM node:22-alpine AS base
2
 
3
- # Install dependencies only when needed
4
- FROM base AS deps
5
  RUN apk add --no-cache libc6-compat
6
  WORKDIR /app
 
7
 
8
- # Install dependencies based on the preferred package manager
9
  COPY package.json pnpm-lock.yaml* ./
10
- RUN corepack enable pnpm && pnpm i --frozen-lockfile
11
 
12
- # Rebuild the source code only when needed
13
- FROM base AS builder
14
- WORKDIR /app
15
- COPY --from=deps /app/node_modules ./node_modules
16
  COPY . .
17
-
18
- # Disable telemetry during the build.
19
  ENV NEXT_TELEMETRY_DISABLED 1
 
20
 
21
- RUN corepack enable pnpm && pnpm run build
22
-
23
- # Production image, copy all the files and run next
24
- FROM base AS runner
25
  WORKDIR /app
26
-
27
  ENV NODE_ENV production
28
  ENV NEXT_TELEMETRY_DISABLED 1
29
 
30
- # HF Spaces run with UID 1000, which is the 'node' user in node:22-alpine
31
- # We ensure the 'node' user is used to avoid UID conflicts
32
-
33
- COPY --from=builder /app/public ./public
34
-
35
- # Set the correct permission for prerender cache
36
- RUN mkdir .next
37
- RUN chown node:node .next
38
-
39
- # Automatically leverage output traces to reduce image size
40
- # https://nextjs.org/docs/advanced-features/output-file-tracing
41
- COPY --from=builder --chown=node:node /app/.next/standalone ./
42
- COPY --from=builder --chown=node:node /app/.next/static ./.next/static
43
 
44
  USER node
45
-
46
  EXPOSE 7860
47
-
48
  ENV PORT 7860
49
  ENV HOSTNAME "0.0.0.0"
50
-
51
  CMD ["node", "server.js"]
 
1
+ FROM node:20-alpine AS base
2
 
 
 
3
  RUN apk add --no-cache libc6-compat
4
  WORKDIR /app
5
+ RUN npm install -g pnpm
6
 
7
+ # Install dependencies
8
  COPY package.json pnpm-lock.yaml* ./
9
+ RUN pnpm i --no-frozen-lockfile --ignore-scripts
10
 
11
+ # Build
 
 
 
12
  COPY . .
 
 
13
  ENV NEXT_TELEMETRY_DISABLED 1
14
+ RUN pnpm run build
15
 
16
+ # Runner
17
+ FROM node:20-alpine AS runner
 
 
18
  WORKDIR /app
 
19
  ENV NODE_ENV production
20
  ENV NEXT_TELEMETRY_DISABLED 1
21
 
22
+ COPY --from=base /app/public ./public
23
+ RUN mkdir -p .next && chown node:node .next
24
+ COPY --from=base --chown=node:node /app/.next/standalone ./
25
+ COPY --from=base --chown=node:node /app/.next/static ./.next/static
 
 
 
 
 
 
 
 
 
26
 
27
  USER node
 
28
  EXPOSE 7860
 
29
  ENV PORT 7860
30
  ENV HOSTNAME "0.0.0.0"
 
31
  CMD ["node", "server.js"]