FROM node:18-alpine WORKDIR /app # Copy the frontend folder COPY frontend/ ./frontend/ WORKDIR /app/frontend # Install dependencies RUN npm install # Expose port 7860 for Hugging Face Spaces compatibility EXPOSE 7860 # We build the application at runtime (CMD) instead of build time (RUN) # so that the VITE_GEMINI_API_KEY environment variable provided by Hugging Face # or docker-compose is successfully injected into the static build. CMD ["sh", "-c", "if [ -f /var/run/secrets/VITE_GEMINI_API_KEY ]; then export VITE_GEMINI_API_KEY=$(cat /var/run/secrets/VITE_GEMINI_API_KEY); fi; if [ -f /var/run/secrets/GEMINI_API_KEY ]; then export GEMINI_API_KEY=$(cat /var/run/secrets/GEMINI_API_KEY); fi; export VITE_GEMINI_API_KEY=${VITE_GEMINI_API_KEY:-$GEMINI_API_KEY}; npm run build && npm run preview -- --port 7860 --host 0.0.0.0"]