updated
Browse files- Dockerfile +29 -16
Dockerfile
CHANGED
|
@@ -1,27 +1,40 @@
|
|
| 1 |
-
# Step 1: Use
|
| 2 |
-
|
| 3 |
-
FROM node:18
|
| 4 |
|
| 5 |
-
# Step 2: Set the working directory
|
| 6 |
WORKDIR /app
|
| 7 |
|
| 8 |
-
# Step 3:
|
| 9 |
-
#
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
# Step 4:
|
| 14 |
-
#
|
|
|
|
| 15 |
RUN npm install --production
|
| 16 |
|
| 17 |
-
# Step 5: Copy the rest of your application
|
| 18 |
-
# This includes server.js, index.html, and any other assets like fonts or logos.
|
| 19 |
COPY . .
|
| 20 |
|
| 21 |
-
# Step 6:
|
| 22 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
EXPOSE 7860
|
| 24 |
|
| 25 |
-
# Step
|
| 26 |
-
#
|
|
|
|
|
|
|
|
|
|
| 27 |
CMD ["node", "index.js"]
|
|
|
|
| 1 |
+
# Step 1: Use a specific, stable Debian-based Node.js image
|
| 2 |
+
FROM node:18-bullseye
|
|
|
|
| 3 |
|
| 4 |
+
# Step 2: Set the working directory
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
+
# Step 3: INSTALL SYSTEM DEPENDENCIES (The Fix)
|
| 8 |
+
# Update the package list and install 'build-essential' and 'python'.
|
| 9 |
+
# These are required to compile the native C++ addons for 'sqlite3'.
|
| 10 |
+
# --no-install-recommends keeps the image smaller.
|
| 11 |
+
# We clean up the apt cache afterwards to reduce final image size.
|
| 12 |
+
RUN apt-get update && apt-get install -y \
|
| 13 |
+
build-essential \
|
| 14 |
+
python \
|
| 15 |
+
--no-install-recommends \
|
| 16 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
+
# Step 4: Copy package.json and install Node.js dependencies
|
| 19 |
+
# This is done before copying the rest of the code to leverage Docker layer caching.
|
| 20 |
+
COPY package*.json ./
|
| 21 |
RUN npm install --production
|
| 22 |
|
| 23 |
+
# Step 5: Copy the rest of your application code
|
|
|
|
| 24 |
COPY . .
|
| 25 |
|
| 26 |
+
# Step 6: Create an empty database file and set permissions
|
| 27 |
+
# The node user (UID 1000) needs to be able to write to the database file.
|
| 28 |
+
# This prevents potential "database is read-only" errors.
|
| 29 |
+
RUN touch quotes.db && chown node:node quotes.db
|
| 30 |
+
|
| 31 |
+
# Step 7: Expose the port the app will run on.
|
| 32 |
+
# Hugging Face Spaces will set the PORT environment variable, usually to 7860.
|
| 33 |
EXPOSE 7860
|
| 34 |
|
| 35 |
+
# Step 8: Specify the user to run the app.
|
| 36 |
+
# The official Node image provides a non-root 'node' user for better security.
|
| 37 |
+
USER node
|
| 38 |
+
|
| 39 |
+
# Step 9: Define the command to run your application
|
| 40 |
CMD ["node", "index.js"]
|