understanding commited on
Commit
ae39c21
·
verified ·
1 Parent(s): a8498e2

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +29 -35
Dockerfile CHANGED
@@ -1,64 +1,58 @@
1
- # --- Stage 1: Base Setup ---
2
-
3
- # Use Node.js 20 slim version as the base image
4
- FROM node:20-slim AS base
5
 
6
  # Set environment variables
7
  ENV NODE_ENV=development \
8
  PNPM_HOME="/pnpm" \
9
  PATH="$PNPM_HOME:$PATH"
10
 
11
- # Update package lists, install git and common build dependencies, and clean up
12
- RUN apt-get update && \
13
- apt-get install -y --no-install-recommends \
14
  git \
15
  python3 \
16
- make \
17
- g++ \
18
- && rm -rf /var/lib/apt/lists/*
19
-
20
- # Set the working directory inside the container
21
- WORKDIR /app
22
 
23
- # --- Copy and Chown Before Corepack ---
24
- # Copy package.json and pnpm lock file first
25
- # IMPORTANT: Ensure package.json contains the "packageManager" field for reliability on HF
26
- COPY package.json pnpm-lock.yaml* ./
27
 
28
- # Change ownership of the /app directory to the 'node' user early
29
- # This ensures subsequent commands/copies have correct permissions
30
- RUN chown -R node:node /app
31
 
32
- # --- PNPM Activation ---
33
- # Enable corepack (built into Node >=16.13 / Node 20 includes this) to manage pnpm
34
- RUN corepack enable
35
 
36
- # Verify pnpm is active and check its version (optional, for confirmation)
37
- RUN pnpm --version
38
- # --- End PNPM Activation ---
39
 
40
- # --- Stage 2: Install Dependencies ---
41
- # Install dependencies using pnpm. Requires pnpm to be active (done above).
42
  RUN pnpm install --frozen-lockfile
43
 
44
- # --- Stage 3: Build & Runtime Setup ---
45
-
46
  # Copy the rest of your application code
47
- # Files will be owned by 'node' because of the earlier chown on /app
48
  COPY . .
49
 
 
 
 
 
 
 
 
 
 
50
  # --- Removed Directory Creation for /app ---
51
  # DO NOT create session/downloads/auth_info_baileys here.
52
  # Your application code should write persistent data to the /data directory,
53
  # which requires enabling Persistent Storage in Hugging Face Space settings.
54
 
55
- # Switch to the non-root 'node' user (security best practice)
56
- USER node
57
 
58
- # Expose the port your application will run on
59
  EXPOSE 7860
60
 
61
  # The command to run your application using pnpm in dev mode
62
- # Consider using "pnpm run start" if you don't need --watch in deployment
63
  CMD ["pnpm", "run", "dev"]
64
 
 
1
+ # Use Node.js 20 Alpine version as the base image (lightweight but check compatibility)
2
+ FROM node:20-alpine
 
 
3
 
4
  # Set environment variables
5
  ENV NODE_ENV=development \
6
  PNPM_HOME="/pnpm" \
7
  PATH="$PNPM_HOME:$PATH"
8
 
9
+ # Install prerequisites using apk (Alpine package manager)
10
+ # Add git, python3, make, g++ (build-base provides make/g++)
11
+ RUN apk add --no-cache \
12
  git \
13
  python3 \
14
+ build-base
 
 
 
 
 
15
 
16
+ # Install pnpm globally using npm (common method on Alpine)
17
+ # Consider matching the version from your package.json "packageManager" field if added
18
+ RUN npm install -g pnpm
 
19
 
20
+ # Verify pnpm installation
21
+ RUN pnpm --version
 
22
 
23
+ # Set the working directory
24
+ WORKDIR /app
 
25
 
26
+ # Copy package manifests
27
+ # IMPORTANT: Ensure package.json contains the "packageManager" field for reliability
28
+ COPY package.json pnpm-lock.yaml* ./
29
 
30
+ # Install ALL dependencies using pnpm (needed for devDependencies like vite-node)
 
31
  RUN pnpm install --frozen-lockfile
32
 
 
 
33
  # Copy the rest of your application code
 
34
  COPY . .
35
 
36
+ # --- Create Non-Root User for Alpine ---
37
+ # Alpine images don't have a 'node' user by default like Debian ones
38
+ # Create a non-root user and group (-S for system user/group)
39
+ RUN addgroup -S appgroup && adduser -S appuser -G appgroup
40
+
41
+ # Change ownership of the app directory to the new user
42
+ RUN chown -R appuser:appgroup /app
43
+ # --- End User Creation ---
44
+
45
  # --- Removed Directory Creation for /app ---
46
  # DO NOT create session/downloads/auth_info_baileys here.
47
  # Your application code should write persistent data to the /data directory,
48
  # which requires enabling Persistent Storage in Hugging Face Space settings.
49
 
50
+ # Switch to the non-root user
51
+ USER appuser
52
 
53
+ # Expose the port your application listens on
54
  EXPOSE 7860
55
 
56
  # The command to run your application using pnpm in dev mode
 
57
  CMD ["pnpm", "run", "dev"]
58