| # Build stage | |
| FROM node:20-alpine AS build | |
| WORKDIR /app | |
| # Install dependencies | |
| COPY package*.json ./ | |
| RUN npm install | |
| # Copy source and build | |
| COPY . . | |
| # Note: We build with placeholders or local .env if present. | |
| # Secrets will be injected at runtime via env.js | |
| RUN npm run build | |
| # Production stage | |
| FROM nginx:stable-alpine | |
| COPY --from=build /app/dist /usr/share/nginx/html | |
| # Clean default configuration and create a new one for Hugging Face (port 7860) | |
| RUN rm /etc/nginx/conf.d/default.conf && \ | |
| printf 'server {\n\ | |
| listen 7860;\n\ | |
| server_name localhost;\n\ | |
| location / {\n\ | |
| root /usr/share/nginx/html;\n\ | |
| index index.html;\n\ | |
| try_files $uri $uri/ /index.html;\n\ | |
| }\n\ | |
| error_page 500 502 503 504 /50x.html;\n\ | |
| location = /50x.html {\n\ | |
| root /usr/share/nginx/html;\n\ | |
| }\n\ | |
| }\n' > /etc/nginx/conf.d/default.conf | |
| EXPOSE 7860 | |
| # At runtime, generate an env.js file that contains the environment variables | |
| # from Hugging Face Secrets, then start Nginx. | |
| CMD ["/bin/sh", "-c", "echo \"window.ENV = { VITE_SUPABASE_URL: '$VITE_SUPABASE_URL', VITE_SUPABASE_PUBLISHABLE_KEY: '$VITE_SUPABASE_PUBLISHABLE_KEY' };\" > /usr/share/nginx/html/env.js && exec nginx -g 'daemon off;'"] | |