Spaces:
Sleeping
Sleeping
File size: 1,146 Bytes
24e8af1 a22621a 24e8af1 a22621a 24e8af1 d0e91b6 a22621a d0e91b6 24e8af1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# Use the official Node.js runtime as base image
FROM node:18-alpine
# Set the working directory
WORKDIR /app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm ci --only=production
# Create a non-root user first
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nodejs -u 1001
# Copy the rest of the application code
COPY . .
# Create data directory for persistent storage
RUN mkdir -p /app/data
# Ensure devices.json exists and has proper permissions
RUN touch /app/data/devices.json && \
chmod 666 /app/data/devices.json
# Change ownership of the app directory to the nodejs user
RUN chown -R nodejs:nodejs /app
# Switch to the non-root user
USER nodejs
# Expose the port that the app runs on
# Hugging Face Spaces expects the app to run on port 7860
EXPOSE 7860
# Set environment variables
ENV NODE_ENV=production
ENV PORT=7860
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:7860', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"
# Start the application
CMD ["node", "server.js"] |