File size: 2,233 Bytes
f42efe4
 
 
b130d3c
f42efe4
 
 
5523e63
 
f42efe4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
# --- Stage 1: Builder ---
# Use a Node.js image suitable for building (includes build tools if needed)
FROM node:18-alpine AS builder
RUN ls
# Set working directory
WORKDIR /app

RUN npm install

# Copy package.json and package-lock.json (or yarn.lock/pnpm-lock.yaml)
# Copying these separately allows Docker to cache this step if only code changes
COPY package.json ./
# If you are using yarn, uncomment the line below and comment out the npm line
# COPY yarn.lock ./
# If you are using pnpm, uncomment the line below and comment out the npm line
# COPY pnpm-lock.yaml ./
COPY package-lock.json ./ # Use package-lock.json if you use npm


# Install dependencies including devDependencies for the build
# Use --frozen-lockfile or --ci for deterministic builds if using npm or yarn v1
RUN npm ci # Or `yarn install --frozen-lockfile` or `pnpm install --frozen-lockfile`


# Copy the rest of the application code
COPY . .

# Build the Next.js application
# NEXT_TELEMETRY_DISABLED=1 disables Next.js telemetry during the build
RUN NEXT_TELEMETRY_DISABLED=1 npm run build

# --- Stage 2: Runner ---
# Use a smaller, production-focused Node.js image
FROM node:18-alpine AS runner

# Set working directory
WORKDIR /app

# Copy necessary files from the builder stage
# Copy production dependencies
COPY --from=builder /app/package.json ./
COPY --from=builder /app/node_modules ./node_modules
# Copy the build output (.next folder)
COPY --from=builder /app/.next ./.next
# Copy public assets
COPY --from=builder /app/public ./public
# Copy next.config.js if it exists
COPY --from=builder /app/next.config.js ./next.config.js


# Set the environment variable for the Next.js port (default is 3000)
# Hugging Face Spaces typically exposes port 7860 for Gradio/Streamlit/etc,
# but for general web apps (like Next.js via the static host option or if you set up a custom server),
# it might expose port 3000 by default when detecting a standard Next.js app.
# It's good practice to set this, but Spaces often handles port mapping.
ENV PORT 3000


# Expose the port the application will run on
EXPOSE 3000

# Disable Next.js telemetry at runtime
ENV NEXT_TELEMETRY_DISABLED 1

# Command to run the production Next.js server
CMD ["npm", "start"]