Before starting Docker containers, setup scripts now check if required ports are available and warn users about conflicts. Features: - Checks all required ports: 8080, 8025, 1025, 6379 - Checks database port based on selection (3306 for MySQL, 5432 for PostgreSQL) - Shows clear status for each port (Available/In Use) - If conflicts found: - Displays warning message - Shows helpful commands to find and stop conflicting processes - Asks user if they want to continue anyway - Exits if user chooses not to continue Benefits: - Prevents confusing 'port already in use' errors during container startup - Provides clear diagnostic information - Gives users control over how to handle conflicts - Improves setup experience and reduces frustration Implementation: - setup.bat: Uses netstat with findstr for Windows - setup.sh: Uses lsof and netstat for Linux/Mac compatibility
210 lines
5.3 KiB
Batchfile
210 lines
5.3 KiB
Batchfile
@echo off
|
|
REM Laravel Docker Development Template - Quick Setup (Windows)
|
|
REM Everything is pre-installed! This just starts Docker and sets up the database.
|
|
REM Usage: setup.bat [mysql|pgsql|sqlite]
|
|
|
|
setlocal enabledelayedexpansion
|
|
|
|
set DB=%1
|
|
if "%DB%"=="" set DB=mysql
|
|
|
|
REM Validate database choice
|
|
if not "%DB%"=="mysql" if not "%DB%"=="pgsql" if not "%DB%"=="sqlite" (
|
|
echo Error: Invalid database '%DB%'
|
|
echo Usage: setup.bat [mysql^|pgsql^|sqlite]
|
|
echo Example: setup.bat mysql
|
|
exit /b 1
|
|
)
|
|
|
|
echo ========================================================
|
|
echo Laravel Docker Development Template
|
|
echo Quick Setup - Everything Pre-Installed!
|
|
echo ========================================================
|
|
echo.
|
|
echo Setting up with %DB%...
|
|
echo.
|
|
|
|
REM Step 1: Check port availability
|
|
echo Checking port availability...
|
|
set PORTS_OK=1
|
|
|
|
REM Check port 8080 (Nginx)
|
|
netstat -ano | findstr ":8080 " | findstr "LISTENING" >nul 2>&1
|
|
if %errorlevel% equ 0 (
|
|
echo [X] Port 8080 (Web Server) - IN USE
|
|
set PORTS_OK=0
|
|
) else (
|
|
echo [√] Port 8080 (Web Server) - Available
|
|
)
|
|
|
|
REM Check port 8025 (Mailpit Dashboard)
|
|
netstat -ano | findstr ":8025 " | findstr "LISTENING" >nul 2>&1
|
|
if %errorlevel% equ 0 (
|
|
echo [X] Port 8025 (Mailpit Dashboard) - IN USE
|
|
set PORTS_OK=0
|
|
) else (
|
|
echo [√] Port 8025 (Mailpit Dashboard) - Available
|
|
)
|
|
|
|
REM Check port 1025 (Mailpit SMTP)
|
|
netstat -ano | findstr ":1025 " | findstr "LISTENING" >nul 2>&1
|
|
if %errorlevel% equ 0 (
|
|
echo [X] Port 1025 (Mailpit SMTP) - IN USE
|
|
set PORTS_OK=0
|
|
) else (
|
|
echo [√] Port 1025 (Mailpit SMTP) - Available
|
|
)
|
|
|
|
REM Check port 6379 (Redis)
|
|
netstat -ano | findstr ":6379 " | findstr "LISTENING" >nul 2>&1
|
|
if %errorlevel% equ 0 (
|
|
echo [X] Port 6379 (Redis) - IN USE
|
|
set PORTS_OK=0
|
|
) else (
|
|
echo [√] Port 6379 (Redis) - Available
|
|
)
|
|
|
|
REM Check database port based on selection
|
|
if "%DB%"=="mysql" (
|
|
netstat -ano | findstr ":3306 " | findstr "LISTENING" >nul 2>&1
|
|
if !errorlevel! equ 0 (
|
|
echo [X] Port 3306 (MySQL) - IN USE
|
|
set PORTS_OK=0
|
|
) else (
|
|
echo [√] Port 3306 (MySQL) - Available
|
|
)
|
|
)
|
|
|
|
if "%DB%"=="pgsql" (
|
|
netstat -ano | findstr ":5432 " | findstr "LISTENING" >nul 2>&1
|
|
if !errorlevel! equ 0 (
|
|
echo [X] Port 5432 (PostgreSQL) - IN USE
|
|
set PORTS_OK=0
|
|
) else (
|
|
echo [√] Port 5432 (PostgreSQL) - Available
|
|
)
|
|
)
|
|
|
|
REM Handle port conflicts
|
|
if %PORTS_OK% equ 0 (
|
|
echo.
|
|
echo WARNING: Some required ports are already in use!
|
|
echo.
|
|
echo To find what's using a port:
|
|
echo netstat -ano ^| findstr ":PORT"
|
|
echo.
|
|
echo To stop a process using a port:
|
|
echo 1. Find the PID from netstat output
|
|
echo 2. taskkill /PID [PID] /F
|
|
echo.
|
|
choice /C YN /M "Do you want to continue anyway"
|
|
if errorlevel 2 (
|
|
echo Setup cancelled.
|
|
exit /b 1
|
|
)
|
|
echo.
|
|
echo Continuing with setup...
|
|
)
|
|
echo.
|
|
|
|
REM Step 2: Configure environment
|
|
echo Configuring environment...
|
|
if exist "src\.env.%DB%" (
|
|
copy /y "src\.env.%DB%" "src\.env" >nul
|
|
echo Environment configured for %DB%
|
|
) else (
|
|
echo ERROR: Template file src\.env.%DB% not found
|
|
exit /b 1
|
|
)
|
|
|
|
REM Step 3: Build containers
|
|
echo Building Docker containers...
|
|
docker-compose build
|
|
echo Containers built
|
|
echo.
|
|
|
|
REM Step 4: Start containers
|
|
echo Starting Docker containers...
|
|
docker-compose --profile %DB% up -d
|
|
echo Containers started
|
|
echo.
|
|
|
|
REM Step 5: Wait for app container to be ready
|
|
echo Waiting for app container...
|
|
timeout /t 3 /nobreak >nul
|
|
echo App container ready
|
|
echo.
|
|
|
|
REM Step 6: Wait for database
|
|
if "%DB%"=="mysql" (
|
|
echo Waiting for database...
|
|
timeout /t 5 /nobreak >nul
|
|
echo Database ready
|
|
echo.
|
|
)
|
|
if "%DB%"=="pgsql" (
|
|
echo Waiting for database...
|
|
timeout /t 5 /nobreak >nul
|
|
echo Database ready
|
|
echo.
|
|
)
|
|
|
|
REM Step 7: Generate app key
|
|
echo Generating application key...
|
|
docker-compose exec -T app php artisan key:generate --force
|
|
echo App key generated
|
|
echo.
|
|
|
|
REM Step 8: Run migrations
|
|
echo Running database migrations...
|
|
docker-compose exec -T app php artisan migrate --force
|
|
echo Migrations completed
|
|
echo.
|
|
|
|
REM Step 9: Seed database
|
|
echo Seeding database (roles, permissions, admin user)...
|
|
docker-compose exec -T app php artisan db:seed --force
|
|
echo Database seeded
|
|
echo.
|
|
|
|
REM Step 10: Create storage link
|
|
echo Creating storage symlink...
|
|
docker-compose exec -T app php artisan storage:link
|
|
echo Storage linked
|
|
echo.
|
|
|
|
REM Done
|
|
echo.
|
|
echo ========================================================
|
|
echo Setup Complete!
|
|
echo ========================================================
|
|
echo.
|
|
echo Your Laravel application is ready!
|
|
echo.
|
|
echo Laravel App: http://localhost:8080
|
|
echo Admin Panel: http://localhost:8080/admin
|
|
echo Mailpit: http://localhost:8025
|
|
echo.
|
|
echo Admin Login:
|
|
echo Email: admin@example.com
|
|
echo Password: password
|
|
echo.
|
|
echo What's Included:
|
|
echo - Laravel 11 with Breeze authentication
|
|
echo - Filament admin panel with user management
|
|
echo - Pest testing framework
|
|
echo - Laravel Pint code style
|
|
echo - Queue workers ^& scheduler (optional profiles)
|
|
echo.
|
|
echo Common Commands:
|
|
echo docker-compose exec app php artisan [command]
|
|
echo docker-compose exec app composer [command]
|
|
echo docker-compose exec app ./vendor/bin/pest
|
|
echo docker-compose logs -f app
|
|
echo.
|
|
echo Stop containers:
|
|
echo docker-compose down
|
|
echo.
|
|
|
|
endlocal
|