Dockerfile 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Use nginx as the base image for serving static files
  2. FROM nginx:alpine
  3. # PERF-019: Only copy necessary web files (exclude .git, desktop-app, wiki, etc.)
  4. COPY index.html /usr/share/nginx/html/
  5. COPY script.js /usr/share/nginx/html/
  6. COPY styles.css /usr/share/nginx/html/
  7. COPY sw.js /usr/share/nginx/html/
  8. COPY manifest.json /usr/share/nginx/html/
  9. COPY robots.txt /usr/share/nginx/html/
  10. COPY sitemap.xml /usr/share/nginx/html/
  11. COPY assets/icon.jpg /usr/share/nginx/html/assets/
  12. # Create a custom nginx configuration with compression and security
  13. # PERF-020: Added gzip compression for text-based assets
  14. RUN echo 'server { \
  15. listen 80; \
  16. server_name localhost; \
  17. root /usr/share/nginx/html; \
  18. index index.html; \
  19. \
  20. # Enable gzip compression (PERF-020) \
  21. gzip on; \
  22. gzip_vary on; \
  23. gzip_proxied any; \
  24. gzip_comp_level 6; \
  25. gzip_min_length 256; \
  26. gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript image/svg+xml; \
  27. \
  28. # Handle client-side routing for SPA \
  29. location / { \
  30. try_files $uri $uri/ /index.html; \
  31. } \
  32. \
  33. # Cache static assets \
  34. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { \
  35. expires 1y; \
  36. add_header Cache-Control "public, immutable"; \
  37. } \
  38. \
  39. # Security headers \
  40. add_header X-Frame-Options "SAMEORIGIN" always; \
  41. add_header X-Content-Type-Options "nosniff" always; \
  42. add_header X-XSS-Protection "1; mode=block" always; \
  43. add_header Referrer-Policy "strict-origin-when-cross-origin" always; \
  44. # PERF-029: Content Security Policy for defense-in-depth \
  45. add_header Content-Security-Policy "default-src '"'"'self'"'"'; script-src '"'"'self'"'"' cdnjs.cloudflare.com cdn.jsdelivr.net '"'"'unsafe-inline'"'"'; style-src '"'"'self'"'"' cdnjs.cloudflare.com cdn.jsdelivr.net '"'"'unsafe-inline'"'"'; img-src '"'"'self'"'"' https: data: blob:; font-src '"'"'self'"'"' cdn.jsdelivr.net; connect-src '"'"'self'"'"' api.github.com raw.githubusercontent.com;" always; \
  46. }' > /etc/nginx/conf.d/default.conf
  47. # Expose port 80
  48. EXPOSE 80
  49. # Start nginx
  50. CMD ["nginx", "-g", "daemon off;"]