deepak191z commited on
Commit
2b10cb1
·
verified ·
1 Parent(s): c972602

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +61 -14
Dockerfile CHANGED
@@ -1,34 +1,81 @@
1
- # Use Node.js 18 base image
2
  FROM node:20
3
 
4
- # Create a non-root user
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  RUN groupadd -r appuser && useradd -r -g appuser appuser
6
 
7
  # Set working directory
8
  WORKDIR /usr/src/app
9
 
10
- # Copy package files and install dependencies
11
  COPY package*.json ./
 
 
 
 
 
 
 
 
12
  RUN npm install
13
  RUN npm i playwright-extra puppeteer-extra-plugin-stealth
 
 
14
  RUN npx playwright install chromium
15
  RUN npx playwright install --with-deps
16
 
17
-
18
- # If building for production, use:
19
- # RUN npm ci --only=production
20
-
21
- # Copy application source code
22
  COPY . .
23
 
24
- # Change ownership of the app directory to the non-root user
25
  RUN chown -R appuser:appuser /usr/src/app
26
 
27
- # Switch to the non-root user
28
  USER appuser
29
 
30
- # Expose the desired port (optional, based on your server.js configuration)
31
  EXPOSE 7860
32
-
33
- # Set the default command to start the server
34
- CMD ["node", "server.js"]
 
 
1
  FROM node:20
2
 
3
+ # Switch to root to manage system dependencies and user creation
4
+ USER root
5
+
6
+ # Install system dependencies required by Playwright and Chromium
7
+ RUN apt-get update && \
8
+ apt-get install -y \
9
+ ca-certificates \
10
+ fonts-liberation \
11
+ libasound2 \
12
+ libatk-bridge2.0-0 \
13
+ libatk1.0-0 \
14
+ libc6 \
15
+ libcairo2 \
16
+ libcups2 \
17
+ libdbus-1-3 \
18
+ libexpat1 \
19
+ libfontconfig1 \
20
+ libgbm1 \
21
+ libgcc1 \
22
+ libglib2.0-0 \
23
+ libgtk-3-0 \
24
+ libnspr4 \
25
+ libnss3 \
26
+ libpango-1.0-0 \
27
+ libpangocairo-1.0-0 \
28
+ libstdc++6 \
29
+ libx11-6 \
30
+ libx11-xcb1 \
31
+ libxcb1 \
32
+ libxcomposite1 \
33
+ libxcursor1 \
34
+ libxdamage1 \
35
+ libxext6 \
36
+ libxfixes3 \
37
+ libxi6 \
38
+ libxrandr2 \
39
+ libxrender1 \
40
+ libxss1 \
41
+ libxtst6 \
42
+ lsb-release \
43
+ wget \
44
+ xdg-utils
45
+
46
+ # Create non-root user
47
  RUN groupadd -r appuser && useradd -r -g appuser appuser
48
 
49
  # Set working directory
50
  WORKDIR /usr/src/app
51
 
52
+ # Copy package files first for efficient layer caching
53
  COPY package*.json ./
54
+
55
+ # Transfer ownership to appuser before installing dependencies
56
+ RUN chown -R appuser:appuser /usr/src/app
57
+
58
+ # Switch to non-root user for dependency installation
59
+ USER appuser
60
+
61
+ # Install Node.js dependencies
62
  RUN npm install
63
  RUN npm i playwright-extra puppeteer-extra-plugin-stealth
64
+
65
+ # Install Playwright browsers under appuser's home directory
66
  RUN npx playwright install chromium
67
  RUN npx playwright install --with-deps
68
 
69
+ # Switch back to root to copy application code
70
+ USER root
 
 
 
71
  COPY . .
72
 
73
+ # Ensure appuser owns all application files
74
  RUN chown -R appuser:appuser /usr/src/app
75
 
76
+ # Switch to non-root user for runtime
77
  USER appuser
78
 
79
+ # Expose port and run application
80
  EXPOSE 7860
81
+ CMD ["node", "server.js"]