| # Build stage | |
| FROM node:20-slim AS builder | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy package files | |
| COPY cruciqe-id-card-backend/package*.json ./ | |
| # Install all dependencies (including dev dependencies for building) | |
| RUN npm ci | |
| # Copy TypeScript config | |
| COPY cruciqe-id-card-backend/tsconfig.json ./ | |
| # Copy source files | |
| COPY cruciqe-id-card-backend/src ./src | |
| # Build TypeScript | |
| RUN npm run build | |
| # Production stage | |
| FROM node:20-slim | |
| # Install system dependencies for Puppeteer | |
| RUN apt-get update && apt-get install -y \ | |
| chromium \ | |
| chromium-sandbox \ | |
| fonts-liberation \ | |
| libappindicator3-1 \ | |
| libasound2 \ | |
| libatk-bridge2.0-0 \ | |
| libatk1.0-0 \ | |
| libcups2 \ | |
| libdbus-1-3 \ | |
| libdrm2 \ | |
| libgbm1 \ | |
| libgtk-3-0 \ | |
| libnspr4 \ | |
| libnss3 \ | |
| libx11-xcb1 \ | |
| libxcomposite1 \ | |
| libxdamage1 \ | |
| libxfixes3 \ | |
| libxrandr2 \ | |
| xdg-utils \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy package files | |
| COPY cruciqe-id-card-backend/package*.json ./ | |
| # Install only production dependencies | |
| RUN npm ci --only=production && npm cache clean --force | |
| # Copy built files from builder stage | |
| COPY --from=builder /app/dist ./dist | |
| # Create directory for database and set permissions | |
| RUN mkdir -p /app/data && chmod 777 /app/data | |
| # Expose port 7860 (required for Hugging Face Spaces) | |
| EXPOSE 7860 | |
| # Set working directory for database (persistent storage on HF spaces) | |
| ENV DB_PATH=/app/data/dev.db | |
| # Set environment variables for Puppeteer | |
| ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true | |
| ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium | |
| # Set port to 7860 (required for HF Spaces) | |
| ENV PORT=7860 | |
| # Run the application | |
| CMD ["node", "dist/index.js"] | |