generated from theradcoza/Laravel-Docker-Dev-Template
Initial commit
This commit is contained in:
85
scripts/backup.sh
Normal file
85
scripts/backup.sh
Normal file
@@ -0,0 +1,85 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Database Backup Script
|
||||
# Usage: ./scripts/backup.sh
|
||||
# Creates timestamped backup in backups/ directory
|
||||
|
||||
set -e
|
||||
|
||||
BACKUP_DIR="backups"
|
||||
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||
|
||||
# Create backup directory
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
# Detect database type from .env
|
||||
if [ -f "src/.env" ]; then
|
||||
DB_CONNECTION=$(grep "^DB_CONNECTION=" src/.env | cut -d '=' -f2)
|
||||
DB_DATABASE=$(grep "^DB_DATABASE=" src/.env | cut -d '=' -f2)
|
||||
DB_USERNAME=$(grep "^DB_USERNAME=" src/.env | cut -d '=' -f2)
|
||||
DB_PASSWORD=$(grep "^DB_PASSWORD=" src/.env | cut -d '=' -f2)
|
||||
else
|
||||
echo "Error: src/.env not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "=========================================="
|
||||
echo "Database Backup"
|
||||
echo "=========================================="
|
||||
echo "Connection: $DB_CONNECTION"
|
||||
echo "Database: $DB_DATABASE"
|
||||
echo ""
|
||||
|
||||
case "$DB_CONNECTION" in
|
||||
mysql)
|
||||
BACKUP_FILE="$BACKUP_DIR/${DB_DATABASE}_${TIMESTAMP}.sql"
|
||||
echo "Creating MySQL backup..."
|
||||
docker-compose exec -T mysql mysqldump \
|
||||
-u"$DB_USERNAME" \
|
||||
-p"$DB_PASSWORD" \
|
||||
"$DB_DATABASE" > "$BACKUP_FILE"
|
||||
;;
|
||||
pgsql)
|
||||
BACKUP_FILE="$BACKUP_DIR/${DB_DATABASE}_${TIMESTAMP}.sql"
|
||||
echo "Creating PostgreSQL backup..."
|
||||
docker-compose exec -T pgsql pg_dump \
|
||||
-U "$DB_USERNAME" \
|
||||
"$DB_DATABASE" > "$BACKUP_FILE"
|
||||
;;
|
||||
sqlite)
|
||||
BACKUP_FILE="$BACKUP_DIR/${DB_DATABASE}_${TIMESTAMP}.sqlite"
|
||||
echo "Creating SQLite backup..."
|
||||
cp "src/database/database.sqlite" "$BACKUP_FILE"
|
||||
;;
|
||||
*)
|
||||
echo "Error: Unknown database connection: $DB_CONNECTION"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Compress backup
|
||||
if [ -f "$BACKUP_FILE" ]; then
|
||||
gzip "$BACKUP_FILE"
|
||||
BACKUP_FILE="${BACKUP_FILE}.gz"
|
||||
|
||||
# Get file size
|
||||
SIZE=$(ls -lh "$BACKUP_FILE" | awk '{print $5}')
|
||||
|
||||
echo ""
|
||||
echo "✓ Backup created successfully!"
|
||||
echo " File: $BACKUP_FILE"
|
||||
echo " Size: $SIZE"
|
||||
echo ""
|
||||
|
||||
# Cleanup old backups (keep last 10)
|
||||
echo "Cleaning up old backups (keeping last 10)..."
|
||||
ls -t "$BACKUP_DIR"/*.gz 2>/dev/null | tail -n +11 | xargs -r rm --
|
||||
|
||||
# List recent backups
|
||||
echo ""
|
||||
echo "Recent backups:"
|
||||
ls -lht "$BACKUP_DIR"/*.gz 2>/dev/null | head -5
|
||||
else
|
||||
echo "Error: Backup file not created"
|
||||
exit 1
|
||||
fi
|
||||
1006
scripts/laravel-setup.sh
Normal file
1006
scripts/laravel-setup.sh
Normal file
File diff suppressed because it is too large
Load Diff
229
scripts/post-install.sh
Normal file
229
scripts/post-install.sh
Normal file
@@ -0,0 +1,229 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Post-install script for Laravel project
|
||||
# Run this after 'composer create-project laravel/laravel'
|
||||
# Usage: ./scripts/post-install.sh
|
||||
|
||||
set -e
|
||||
|
||||
echo "=========================================="
|
||||
echo "Laravel Post-Install Setup"
|
||||
echo "=========================================="
|
||||
|
||||
# Check if we're in a Laravel project
|
||||
if [ ! -f "artisan" ]; then
|
||||
echo "Error: Not in a Laravel project directory"
|
||||
echo "Run this from your Laravel project root (src/)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install Ignition (already included in Laravel, but ensure latest)
|
||||
echo ""
|
||||
echo "[1/5] Ensuring Ignition is installed..."
|
||||
composer require spatie/laravel-ignition --dev
|
||||
|
||||
# Install Flare for production error tracking
|
||||
echo ""
|
||||
echo "[2/5] Installing Flare for production error tracking..."
|
||||
composer require spatie/laravel-flare
|
||||
|
||||
# Install Telescope for development debugging (optional)
|
||||
echo ""
|
||||
read -p "Install Laravel Telescope for development debugging? [y/N]: " INSTALL_TELESCOPE
|
||||
if [[ "$INSTALL_TELESCOPE" =~ ^[Yy]$ ]]; then
|
||||
composer require laravel/telescope --dev
|
||||
php artisan telescope:install
|
||||
php artisan migrate
|
||||
echo "Telescope installed. Access at: /telescope"
|
||||
fi
|
||||
|
||||
# Publish Flare config
|
||||
echo ""
|
||||
echo "[3/5] Publishing Flare configuration..."
|
||||
php artisan vendor:publish --tag=flare-config
|
||||
|
||||
# Setup Laravel Pint (code style)
|
||||
echo ""
|
||||
echo "[4/5] Setting up Laravel Pint..."
|
||||
if [ -f "../src/pint.json" ]; then
|
||||
cp ../pint.json ./pint.json 2>/dev/null || true
|
||||
fi
|
||||
echo "Pint configured. Run: ./vendor/bin/pint"
|
||||
|
||||
# Create custom error pages
|
||||
echo ""
|
||||
echo "[5/5] Creating custom error pages..."
|
||||
|
||||
mkdir -p resources/views/errors
|
||||
|
||||
# 500 Error Page
|
||||
cat > resources/views/errors/500.blade.php << 'EOF'
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Server Error</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
}
|
||||
.container {
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
padding: 48px;
|
||||
text-align: center;
|
||||
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
|
||||
max-width: 500px;
|
||||
}
|
||||
h1 { color: #1f2937; font-size: 72px; margin: 0; }
|
||||
h2 { color: #4b5563; font-weight: 500; margin: 16px 0; }
|
||||
p { color: #6b7280; line-height: 1.6; }
|
||||
a {
|
||||
display: inline-block;
|
||||
margin-top: 24px;
|
||||
padding: 12px 24px;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 8px;
|
||||
font-weight: 500;
|
||||
}
|
||||
a:hover { background: #5a67d8; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>500</h1>
|
||||
<h2>Something went wrong</h2>
|
||||
<p>We're sorry, but something unexpected happened. Our team has been notified and is working on it.</p>
|
||||
<a href="/">Go Home</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
|
||||
# 404 Error Page
|
||||
cat > resources/views/errors/404.blade.php << 'EOF'
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Page Not Found</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
}
|
||||
.container {
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
padding: 48px;
|
||||
text-align: center;
|
||||
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
|
||||
max-width: 500px;
|
||||
}
|
||||
h1 { color: #1f2937; font-size: 72px; margin: 0; }
|
||||
h2 { color: #4b5563; font-weight: 500; margin: 16px 0; }
|
||||
p { color: #6b7280; line-height: 1.6; }
|
||||
a {
|
||||
display: inline-block;
|
||||
margin-top: 24px;
|
||||
padding: 12px 24px;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 8px;
|
||||
font-weight: 500;
|
||||
}
|
||||
a:hover { background: #5a67d8; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>404</h1>
|
||||
<h2>Page not found</h2>
|
||||
<p>The page you're looking for doesn't exist or has been moved.</p>
|
||||
<a href="/">Go Home</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
|
||||
# 503 Maintenance Page
|
||||
cat > resources/views/errors/503.blade.php << 'EOF'
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Maintenance Mode</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
|
||||
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
}
|
||||
.container {
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
padding: 48px;
|
||||
text-align: center;
|
||||
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
|
||||
max-width: 500px;
|
||||
}
|
||||
h1 { color: #1f2937; font-size: 48px; margin: 0; }
|
||||
h2 { color: #4b5563; font-weight: 500; margin: 16px 0; }
|
||||
p { color: #6b7280; line-height: 1.6; }
|
||||
.icon { font-size: 64px; margin-bottom: 16px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="icon">🔧</div>
|
||||
<h1>Be Right Back</h1>
|
||||
<h2>We're doing some maintenance</h2>
|
||||
<p>We're making some improvements and will be back shortly. Thanks for your patience!</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "=========================================="
|
||||
echo "Post-install setup complete!"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo " 1. Get your Flare key at: https://flareapp.io"
|
||||
echo " 2. Add FLARE_KEY to your .env file"
|
||||
echo " 3. Customize error pages in resources/views/errors/"
|
||||
echo ""
|
||||
echo "Ignition features (development):"
|
||||
echo " - AI error explanations"
|
||||
echo " - Click-to-open in VS Code"
|
||||
echo " - Runnable solution suggestions"
|
||||
echo ""
|
||||
if [[ "$INSTALL_TELESCOPE" =~ ^[Yy]$ ]]; then
|
||||
echo "Telescope dashboard: http://localhost:8080/telescope"
|
||||
echo ""
|
||||
fi
|
||||
101
scripts/restore.sh
Normal file
101
scripts/restore.sh
Normal file
@@ -0,0 +1,101 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Database Restore Script
|
||||
# Usage: ./scripts/restore.sh <backup_file>
|
||||
# Example: ./scripts/restore.sh backups/laravel_20240306_120000.sql.gz
|
||||
|
||||
set -e
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: ./scripts/restore.sh <backup_file>"
|
||||
echo ""
|
||||
echo "Available backups:"
|
||||
ls -lht backups/*.gz 2>/dev/null || echo " No backups found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BACKUP_FILE="$1"
|
||||
|
||||
if [ ! -f "$BACKUP_FILE" ]; then
|
||||
echo "Error: Backup file not found: $BACKUP_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Detect database type from .env
|
||||
if [ -f "src/.env" ]; then
|
||||
DB_CONNECTION=$(grep "^DB_CONNECTION=" src/.env | cut -d '=' -f2)
|
||||
DB_DATABASE=$(grep "^DB_DATABASE=" src/.env | cut -d '=' -f2)
|
||||
DB_USERNAME=$(grep "^DB_USERNAME=" src/.env | cut -d '=' -f2)
|
||||
DB_PASSWORD=$(grep "^DB_PASSWORD=" src/.env | cut -d '=' -f2)
|
||||
else
|
||||
echo "Error: src/.env not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "=========================================="
|
||||
echo "Database Restore"
|
||||
echo "=========================================="
|
||||
echo "Connection: $DB_CONNECTION"
|
||||
echo "Database: $DB_DATABASE"
|
||||
echo "File: $BACKUP_FILE"
|
||||
echo ""
|
||||
|
||||
read -p "⚠️ This will OVERWRITE the current database. Continue? [y/N]: " CONFIRM
|
||||
if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then
|
||||
echo "Restore cancelled."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Decompress if needed
|
||||
if [[ "$BACKUP_FILE" == *.gz ]]; then
|
||||
echo "Decompressing backup..."
|
||||
TEMP_FILE=$(mktemp)
|
||||
gunzip -c "$BACKUP_FILE" > "$TEMP_FILE"
|
||||
RESTORE_FILE="$TEMP_FILE"
|
||||
else
|
||||
RESTORE_FILE="$BACKUP_FILE"
|
||||
fi
|
||||
|
||||
case "$DB_CONNECTION" in
|
||||
mysql)
|
||||
echo "Restoring MySQL database..."
|
||||
docker-compose exec -T mysql mysql \
|
||||
-u"$DB_USERNAME" \
|
||||
-p"$DB_PASSWORD" \
|
||||
"$DB_DATABASE" < "$RESTORE_FILE"
|
||||
;;
|
||||
pgsql)
|
||||
echo "Restoring PostgreSQL database..."
|
||||
# Drop and recreate database
|
||||
docker-compose exec -T pgsql psql \
|
||||
-U "$DB_USERNAME" \
|
||||
-c "DROP DATABASE IF EXISTS $DB_DATABASE;"
|
||||
docker-compose exec -T pgsql psql \
|
||||
-U "$DB_USERNAME" \
|
||||
-c "CREATE DATABASE $DB_DATABASE;"
|
||||
docker-compose exec -T pgsql psql \
|
||||
-U "$DB_USERNAME" \
|
||||
-d "$DB_DATABASE" < "$RESTORE_FILE"
|
||||
;;
|
||||
sqlite)
|
||||
echo "Restoring SQLite database..."
|
||||
cp "$RESTORE_FILE" "src/database/database.sqlite"
|
||||
chmod 666 "src/database/database.sqlite"
|
||||
;;
|
||||
*)
|
||||
echo "Error: Unknown database connection: $DB_CONNECTION"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Cleanup temp file
|
||||
if [ -n "$TEMP_FILE" ] && [ -f "$TEMP_FILE" ]; then
|
||||
rm "$TEMP_FILE"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "✓ Database restored successfully!"
|
||||
echo ""
|
||||
echo "You may want to run:"
|
||||
echo " make artisan cmd='cache:clear'"
|
||||
echo " make artisan cmd='config:clear'"
|
||||
Reference in New Issue
Block a user