diff --git a/.gitignore b/.gitignore index 9c7a4ce..e3caaea 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /public/tmp /storage/*.key /vendor +/sail-mysql .env .env.backup .phpunit.result.cache diff --git a/Dockerfile b/Dockerfile index 5984f5c..3c992f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,21 @@ -FROM rockylinux:9.2 as build +FROM almalinux:10 AS build EXPOSE 80 # Installazione pacchetti principali RUN dnf update -y \ && dnf install npm nodejs ncurses unzip wget procps nano -y \ - && dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm -y \ - && dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y \ + && dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm -y \ + && dnf install https://rpms.remirepo.net/enterprise/remi-release-10.rpm -y \ + && dnf install https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm -y \ && dnf update -y \ - && dnf module install php:remi-8.2 -y \ + && dnf module install php:remi-8.3 -y \ && dnf install \ php-pgsql php-gd php-imap php-mysql \ php-zip php-bcmath php-soap php-intl php-ldap \ php-msgpack php-igbinary php-redis \ php-memcached php-pcov php-xdebug -y \ - && dnf install supervisor -y -RUN dnf install php-swoole --nobest -y -RUN dnf install mysql -y + && dnf install supervisor mysql-community-client --nogpgcheck -y +RUN dnf install php-swoole --nobest -y RUN mkdir -p /run/php-fpm/ RUN curl https://getmic.ro | bash && mv micro /usr/bin/ @@ -31,6 +31,10 @@ WORKDIR /root/docker # Copia della repo COPY . /root/docker +# Copy and setup entrypoint script BEFORE using it +COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + # Installazione librerie composer e npm RUN composer install --optimize-autoloader --no-dev \ && npm install \ @@ -39,9 +43,11 @@ RUN composer install --optimize-autoloader --no-dev \ COPY httpd.conf /etc/httpd/conf/ COPY php.ini /etc/php.ini RUN cp -R /root/docker/. /var/www/html -RUN chown -R apache:apache /var/www/html COPY supervisord.production.conf /etc/supervisord.conf +# Set entrypoint with absolute path +ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] + WORKDIR /var/www/html -CMD ["supervisord"] \ No newline at end of file +CMD ["supervisord"] diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php new file mode 100644 index 0000000..7e6ac93 --- /dev/null +++ b/app/Console/Commands/Init.php @@ -0,0 +1,31 @@ +/dev/null | grep "mysql" | grep -q "OK"; then + echo "✅ Database connection established!" + return 0 + fi + + echo "⚠️ Database not ready yet... attempt $attempt/$max_attempts" + attempt=$((attempt + 1)) + sleep 3 + done + + echo "❌ ERROR: Could not connect to database after $max_attempts attempts" + exit 1 +} + +# Your initialization function +init_laravel() { + echo "🚀 Initializing Laravel application..." + + # Ensure we're in the right directory + cd /var/www/html + + # Check if Laravel is properly installed + if [ ! -f "artisan" ]; then + echo "❌ Laravel artisan file not found!" + exit 1 + fi + + # Wait for database to be ready (if using database) + wait_for_database + + # Run migrations + echo "🔄 Running migrations..." + php artisan migrate --force || { + echo "⚠️ Migration failed, but continuing..." + } + + # Create laravel.log file if it doesn't exist + echo "📝 Creating laravel.log file..." + if [ ! -f "storage/logs/laravel.log" ]; then + touch storage/logs/laravel.log + fi + + # Run init command + echo "🚀 Running init command..." + php artisan app:init || { + echo "⚠️ Init command failed, but continuing..." + } + + # Set file ownership to apache + echo "🔧 Setting file ownership to apache..." + chown -R apache:apache /var/www/html + + echo "✅ Laravel initialization completed!" +} + +# Run initialization +init_laravel + +# Execute the original command +exec "$@" \ No newline at end of file