Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +44 -11
Dockerfile
CHANGED
|
@@ -1,28 +1,61 @@
|
|
| 1 |
-
# Use
|
| 2 |
-
FROM
|
| 3 |
-
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
&& apt-get clean \
|
| 7 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
|
|
|
|
| 9 |
WORKDIR /app
|
| 10 |
|
| 11 |
-
# Copy package files
|
| 12 |
COPY package*.json ./
|
| 13 |
|
| 14 |
-
# Install dependencies
|
| 15 |
RUN npm ci --only=production && npm cache clean --force
|
| 16 |
|
| 17 |
-
# Copy source code
|
| 18 |
COPY . .
|
| 19 |
|
| 20 |
-
# Create non-root user
|
| 21 |
RUN groupadd -r nodeuser && useradd -r -g nodeuser nodeuser \
|
| 22 |
&& chown -R nodeuser:nodeuser /app
|
| 23 |
|
|
|
|
| 24 |
USER nodeuser
|
| 25 |
|
|
|
|
| 26 |
EXPOSE 5000
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use official Node.js 18 slim image
|
| 2 |
+
FROM node:18-slim
|
| 3 |
+
|
| 4 |
+
# Set environment variables for Puppeteer
|
| 5 |
+
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
|
| 6 |
+
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
|
| 7 |
+
|
| 8 |
+
# Install only essential dependencies in a single layer
|
| 9 |
+
RUN apt-get update && apt-get install -y \
|
| 10 |
+
chromium \
|
| 11 |
+
fonts-liberation \
|
| 12 |
+
libappindicator3-1 \
|
| 13 |
+
libasound2 \
|
| 14 |
+
libatk-bridge2.0-0 \
|
| 15 |
+
libatk1.0-0 \
|
| 16 |
+
libcups2 \
|
| 17 |
+
libdbus-1-3 \
|
| 18 |
+
libdrm2 \
|
| 19 |
+
libgbm1 \
|
| 20 |
+
libgtk-3-0 \
|
| 21 |
+
libnspr4 \
|
| 22 |
+
libnss3 \
|
| 23 |
+
libx11-xcb1 \
|
| 24 |
+
libxcomposite1 \
|
| 25 |
+
libxdamage1 \
|
| 26 |
+
libxrandr2 \
|
| 27 |
+
libxss1 \
|
| 28 |
+
libxtst6 \
|
| 29 |
+
xdg-utils \
|
| 30 |
+
--no-install-recommends \
|
| 31 |
&& apt-get clean \
|
| 32 |
+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
| 33 |
|
| 34 |
+
# Set working directory
|
| 35 |
WORKDIR /app
|
| 36 |
|
| 37 |
+
# Copy package files first (better layer caching)
|
| 38 |
COPY package*.json ./
|
| 39 |
|
| 40 |
+
# Install dependencies with production flag and clean npm cache
|
| 41 |
RUN npm ci --only=production && npm cache clean --force
|
| 42 |
|
| 43 |
+
# Copy only necessary source code files
|
| 44 |
COPY . .
|
| 45 |
|
| 46 |
+
# Create non-root user for security
|
| 47 |
RUN groupadd -r nodeuser && useradd -r -g nodeuser nodeuser \
|
| 48 |
&& chown -R nodeuser:nodeuser /app
|
| 49 |
|
| 50 |
+
# Switch to non-root user
|
| 51 |
USER nodeuser
|
| 52 |
|
| 53 |
+
# Expose port
|
| 54 |
EXPOSE 5000
|
| 55 |
|
| 56 |
+
# Health check (optional but recommended)
|
| 57 |
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s \
|
| 58 |
+
CMD node -e "require('http').get('http://localhost:5000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
|
| 59 |
+
|
| 60 |
+
# Start the server
|
| 61 |
+
CMD ["npm", "start"]
|