Skip to content

Commit c194a0b

Browse files
authored
Merge pull request #10 from andreazorzi/development
Development
2 parents 5aa73aa + 34942d1 commit c194a0b

5 files changed

Lines changed: 127 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/public/tmp
77
/storage/*.key
88
/vendor
9+
/sail-mysql
910
.env
1011
.env.backup
1112
.phpunit.result.cache

Dockerfile

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
FROM rockylinux:9.2 as build
1+
FROM almalinux:10 AS build
22
EXPOSE 80
33

44
# Installazione pacchetti principali
55
RUN dnf update -y \
66
&& dnf install npm nodejs ncurses unzip wget procps nano -y \
7-
&& dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm -y \
8-
&& dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y \
7+
&& dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm -y \
8+
&& dnf install https://rpms.remirepo.net/enterprise/remi-release-10.rpm -y \
9+
&& dnf install https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm -y \
910
&& dnf update -y \
10-
&& dnf module install php:remi-8.2 -y \
11+
&& dnf module install php:remi-8.3 -y \
1112
&& dnf install \
1213
php-pgsql php-gd php-imap php-mysql \
1314
php-zip php-bcmath php-soap php-intl php-ldap \
1415
php-msgpack php-igbinary php-redis \
1516
php-memcached php-pcov php-xdebug -y \
16-
&& dnf install supervisor -y
17-
RUN dnf install php-swoole --nobest -y
18-
RUN dnf install mysql -y
17+
&& dnf install supervisor mysql-community-client --nogpgcheck -y
18+
RUN dnf install php-swoole --nobest -y
1919
RUN mkdir -p /run/php-fpm/
2020

2121
RUN curl https://getmic.ro | bash && mv micro /usr/bin/
@@ -31,6 +31,10 @@ WORKDIR /root/docker
3131
# Copia della repo
3232
COPY . /root/docker
3333

34+
# Copy and setup entrypoint script BEFORE using it
35+
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
36+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
37+
3438
# Installazione librerie composer e npm
3539
RUN composer install --optimize-autoloader --no-dev \
3640
&& npm install \
@@ -39,9 +43,11 @@ RUN composer install --optimize-autoloader --no-dev \
3943
COPY httpd.conf /etc/httpd/conf/
4044
COPY php.ini /etc/php.ini
4145
RUN cp -R /root/docker/. /var/www/html
42-
RUN chown -R apache:apache /var/www/html
4346

4447
COPY supervisord.production.conf /etc/supervisord.conf
4548

49+
# Set entrypoint with absolute path
50+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
51+
4652
WORKDIR /var/www/html
47-
CMD ["supervisord"]
53+
CMD ["supervisord"]

app/Console/Commands/Init.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Artisan;
7+
8+
class Init extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'app:init';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Command description';
23+
24+
/**
25+
* Execute the console command.
26+
*/
27+
public function handle()
28+
{
29+
30+
}
31+
}

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ services:
4444
MYSQL_PASSWORD: '${DB_PASSWORD}'
4545
MYSQL_ALLOW_EMPTY_PASSWORD: 1
4646
volumes:
47-
- 'sail-mysql:/var/lib/mysql'
47+
- './sail-mysql:/var/lib/mysql'
4848
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
4949
networks:
5050
- sail

docker-entrypoint.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Function to wait for database
5+
wait_for_database() {
6+
echo "⏳ Waiting for database..."
7+
8+
# Check if database environment variables are set
9+
if [ -z "$DB_HOST" ] || [ "$DB_HOST" = "localhost" ] || [ "$DB_HOST" = "127.0.0.1" ]; then
10+
echo "ℹ️ No external database configured, skipping database wait"
11+
return 0
12+
fi
13+
14+
# Wait for database connection
15+
max_attempts=30
16+
attempt=1
17+
18+
until [ $attempt -eq $max_attempts ]; do
19+
# Check if db:monitor returns OK for mysql
20+
if php artisan db:monitor --databases=mysql 2>/dev/null | grep "mysql" | grep -q "OK"; then
21+
echo "✅ Database connection established!"
22+
return 0
23+
fi
24+
25+
echo "⚠️ Database not ready yet... attempt $attempt/$max_attempts"
26+
attempt=$((attempt + 1))
27+
sleep 3
28+
done
29+
30+
echo "❌ ERROR: Could not connect to database after $max_attempts attempts"
31+
exit 1
32+
}
33+
34+
# Your initialization function
35+
init_laravel() {
36+
echo "🚀 Initializing Laravel application..."
37+
38+
# Ensure we're in the right directory
39+
cd /var/www/html
40+
41+
# Check if Laravel is properly installed
42+
if [ ! -f "artisan" ]; then
43+
echo "❌ Laravel artisan file not found!"
44+
exit 1
45+
fi
46+
47+
# Wait for database to be ready (if using database)
48+
wait_for_database
49+
50+
# Run migrations
51+
echo "🔄 Running migrations..."
52+
php artisan migrate --force || {
53+
echo "⚠️ Migration failed, but continuing..."
54+
}
55+
56+
# Create laravel.log file if it doesn't exist
57+
echo "📝 Creating laravel.log file..."
58+
if [ ! -f "storage/logs/laravel.log" ]; then
59+
touch storage/logs/laravel.log
60+
fi
61+
62+
# Run init command
63+
echo "🚀 Running init command..."
64+
php artisan app:init || {
65+
echo "⚠️ Init command failed, but continuing..."
66+
}
67+
68+
# Set file ownership to apache
69+
echo "🔧 Setting file ownership to apache..."
70+
chown -R apache:apache /var/www/html
71+
72+
echo "✅ Laravel initialization completed!"
73+
}
74+
75+
# Run initialization
76+
init_laravel
77+
78+
# Execute the original command
79+
exec "$@"

0 commit comments

Comments
 (0)