Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/public/tmp
/storage/*.key
/vendor
/sail-mysql
.env
.env.backup
.phpunit.result.cache
Expand Down
24 changes: 15 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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/
Expand All @@ -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 \
Expand All @@ -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"]
CMD ["supervisord"]
31 changes: 31 additions & 0 deletions app/Console/Commands/Init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;

class Init extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:init';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Execute the console command.
*/
public function handle()
{

}
}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
79 changes: 79 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash
set -e

# Function to wait for database
wait_for_database() {
echo "⏳ Waiting for database..."

# Check if database environment variables are set
if [ -z "$DB_HOST" ] || [ "$DB_HOST" = "localhost" ] || [ "$DB_HOST" = "127.0.0.1" ]; then
echo "ℹ️ No external database configured, skipping database wait"
return 0
fi

# Wait for database connection
max_attempts=30
attempt=1

until [ $attempt -eq $max_attempts ]; do
# Check if db:monitor returns OK for mysql
if php artisan db:monitor --databases=mysql 2>/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 "$@"
Loading