datamk commited on
Commit
8f5d9e5
Β·
verified Β·
1 Parent(s): 755f171

Upload 63 files

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -41
Dockerfile CHANGED
@@ -1,55 +1,34 @@
1
- # ── Build Stage ─────────────────────────────────────────────────────────────
2
- # Use full node image for building to ensure all C++ tools and libs are available
3
- FROM node:20-bookworm AS builder
4
 
5
- WORKDIR /app
 
 
 
 
6
 
7
- # Copy dependency manifests
8
- COPY package*.json ./
9
 
10
- # Install all dependencies (including optional tfjs-node and devDeps for build)
11
- # We use --legacy-peer-deps to avoid strict version conflicts on different OS environments
12
- RUN npm ci --legacy-peer-deps
13
 
14
- # Copy source code
15
- COPY . .
16
 
17
- # Build static frontend
18
- # We set CI=false to prevent warnings from being treated as errors
19
- RUN CI=false npm run build
20
-
21
- # Prune dev dependencies to reduce image size
22
- RUN npm prune --omit=dev
23
-
24
- # ── Runtime Stage ───────────────────────────────────────────────────────────
25
- # Use slim for a smaller runtime footprint
26
- FROM node:20-slim
27
-
28
- WORKDIR /app
29
 
30
- # Install basic runtime dependencies (if needed by native modules)
31
- RUN apt-get update && apt-get install -y --no-install-recommends \
32
- ca-certificates \
33
- && rm -rf /var/lib/apt/lists/*
34
-
35
- # Copy build artifacts and production node_modules from builder
36
- COPY --from=builder /app/dist ./dist
37
- COPY --from=builder /app/package*.json ./
38
- COPY --from=builder /app/node_modules ./node_modules
39
- COPY --from=builder /app/server ./server
40
 
41
- # Create and set permissions for uploads directory
42
- RUN mkdir -p server/uploads && chmod 777 server/uploads
43
 
44
- # Env configuration for Hugging Face Spaces
45
  ENV NODE_ENV=production
46
  ENV PORT=7860
47
  EXPOSE 7860
48
 
49
- # Non-root security (Hugging Face compatible)
50
- RUN useradd -m -u 1000 appuser
51
- RUN chown -R appuser:appuser /app
52
- USER appuser
53
-
54
  # Start the application
55
  CMD ["node", "server/index.js"]
 
1
+ # Use full node image for a stable build environment
2
+ FROM node:20
 
3
 
4
+ # Hugging Face specific user setup (UID 1000)
5
+ RUN useradd -m -u 1000 user
6
+ USER user
7
+ ENV HOME=/home/user \
8
+ PATH=/home/user/.local/bin:$PATH
9
 
10
+ WORKDIR $HOME/app
 
11
 
12
+ # Copy dependency manifests with correct permissions
13
+ COPY --chown=user package*.json ./
 
14
 
15
+ # Install dependencies (including optional ones like tfjs-node)
16
+ RUN npm install --legacy-peer-deps
17
 
18
+ # Copy the rest of the application code
19
+ COPY --chown=user . .
 
 
 
 
 
 
 
 
 
 
20
 
21
+ # Build the frontend with increased memory limit for Vite/Rollup
22
+ ENV NODE_OPTIONS="--max-old-space-size=4096"
23
+ RUN CI=false npm run build
 
 
 
 
 
 
 
24
 
25
+ # Ensure the uploads directory exists and is writable
26
+ RUN mkdir -p server/uploads
27
 
28
+ # Environment variables for production
29
  ENV NODE_ENV=production
30
  ENV PORT=7860
31
  EXPOSE 7860
32
 
 
 
 
 
 
33
  # Start the application
34
  CMD ["node", "server/index.js"]