Refactor: Move npm/composer setup to entrypoint script for proper volume handling

This commit is contained in:
Mischa Spelt
2026-08-25 14:33:08 +02:00
parent 95cf933424
commit e070c9f374
3 changed files with 51 additions and 8 deletions
Executable → Regular
+13 -8
View File
@@ -1,5 +1,8 @@
FROM php:8.3-apache 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 \ RUN apt-get update && apt-get install -y \
git \ git \
curl \ curl \
@@ -43,12 +46,15 @@ RUN echo '<Directory /var/www/app/public>\n\
</Directory>' > /etc/apache2/conf-available/laravel.conf \ </Directory>' > /etc/apache2/conf-available/laravel.conf \
&& a2enconf laravel && a2enconf laravel
# Copy app files (composer/npm setup happens at runtime via entrypoint)
COPY composer.json composer.lock ./ 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 # Note: for Laravel, the COPY . . needs to be before the composer install
COPY . . COPY . .
# Make sure the storage and cache directories exist and are writeable before running composer install # Create storage directories
RUN mkdir -p \ RUN mkdir -p \
storage/app \ storage/app \
storage/framework/cache/data \ storage/framework/cache/data \
@@ -56,13 +62,12 @@ RUN mkdir -p \
storage/framework/views \ storage/framework/views \
storage/logs \ storage/logs \
bootstrap/cache \ bootstrap/cache \
&& chown -R www-data:www-data storage bootstrap/cache \ public/assets/vendor
&& chmod -R ug+rwX storage bootstrap/cache
RUN composer install \ # Copy and set up entrypoint script
--no-dev \ COPY docker-entrypoint.sh /usr/local/bin/
--prefer-dist \ RUN chmod +x /usr/local/bin/docker-entrypoint.sh
--no-interaction \
--optimize-autoloader ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 80 EXPOSE 80
+34
View File
@@ -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
Executable → Regular
+4
View File
@@ -1,6 +1,10 @@
{ {
"private": true, "private": true,
"type": "module",
"scripts": { "scripts": {
"dev": "grunt watch",
"build": "grunt uglify concat",
"postinstall": "node scripts/setup-vendor.js || true",
"sass": "sass resources/assets/sass:public/css", "sass": "sass resources/assets/sass:public/css",
"sass-watch": "sass --watch 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", "sass-minify": "sass resources/assets/sass/style.scss:public/css/style.min.css --style compressed",