Dockerfile 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # --- Stage 1: compile Tailwind CSS --------------------------------------
  2. # Runs the Tailwind JIT over views/, src/, and our JS so only classes that
  3. # are actually referenced end up in the output. No runtime <style> injection,
  4. # which lets the CSP drop 'unsafe-inline' for style-src.
  5. FROM node:20-alpine AS css-builder
  6. WORKDIR /build
  7. COPY package.json package-lock.json* ./
  8. RUN npm ci --no-audit --no-fund
  9. # Only the files that contribute to class discovery / the entry stylesheet.
  10. COPY tailwind.config.js ./
  11. COPY assets/css/input.css ./assets/css/input.css
  12. COPY views/ ./views/
  13. COPY src/ ./src/
  14. COPY public/assets/js/ ./public/assets/js/
  15. RUN npx tailwindcss -i ./assets/css/input.css -o /build/app.css --minify
  16. # --- Stage 2: the actual PHP runtime ------------------------------------
  17. FROM php:8.3-apache
  18. RUN apt-get update && apt-get install -y --no-install-recommends \
  19. libsqlite3-dev unzip git \
  20. && docker-php-ext-install pdo pdo_sqlite \
  21. && a2enmod rewrite \
  22. && rm -rf /var/lib/apt/lists/*
  23. COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
  24. WORKDIR /var/www/html
  25. COPY composer.json composer.lock* ./
  26. RUN composer install --no-dev --no-interaction --prefer-dist --no-progress
  27. COPY . .
  28. # Place the compiled CSS where Apache can serve it.
  29. COPY --from=css-builder /build/app.css /var/www/html/public/assets/css/app.css
  30. # Write a clean Apache site config pointing at public/ and routing every
  31. # unmatched URL to the front controller via FallbackResource. That replaces
  32. # the need for .htaccess rewrites (the .htaccess is kept as defense-in-depth
  33. # for deployments that don't use this image).
  34. RUN mkdir -p /var/www/data /var/www/data/sessions \
  35. && chown -R www-data:www-data /var/www/data \
  36. && printf '%s\n' \
  37. '<VirtualHost *:80>' \
  38. ' DocumentRoot /var/www/html/public' \
  39. ' <Directory /var/www/html/public>' \
  40. ' Options -Indexes +FollowSymLinks' \
  41. ' AllowOverride All' \
  42. ' Require all granted' \
  43. ' FallbackResource /index.php' \
  44. ' </Directory>' \
  45. ' ErrorLog ${APACHE_LOG_DIR}/error.log' \
  46. ' CustomLog ${APACHE_LOG_DIR}/access.log combined' \
  47. '</VirtualHost>' \
  48. > /etc/apache2/sites-available/000-default.conf
  49. EXPOSE 80
  50. CMD ["apache2-foreground"]