From 065d57a74feb9f0d730f2cd8f293b18d5d62db40 Mon Sep 17 00:00:00 2001 From: David Fencl Date: Thu, 11 Dec 2025 19:12:53 +0100 Subject: [PATCH] fix(docker): implement multi-stage build and serve dist folder --- Dockerfile | 27 ++++++++++++++++----------- vhost.conf | 13 +++++++++++-- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0e48a18..37d2dcb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,27 @@ -#FROM php:8.0-apache +# Stage 1: Build the React Application +FROM node:20 AS build +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci +COPY . . +RUN npm run build + +# Stage 2: Serve the application with Apache FROM --platform=linux/amd64 php:8.4-apache WORKDIR /var/www/html -#COPY index.php index.php +# Enable necessary Apache modules +RUN a2enmod rewrite headers -RUN mkdir /app COPY vhost.conf /etc/apache2/sites-available/000-default.conf -# COPY adf/saveData.php /var/www/html/saveData.php +# Copy the built application from the build stage +COPY --from=build /app/dist /app/dist -WORKDIR /app +# Ensure correct permissions +RUN chown -R www-data:www-data /app -COPY . . - -# ADD extras/dockerstart.sh /usr/local/servicemix/bin/ -# RUN chmod 755 /usr/local/bin/dockerstart.sh - -RUN chown -R www-data:www-data /app && a2enmod rewrite +# Keep original PHP extensions just in case RUN docker-php-ext-install mysqli pdo pdo_mysql EXPOSE 80 diff --git a/vhost.conf b/vhost.conf index 3402f3f..adc61a3 100644 --- a/vhost.conf +++ b/vhost.conf @@ -3,13 +3,22 @@ LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so ServerName localhost - DocumentRoot /app + DocumentRoot /app/dist - + Options Indexes FollowSymLinks Includes execCGI AllowOverride All Require all granted allow from all + + + RewriteEngine On + RewriteBase / + RewriteRule ^index\.html$ - [L] + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule . /index.html [L] + ErrorLog ${APACHE_LOG_DIR}/error.log