Files
Laravel-Docker-Dev-Template/setup.sh

124 lines
4.6 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: Install composer dependencies
echo -e "${YELLOW}→ Installing composer dependencies...${NC}"
docker-compose build
docker-compose --profile ${DB} run --rm app composer install --no-interaction
echo -e "${GREEN}✓ Dependencies installed${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: 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 5: Generate app key if needed
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 6: 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 7: 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 ""
# Step 8: Create admin user
echo -e "${YELLOW}→ Creating admin user...${NC}"
echo -e "${YELLOW} Email: admin@example.com${NC}"
echo -e "${YELLOW} Password: password${NC}"
docker-compose exec -T app php artisan make:filament-user --name=Admin --email=admin@example.com --password=password 2>/dev/null || echo -e "${YELLOW} (Admin user may already exist)${NC}"
echo -e "${GREEN}✓ Admin user ready${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 ""