datamk commited on
Commit
755f171
Β·
verified Β·
1 Parent(s): 0d8a28a

Upload 63 files

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -20
Dockerfile CHANGED
@@ -1,43 +1,44 @@
1
  # ── Build Stage ─────────────────────────────────────────────────────────────
2
- FROM node:20-slim AS builder
 
3
 
4
  WORKDIR /app
5
 
6
- # Install build tools for native modules (sharp, tfjs-node)
7
- RUN apt-get update && apt-get install -y --no-install-recommends \
8
- python3 \
9
- make \
10
- g++ \
11
- && rm -rf /var/lib/apt/lists/*
12
-
13
- # Install all dependencies (including optional tfjs-node)
14
  COPY package*.json ./
15
- RUN npm ci
16
 
17
- # Copy source and build static frontend
 
 
 
 
18
  COPY . .
19
- RUN npm run build
20
 
21
- # Prune devDeps (keeps production node_modules and native binaries)
 
 
 
 
22
  RUN npm prune --omit=dev
23
 
24
  # ── Runtime Stage ───────────────────────────────────────────────────────────
 
25
  FROM node:20-slim
26
 
27
  WORKDIR /app
28
 
29
- # Runtime dependencies for sharp/tensorflow
30
  RUN apt-get update && apt-get install -y --no-install-recommends \
31
- libvips-dev \
32
  && rm -rf /var/lib/apt/lists/*
33
 
34
- # Copy only what's needed from builder
35
  COPY --from=builder /app/dist ./dist
36
  COPY --from=builder /app/package*.json ./
37
  COPY --from=builder /app/node_modules ./node_modules
38
  COPY --from=builder /app/server ./server
39
 
40
- # Ensure upload directory remains writable
41
  RUN mkdir -p server/uploads && chmod 777 server/uploads
42
 
43
  # Env configuration for Hugging Face Spaces
@@ -45,9 +46,10 @@ ENV NODE_ENV=production
45
  ENV PORT=7860
46
  EXPOSE 7860
47
 
48
- # Non-root security
49
- RUN groupadd -r appgroup && useradd -r -g appgroup appuser
50
- RUN chown -R appuser:appgroup /app
51
  USER appuser
52
 
 
53
  CMD ["node", "server/index.js"]
 
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
 
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"]