diff --git a/Dockerfile b/Dockerfile index 2071a3f..65e4206 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,25 +52,10 @@ RUN composer run-script post-autoload-dump || echo "Post-autoload dump skipped" # Generate key if needed RUN php artisan key:generate --no-interaction --force || true -# Create startup script with runtime directory creation -RUN echo '#!/bin/sh' > /start.sh && \ - echo '' >> /start.sh && \ - echo '# Ensure storage directories exist at runtime' >> /start.sh && \ - echo 'mkdir -p storage/framework/{cache,sessions,views}' >> /start.sh && \ - echo 'mkdir -p storage/logs' >> /start.sh && \ - echo 'mkdir -p bootstrap/cache' >> /start.sh && \ - echo 'chmod -R 777 storage bootstrap/cache' >> /start.sh && \ - echo '' >> /start.sh && \ - echo '# Start the application based on mode' >> /start.sh && \ - echo 'if [ "$MODE" = "dev" ]; then' >> /start.sh && \ - echo ' echo "Starting in DEV mode with PHP built-in server on port 8000..."' >> /start.sh && \ - echo ' php artisan serve --host=0.0.0.0 --port=8000' >> /start.sh && \ - echo 'else' >> /start.sh && \ - echo ' echo "Starting in PROD mode with PHP-FPM on port 9000..."' >> /start.sh && \ - echo ' php-fpm' >> /start.sh && \ - echo 'fi' >> /start.sh && \ - chmod +x /start.sh +# Copy entrypoint script +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh EXPOSE 8000 9000 -CMD ["/start.sh"] \ No newline at end of file +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..8c6e603 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,56 @@ +#!/bin/sh +set -e + +echo "========================================" +echo "Starting container setup..." +echo "========================================" + +# Show current user +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; } + +# 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; } + +# Verify directories +echo "Verifying directories..." +ls -la storage/framework/ +ls -la bootstrap/ + +# Check if .env exists +if [ ! -f .env ]; then + echo "WARNING: .env file not found!" + cp .env.example .env 2>/dev/null || echo "APP_ENV=production" > .env +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 + +echo "========================================" +echo "Setup complete. Starting application..." +echo "========================================" + +# Start the application +if [ "$MODE" = "dev" ]; then + echo "Starting PHP built-in server on port 8000..." + exec php artisan serve --host=0.0.0.0 --port=8000 +else + echo "Starting PHP-FPM on port 9000..." + exec php-fpm +fi \ No newline at end of file