devusman commited on
Commit
e9676bb
·
1 Parent(s): 048c2f8
Files changed (1) hide show
  1. Dockerfile +29 -16
Dockerfile CHANGED
@@ -1,27 +1,40 @@
1
- # Step 1: Use an official Node.js runtime as the base image
2
- # Using Node.js 18, which is a stable LTS (Long-Term Support) version
3
- FROM node:18
4
 
5
- # Step 2: Set the working directory inside the container
6
  WORKDIR /app
7
 
8
- # Step 3: Copy package.json and package-lock.json first
9
- # This leverages Docker's layer caching. The 'npm install' step will only be re-run
10
- # if the dependencies in package.json have changed.
11
- COPY package*.json ./
 
 
 
 
 
 
12
 
13
- # Step 4: Install the application dependencies
14
- # --production flag ensures we don't install development dependencies, keeping the image small
 
15
  RUN npm install --production
16
 
17
- # Step 5: Copy the rest of your application files into the container
18
- # This includes server.js, index.html, and any other assets like fonts or logos.
19
  COPY . .
20
 
21
- # Step 6: Expose the port the app will run on
22
- # Hugging Face Spaces typically use port 7860 by default. Our server.js will read this from process.env.PORT.
 
 
 
 
 
23
  EXPOSE 7860
24
 
25
- # Step 7: Define the command to run your application
26
- # This will execute 'node server.js' when the container starts
 
 
 
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"]