diff --git a/Dockerfile b/Dockerfile old mode 100755 new mode 100644 index ed1f15a8..94a95843 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM php:8.3-apache +# Install Node.js +RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && apt-get install -y nodejs + RUN apt-get update && apt-get install -y \ git \ curl \ @@ -43,12 +46,15 @@ RUN echo '\n\ ' > /etc/apache2/conf-available/laravel.conf \ && a2enconf laravel +# Copy app files (composer/npm setup happens at runtime via entrypoint) COPY composer.json composer.lock ./ +COPY package.json package-lock.json* ./ +COPY scripts/ ./scripts/ 2>/dev/null || true # Note: for Laravel, the COPY . . needs to be before the composer install COPY . . -# Make sure the storage and cache directories exist and are writeable before running composer install +# Create storage directories RUN mkdir -p \ storage/app \ storage/framework/cache/data \ @@ -56,13 +62,12 @@ RUN mkdir -p \ storage/framework/views \ storage/logs \ bootstrap/cache \ - && chown -R www-data:www-data storage bootstrap/cache \ - && chmod -R ug+rwX storage bootstrap/cache + public/assets/vendor -RUN composer install \ - --no-dev \ - --prefer-dist \ - --no-interaction \ - --optimize-autoloader +# Copy and set up entrypoint script +COPY docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + +ENTRYPOINT ["docker-entrypoint.sh"] EXPOSE 80 diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 00000000..18b9a265 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,34 @@ +#!/bin/bash +set -e + +cd /var/www/app + +# Set HOME for npm cache (www-data user needs writable cache directory) +export HOME=/tmp + +echo "Setting up dependencies..." + +# Create vendor directories and fix permissions +echo "Fixing permissions..." +mkdir -p bootstrap/cache storage/framework storage/logs +chown -R www-data:www-data bootstrap/cache storage/framework storage/logs +chmod -R ug+rwX bootstrap/cache storage/framework storage/logs + +# Install PHP dependencies +echo "Installing PHP packages..." +composer install \ + --no-dev \ + --prefer-dist \ + --no-interaction \ + --optimize-autoloader + +# Install npm dependencies if package.json has dependencies +if grep -q "\"dependencies\"" package.json; then + echo "Installing npm packages..." + npm ci --omit=dev +fi + +chmod -R ug+rwX bootstrap/cache + +echo "✓ Setup complete, starting Apache..." +exec apache2-foreground diff --git a/package.json b/package.json old mode 100755 new mode 100644 index 4ceb0f9b..6207906b --- a/package.json +++ b/package.json @@ -1,6 +1,10 @@ { "private": true, + "type": "module", "scripts": { + "dev": "grunt watch", + "build": "grunt uglify concat", + "postinstall": "node scripts/setup-vendor.js || true", "sass": "sass resources/assets/sass:public/css", "sass-watch": "sass --watch resources/assets/sass:public/css", "sass-minify": "sass resources/assets/sass/style.scss:public/css/style.min.css --style compressed",