ADD: Se agregaron los comandos php artisan para las migraciones y los seeders, para el YAML de prod y dev
This commit is contained in:
parent
7fff56f592
commit
7503b2beda
@ -34,7 +34,10 @@ DB_PORT=3306
|
||||
DB_DATABASE=holos-backend
|
||||
DB_USERNAME=notsoweb
|
||||
DB_PASSWORD=
|
||||
PMA_PORT=8081 # Port para phpMyAdmin
|
||||
PMA_PORT=8081 # Puerto para phpMyAdmin
|
||||
|
||||
REDIS_PORT=6379 # Puerto para Redis
|
||||
NGINX_PORT=8080 # Puerto para Nginx
|
||||
|
||||
SESSION_DRIVER=database
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
33
bd-init.sh
Normal file
33
bd-init.sh
Normal file
@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Esperar a que MySQL esté disponible
|
||||
echo "Esperando conexión a MySQL..."
|
||||
wait_for_mysql() {
|
||||
echo "Esperando a que MySQL esté disponible..."
|
||||
|
||||
until php -r "
|
||||
try {
|
||||
\$pdo = new PDO('mysql:host=${DB_HOST};port=${DB_PORT}', '${DB_USERNAME}', '${DB_PASSWORD}');
|
||||
echo 'MySQL está disponible' . PHP_EOL;
|
||||
exit(0);
|
||||
} catch (PDOException \$e) {
|
||||
echo 'MySQL no disponible: ' . \$e->getMessage() . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
"; do
|
||||
echo "Esperando MySQL..."
|
||||
sleep 2
|
||||
done
|
||||
}
|
||||
|
||||
# Esperar a MySQL
|
||||
wait_for_mysql
|
||||
|
||||
echo "MySQL conectado, ejecutando migraciones..."
|
||||
|
||||
# Ejecutar migraciones y seeders
|
||||
php artisan migrate:fresh --seeder=DevSeeder --force
|
||||
php artisan passport:client --personal --name=Holos
|
||||
|
||||
# Iniciar PHP-FPM
|
||||
exec php-fpm
|
||||
61
database/migrations/path/2025_09_11_115824_seed_seeders.php
Normal file
61
database/migrations/path/2025_09_11_115824_seed_seeders.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use Database\Seeders\DevSeeder;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// Solo ejecutar en desarrollo y si no existen datos
|
||||
if ($this->shouldSeed()) {
|
||||
(new DevSeeder)->run();
|
||||
|
||||
$this->createPassportClient();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Verificar si debe ejecutar el seeding
|
||||
*/
|
||||
private function shouldSeed(): bool
|
||||
{
|
||||
// Verificar si ya existen usuarios del sistema
|
||||
$usersExist = DB::table('users')
|
||||
->whereIn('email', ['developer@notsoweb.com', 'admin@notsoweb.com'])
|
||||
->exists();
|
||||
|
||||
return !$usersExist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crear cliente Passport si no existe
|
||||
*/
|
||||
private function createPassportClient(): void
|
||||
{
|
||||
// Verificar si ya existe un cliente personal con el nombre "Holos"
|
||||
$clientExists = DB::table('oauth_clients')
|
||||
->where('name', 'Holos')
|
||||
->where('personal_access_client', true)
|
||||
->exists();
|
||||
|
||||
if (!$clientExists) {
|
||||
Artisan::call('passport:client', [
|
||||
'--personal' => true,
|
||||
'--name' => 'Holos',
|
||||
'--no-interaction' => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -10,13 +10,15 @@ services:
|
||||
networks:
|
||||
- holos-network
|
||||
depends_on:
|
||||
- mysql
|
||||
- redis
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
ports:
|
||||
- "8080:80"
|
||||
- "${NGINX_PORT}:80"
|
||||
volumes:
|
||||
- ./public:/var/www/holos.backend/public
|
||||
- ./Docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
@ -38,6 +40,10 @@ services:
|
||||
- mysql_data:/var/lib/mysql
|
||||
networks:
|
||||
- holos-network
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
|
||||
timeout: 15s
|
||||
retries: 10
|
||||
|
||||
phpmyadmin:
|
||||
image: phpmyadmin/phpmyadmin
|
||||
@ -53,10 +59,16 @@ services:
|
||||
|
||||
redis:
|
||||
image: redis:alpine
|
||||
ports:
|
||||
- "${REDIS_PORT}:6379"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
networks:
|
||||
- holos-network
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
volumes:
|
||||
mysql_data:
|
||||
|
||||
@ -10,13 +10,15 @@ services:
|
||||
networks:
|
||||
- holos-network
|
||||
depends_on:
|
||||
- mysql
|
||||
- redis
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
ports:
|
||||
- "8080:80"
|
||||
- "${NGINX_PORT}:80"
|
||||
volumes:
|
||||
- ./public:/var/www/holos.backend/public
|
||||
- ./Docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
@ -38,6 +40,10 @@ services:
|
||||
- mysql_data:/var/lib/mysql
|
||||
networks:
|
||||
- holos-network
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
|
||||
timeout: 15s
|
||||
retries: 10
|
||||
|
||||
phpmyadmin:
|
||||
image: phpmyadmin/phpmyadmin
|
||||
@ -53,10 +59,16 @@ services:
|
||||
|
||||
redis:
|
||||
image: redis:alpine
|
||||
ports:
|
||||
- "${REDIS_PORT}:6379"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
networks:
|
||||
- holos-network
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
volumes:
|
||||
mysql_data:
|
||||
|
||||
@ -24,6 +24,11 @@ RUN composer install --no-dev --no-scripts --optimize-autoloader --no-interactio
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN php artisan package:discover --ansi \
|
||||
&& php artisan storage:link --force || true
|
||||
|
||||
RUN chown -R www-data:www-data /var/www/holos.backend/storage /var/www/holos.backend/bootstrap/cache
|
||||
|
||||
EXPOSE 9000
|
||||
|
||||
CMD ["php-fpm"]
|
||||
CMD ["sh", "-c", "sleep 10 && php artisan migrate --force && php artisan migrate --path=database/migrations/path --force && php-fpm"]
|
||||
|
||||
@ -25,9 +25,11 @@ RUN composer install --optimize-autoloader --no-interaction --no-scripts
|
||||
|
||||
COPY . .
|
||||
|
||||
# Ejecutar los scripts de Laravel después de copiar el código
|
||||
RUN composer run-script post-autoload-dump
|
||||
RUN php artisan package:discover --ansi \
|
||||
&& php artisan storage:link --force || true
|
||||
|
||||
RUN chown -R www-data:www-data /var/www/holos.backend/storage /var/www/holos.backend/bootstrap/cache
|
||||
|
||||
EXPOSE 9000
|
||||
|
||||
CMD ["php-fpm"]
|
||||
CMD ["sh", "-c", "sleep 10 && php artisan migrate --force && php artisan migrate --path=database/migrations/path --force && php-fpm"]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user