Update Dockerfile and Seeder

This commit is contained in:
Matteo Gheza 2024-04-01 23:21:49 +02:00
parent 449964e2ff
commit 94c58daae3
No known key found for this signature in database
GPG Key ID: A7019AD593CEF319
4 changed files with 29 additions and 12 deletions

View File

@ -1,5 +1,5 @@
# Stage 1: Build PHP app and install dependencies
FROM php:8.2 AS builder
FROM php:8.3.4 AS builder
WORKDIR /app
@ -16,7 +16,7 @@ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local
RUN COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --optimize-autoloader
# Stage 2: Serve the application using Apache PHP
FROM php:8.1.10-apache
FROM php:8.3.4-apache
# Copy the built PHP app from the builder stage
COPY --from=builder /app /var/www/html
@ -34,7 +34,7 @@ RUN apt-get update && apt-get install -y \
libmariadb-dev-compat \
python3-dev \
python3-pip \
&& pip3 install mysqlclient \
&& pip3 install --break-system-packages mysqlclient \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \

View File

@ -24,6 +24,19 @@ class DummyDataSeeder extends Seeder
$user->addRole('superadmin');
$user->save();
$names = [
['Mario', 'Rossi'],
['Luigi', 'Verdi'],
['Paolo', 'Bianchi'],
['Giovanni', 'Neri'],
['Giuseppe', 'Fontana'],
['Antonio', 'Gallo'],
['Francesco', 'Greco'],
['Angelo', 'Martini'],
['Vincenzo', 'Mancini'],
['Salvatore', 'Costa'],
];
/*
Create 10 users:
- 1 chief and with role 'admin'
@ -34,10 +47,10 @@ class DummyDataSeeder extends Seeder
*/
for ($i = 1; $i <= 10; $i++) {
$user = new User();
$user->name = ''.$i;
$user->surname = 'User';
$user->username = 'user' . $i;
$user->password = Hash::make('user' . $i);
$user->name = $names[$i-1][0];
$user->surname = $names[$i-1][1];
$user->username = strtolower($user->surname.".".$user->name);
$user->password = Hash::make('password');
$user->email = 'u' . $i+1 . '@example.com';
$user->save();

View File

@ -15,13 +15,18 @@ else
sed -i "s/DB_DATABASE=laravel/DB_DATABASE=${DB_DATABASE}/g" .env.tmp
sed -i "s/DB_USERNAME=root/DB_USERNAME=${DB_USER}/g" .env.tmp
sed -i "s/DB_PASSWORD=/DB_PASSWORD=${DB_PASSWORD}/g" .env.tmp
# Set encryption key
echo "Generating encryption key..."
# We can't use just the command, so we need to save the output to a file and then overwrite it in .env.test
php artisan key:generate --show > key.tmp
sed -i "s#APP_KEY=#APP_KEY=$(cat key.tmp)#g" .env.tmp
rm key.tmp
# Overwrite .env with the updated .env.tmp
cat .env.tmp > .env
rm .env.tmp
# Generate encryption key
echo "Generating encryption key..."
php artisan key:generate
# Run migrations
echo "Running migrations..."
php artisan migrate --force

View File

@ -29,7 +29,6 @@ services:
- DB_DATABASE=mydb
volumes:
- laravel-storage:/var/www/html/storage
- ./.env.docker:/var/www/html/.env
db:
image: mysql:5.7