From d72229503626ff3df711554ff5ba3dad55455916 Mon Sep 17 00:00:00 2001 From: eko Date: Sun, 29 Mar 2026 19:35:21 +0700 Subject: [PATCH] fix /plan --- .dockerignore | 22 +++++++++++++++++++++ Dockerfile | 55 ++++++++++++++++++++++----------------------------- entrypoint.sh | 37 ++++++++++++++++++++++++++++------ server.php | 21 ++++++++++++++++++++ 4 files changed, 98 insertions(+), 37 deletions(-) create mode 100644 .dockerignore create mode 100644 server.php diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..08b72ac7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,22 @@ +**/node_modules +**/vendor +.env +.env.backup +.git +.phpunit.result.cache +Homestead.json +Homestead.yaml +auth.json +npm-debug.log +yarn-error.log +.idea +.vscode +storage/app/public +storage/app/temp +storage/app/uploads +storage/debugbar +storage/framework/views/* +public/modules/* +.qodo +.camel-jbang + diff --git a/Dockerfile b/Dockerfile index 441a6396..a6dc6f01 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,41 +33,39 @@ COPY --from=composer:latest /usr/bin/composer /usr/bin/composer WORKDIR /var/www/html -# Copy ALL application files first -COPY --chown=www-data:www-data . . +# Copy ONLY composer files first +COPY composer.json composer.lock ./ -# Remove any nested vendor directories -RUN find . -type d -name "vendor" -not -path "./vendor*" -exec rm -rf {} + 2>/dev/null || true - -# Remove composer.lock to ensure fresh install -RUN rm -f composer.lock - -# Create ALL storage directories BEFORE composer install +# Create storage and bootstrap directories needed for composer scripts RUN mkdir -p storage/framework/cache \ && mkdir -p storage/framework/sessions \ && mkdir -p storage/framework/views \ && mkdir -p storage/framework/testing \ && mkdir -p storage/logs \ && mkdir -p bootstrap/cache \ - && mkdir -p storage/framework/cache/data \ && chmod -R 777 storage \ && chmod -R 777 bootstrap/cache -# Create a temporary config file to avoid cache path issues during composer -RUN if [ ! -f config/app.php ]; then \ - echo " []];" > config/app.php; \ +# Install PHP dependencies (this layer will be cached) +RUN composer install --no-interaction --no-progress --no-scripts + +# Isolate the clean vendor directory +RUN mv vendor /vendor_clean + +# Copy the rest of the application files (will ignore vendor because of .dockerignore) +COPY --chown=www-data:www-data . . + +# Restore the clean vendor directory +RUN rm -rf vendor && mv /vendor_clean vendor + +# Final build verification +RUN if [ ! -f vendor/laravel/prompts/src/helpers.php ]; then \ + echo "ERROR: laravel/prompts/src/helpers.php missing!" && exit 1; \ fi -# Set environment variable for cache path -ENV VIEW_COMPILED_PATH=/var/www/html/storage/framework/views - -# Install PHP dependencies -RUN composer install --no-interaction --no-progress --optimize-autoloader - -# Verify critical files exist -RUN if [ ! -f vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php ]; then \ - echo "ERROR: server.php missing!" && exit 1; \ - fi +# Final check and debug listing +RUN ls -l vendor/laravel/prompts/src/helpers.php \ + && du -sh vendor/laravel/prompts # Copy package files for NPM COPY package*.json ./ @@ -77,17 +75,12 @@ COPY vite.config.js ./ RUN npm install --legacy-peer-deps --no-audit # Build Vite assets -RUN npm run build || true - -# Generate application key -RUN php artisan key:generate --no-interaction --force || true - -# Cache configurations -RUN php artisan config:cache || true +RUN npm run build +# Copy entrypoint script and ensure it's executable COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh +# Let the entrypoint handle artisan commands at runtime EXPOSE 8000 9000 - ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index 767f52e2..8a6535ca 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -9,6 +9,10 @@ echo "========================================" echo "Current user: $(whoami)" echo "Current directory: $(pwd)" +# Force debug mode for troubleshooting +export APP_DEBUG=true +export LOG_LEVEL=debug + # Create ALL required Laravel directories echo "Creating storage directories..." mkdir -p storage/framework/cache @@ -54,12 +58,33 @@ EOF fi fi -# Generate key if not present -if ! grep -q "APP_KEY=" .env || grep -q "APP_KEY=$" .env; then +# Generate key if not present (only if APP_KEY is empty or missing) +echo "Checking .env for APP_KEY..." +if ! grep -E "APP_KEY=.{10,}" .env; then + echo "APP_KEY is empty or missing. Generating..." echo "Generating application key..." - php artisan key:generate --no-interaction --force || echo "Key generation failed" + # If the file doesn't have APP_KEY= at all, add it so artisan can replace it + if ! grep -q "APP_KEY=" .env; then + echo "Appending APP_KEY= placeholder..." + echo "" >> .env + echo "APP_KEY=" >> .env + fi + php artisan key:generate --no-interaction --force || echo "❌ Key generation failed!" fi +echo "Verifying APP_KEY after generation:" +grep "APP_KEY" .env + +# Force autoloader regeneration to ensure absolute path consistency +echo "Regenerating autoloader..." +composer dump-autoload + +# Verify vendor integrity at PHP level +echo "Checking vendor visibility and READABILITY for PHP..." +ls -la /var/www/html/vendor/laravel/prompts/src/helpers.php +php -r 'if (file_exists("/var/www/html/vendor/laravel/prompts/src/helpers.php")) { echo "✅ file_exists true\n"; }' +php -r 'require "/var/www/html/vendor/laravel/prompts/src/helpers.php"; echo "✅ PHP successfully REQUIRED helpers.php\n";' + # Clear all caches to ensure fresh state echo "Clearing caches..." php artisan config:clear || true @@ -85,9 +110,9 @@ echo "========================================" # Start the application with proper error handling if [ "$MODE" = "staging" ]; then - echo "Starting PHP built-in server on port 8000..." - # Use exec with error capture - exec php artisan serve --host=0.0.0.0 --port=8000 2>&1 | tee -a /var/log/php-server.log + echo "Starting DIRECT PHP server on port 8000 (Bypassing artisan serve)..." + # Use direct php -S to eliminate any artisan wrapper issues + exec php -d opcache.enable=0 -S 0.0.0.0:8000 -t public server.php 2>&1 | tee -a /var/log/php-server.log else echo "Starting PHP-FPM on port 9000..." # Ensure PHP-FPM is properly configured diff --git a/server.php b/server.php new file mode 100644 index 00000000..5fb6379e --- /dev/null +++ b/server.php @@ -0,0 +1,21 @@ + + */ + +$uri = urldecode( + parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) +); + +// This file allows us to emulate Apache's "mod_rewrite" functionality from the +// built-in PHP web server. This provides a convenient way to test a Laravel +// application without having installed a "real" web server software here. +if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { + return false; +} + +require_once __DIR__.'/public/index.php';