Refactor: Move npm/composer setup to entrypoint script for proper volume handling
This commit is contained in:
Executable → Regular
+13
-8
@@ -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 '<Directory /var/www/app/public>\n\
|
||||
</Directory>' > /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
|
||||
|
||||
Executable
+34
@@ -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
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user