From edfc0f0680b48fc973573f4a90dd1526344c321b Mon Sep 17 00:00:00 2001 From: eko Date: Mon, 23 Mar 2026 11:27:36 +0700 Subject: [PATCH] fix docker --- Dockerfile | 18 +++++++----------- entrypoint.sh | 47 +++++++++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 37 deletions(-) diff --git a/Dockerfile b/Dockerfile index b29495a8..5b6e4dc0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,29 +28,25 @@ COPY --from=composer:latest /usr/bin/composer /usr/bin/composer WORKDIR /var/www/html -# Copy composer files first (for dependency caching) +# Copy ONLY composer files first (for better caching) COPY composer.json composer.lock* ./ -# Install dependencies BEFORE copying application files -RUN composer install --no-interaction --no-progress --optimize-autoloader +# Install dependencies (including laravel/prompts) +RUN composer install --no-dev --no-interaction --no-progress --optimize-autoloader # Copy the rest of the application files COPY --chown=www-data:www-data . . -# Create necessary directories +# Create storage directories after copying files RUN mkdir -p storage/framework/{cache,sessions,views} \ && mkdir -p storage/logs \ && mkdir -p bootstrap/cache \ - && chmod -R 775 storage \ - && chmod -R 775 bootstrap/cache \ - && chown -R www-data:www-data storage bootstrap + && chmod -R 777 storage \ + && chmod -R 777 bootstrap/cache -# Generate application key +# Generate key (after composer install and storage setup) RUN php artisan key:generate --no-interaction --force -# Clear and cache configurations (optional) -RUN php artisan config:clear && php artisan cache:clear || true - # Copy entrypoint script COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh diff --git a/entrypoint.sh b/entrypoint.sh index 8c6e603c..7c23b2a5 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,42 +5,37 @@ echo "========================================" echo "Starting container setup..." echo "========================================" -# Show current user +# Show current user and directory echo "Current user: $(whoami)" echo "Current directory: $(pwd)" -# Create directories one by one with error checking -echo "Creating storage directories..." -mkdir -p storage/framework/cache || { echo "Failed to create cache dir"; exit 1; } -mkdir -p storage/framework/sessions || { echo "Failed to create sessions dir"; exit 1; } -mkdir -p storage/framework/views || { echo "Failed to create views dir"; exit 1; } -mkdir -p storage/logs || { echo "Failed to create logs dir"; exit 1; } -mkdir -p bootstrap/cache || { echo "Failed to create bootstrap cache dir"; exit 1; } +# Ensure directories exist with proper permissions +echo "Ensuring storage directories exist..." +mkdir -p storage/framework/{cache,sessions,views} +mkdir -p storage/logs +mkdir -p bootstrap/cache # Set permissions echo "Setting permissions..." -chmod -R 777 storage || { echo "Failed to set storage permissions"; exit 1; } -chmod -R 777 bootstrap/cache || { echo "Failed to set bootstrap permissions"; exit 1; } +chmod -R 777 storage +chmod -R 777 bootstrap/cache -# Verify directories -echo "Verifying directories..." -ls -la storage/framework/ -ls -la bootstrap/ - -# Check if .env exists +# Check if .env exists, create if not if [ ! -f .env ]; then - echo "WARNING: .env file not found!" - cp .env.example .env 2>/dev/null || echo "APP_ENV=production" > .env + echo "Creating .env file..." + if [ -f .env.example ]; then + cp .env.example .env + else + echo "APP_NAME=Laravel" > .env + echo "APP_ENV=production" >> .env + echo "APP_KEY=" >> .env + echo "APP_DEBUG=false" >> .env + echo "APP_URL=http://localhost" >> .env + fi fi -# Generate key -echo "Generating application key..." -php artisan key:generate --no-interaction --force || echo "Key generation failed" - -# Clear cache -echo "Clearing cache..." -php artisan config:clear || true -php artisan cache:clear || true +# Run migrations if needed (optional) +# php artisan migrate --force echo "========================================" echo "Setup complete. Starting application..."