Spaces:
Paused
Paused
Update Dockerfile
Browse files- Dockerfile +29 -35
Dockerfile
CHANGED
|
@@ -1,64 +1,58 @@
|
|
| 1 |
-
#
|
| 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 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
git \
|
| 15 |
python3 \
|
| 16 |
-
|
| 17 |
-
g++ \
|
| 18 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 19 |
-
|
| 20 |
-
# Set the working directory inside the container
|
| 21 |
-
WORKDIR /app
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
COPY package.json pnpm-lock.yaml* ./
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
RUN chown -R node:node /app
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
RUN corepack enable
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
-
#
|
| 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
|
| 56 |
-
USER
|
| 57 |
|
| 58 |
-
# Expose the port your application
|
| 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 |
|