Files
Laravel-Docker-Dev-Template/setup.sh
theRADcozaDEV 97acc5e8ea CRITICAL FIX: Move composer install after containers start
The previous setup scripts ran 'composer install' in a temporary container
before starting the actual containers. This caused vendor/ directory to be
created inside the temporary container and then deleted, leaving the host
filesystem without dependencies.

Changes:
- setup.bat: Move composer install to Step 4 (after containers start)
- setup.sh: Move composer install to Step 4 (after containers start)
- Use 'docker-compose exec' instead of 'docker-compose run --rm'
- This ensures vendor/ is written to the host filesystem via volume mount
- Added TEST_SETUP.md with comprehensive testing procedures

Now the vendor/ directory will persist correctly on Windows/WSL2 and the
app will load without 'vendor/autoload.php not found' errors.

This was the root cause of the setup not being truly '2-minute ready'.
2026-03-09 18:35:56 +02:00

127 lines
4.5 KiB
Bash

#!/bin/bash
# Laravel Docker Development Template - Quick Setup
# Everything is pre-installed! This just starts Docker and sets up the database.
# Usage: ./setup.sh [mysql|pgsql|sqlite]
set -e
DB=${1:-mysql}
VALID_DBS=("mysql" "pgsql" "sqlite")
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${GREEN}╔════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ Laravel Docker Development Template ║${NC}"
echo -e "${GREEN}║ Quick Setup - Everything Pre-Installed! ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════════════╝${NC}"
echo ""
# Validate database choice
if [[ ! " ${VALID_DBS[@]} " =~ " ${DB} " ]]; then
echo -e "${RED}Error: Invalid database '${DB}'${NC}"
echo "Usage: ./setup.sh [mysql|pgsql|sqlite]"
echo "Example: ./setup.sh mysql"
exit 1
fi
echo -e "${YELLOW}Setting up with ${DB}...${NC}"
echo ""
# Step 1: Configure environment
echo -e "${YELLOW}→ Configuring environment...${NC}"
if [ -f "src/.env.${DB}" ]; then
cp "src/.env.${DB}" "src/.env"
echo -e "${GREEN}✓ Environment configured for ${DB}${NC}"
else
echo -e "${RED}✗ Template file src/.env.${DB} not found${NC}"
exit 1
fi
# Step 2: Build containers
echo -e "${YELLOW}→ Building Docker containers...${NC}"
docker-compose build
echo -e "${GREEN}✓ Containers built${NC}"
echo ""
# Step 3: Start containers
echo -e "${YELLOW}→ Starting Docker containers...${NC}"
docker-compose --profile ${DB} up -d
echo -e "${GREEN}✓ Containers started${NC}"
echo ""
# Step 4: Install composer dependencies
echo -e "${YELLOW}→ Installing composer dependencies...${NC}"
docker-compose exec app composer install --no-interaction
echo -e "${GREEN}✓ Dependencies installed${NC}"
echo ""
# Step 5: Wait for database
if [ "$DB" = "mysql" ] || [ "$DB" = "pgsql" ]; then
echo -e "${YELLOW}→ Waiting for database...${NC}"
sleep 5
echo -e "${GREEN}✓ Database ready${NC}"
echo ""
fi
# Step 6: Generate app key
echo -e "${YELLOW}→ Generating application key...${NC}"
docker-compose exec app php artisan key:generate --force
echo -e "${GREEN}✓ App key generated${NC}"
echo ""
# Step 7: Run migrations
echo -e "${YELLOW}→ Running database migrations...${NC}"
docker-compose exec app php artisan migrate --force
echo -e "${GREEN}✓ Migrations completed${NC}"
echo ""
# Step 8: Seed database (roles, permissions, admin user)
echo -e "${YELLOW}→ Seeding database (roles, permissions, admin user)...${NC}"
docker-compose exec app php artisan db:seed --force
echo -e "${GREEN}✓ Database seeded${NC}"
echo ""
# Step 9: Create storage link
echo -e "${YELLOW}→ Creating storage symlink...${NC}"
docker-compose exec app php artisan storage:link
echo -e "${GREEN}✓ Storage linked${NC}"
echo ""
# Done!
echo ""
echo -e "${GREEN}╔════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ 🎉 Setup Complete! 🎉 ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${GREEN}Your Laravel application is ready!${NC}"
echo ""
echo -e " 📱 Laravel App: ${GREEN}http://localhost:8080${NC}"
echo -e " 🔐 Admin Panel: ${GREEN}http://localhost:8080/admin${NC}"
echo -e " 📧 Mailpit: ${GREEN}http://localhost:8025${NC}"
echo ""
echo -e "${YELLOW}Admin Login:${NC}"
echo -e " Email: admin@example.com"
echo -e " Password: password"
echo ""
echo -e "${YELLOW}What's Included:${NC}"
echo -e " ✓ Laravel 11 with Breeze authentication"
echo -e " ✓ Filament admin panel with user management"
echo -e " ✓ Pest testing framework"
echo -e " ✓ Laravel Pint code style"
echo -e " ✓ Queue workers & scheduler (optional profiles)"
echo ""
echo -e "${YELLOW}Common Commands:${NC}"
echo -e " docker-compose exec app php artisan <command>"
echo -e " docker-compose exec app composer <command>"
echo -e " docker-compose exec app ./vendor/bin/pest"
echo -e " docker-compose logs -f app"
echo ""
echo -e "${YELLOW}Stop containers:${NC}"
echo -e " docker-compose down"
echo ""