From 1f61c50e5c4dc152935de2c87c352c5ad48d67f7 Mon Sep 17 00:00:00 2001 From: Andrea Zorzi Date: Mon, 20 Apr 2026 09:39:27 +0200 Subject: [PATCH 1/2] Bind mount ./sail-mysql and ignore it Switch MySQL service volume from the named volume 'sail-mysql' to a host bind mount './sail-mysql' in docker-compose.yml so DB files are stored in the project directory. Add /sail-mysql to .gitignore to avoid committing the database files. --- .gitignore | 1 + docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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/docker-compose.yml b/docker-compose.yml index 3681bc1..a66f2d3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,7 +44,7 @@ services: MYSQL_PASSWORD: '${DB_PASSWORD}' MYSQL_ALLOW_EMPTY_PASSWORD: 1 volumes: - - 'sail-mysql:/var/lib/mysql' + - './sail-mysql:/var/lib/mysql' - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh' networks: - sail From 34942d10746e96cb1301ee3c6ffb92911b305819 Mon Sep 17 00:00:00 2001 From: Andrea Zorzi Date: Mon, 20 Apr 2026 09:41:21 +0200 Subject: [PATCH 2/2] Switch to AlmaLinux 10; add entrypoint & init Update Dockerfile to use AlmaLinux 10 and corresponding EPEL/Remi repos, add MySQL community repo and mysql client, and bump PHP module to remi-8.3. Install supervisor and php-swoole, copy and register an absolute-path docker-entrypoint.sh, and ensure permissions. Add a docker-entrypoint.sh that waits for the database, runs migrations, creates storage log, runs an app:init Artisan command, fixes ownership, and then execs the container command. Add a scaffolded Laravel console command App\Console\Commands\Init to support the init step. --- Dockerfile | 24 +++++++---- app/Console/Commands/Init.php | 31 ++++++++++++++ docker-entrypoint.sh | 79 +++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 app/Console/Commands/Init.php create mode 100644 docker-entrypoint.sh 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