# 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"]