remove not used sh and md
This commit is contained in:
356
BACKUP_README.md
356
BACKUP_README.md
@@ -1,356 +0,0 @@
|
||||
# 🗃️ CKB Database Backup & Restore Guide
|
||||
|
||||
Panduan lengkap untuk backup dan restore database Docker CKB menggunakan mysqldump.
|
||||
|
||||
## 📋 Informasi Database
|
||||
|
||||
- **Container Name**: `ckb-mysql-dev`
|
||||
- **Database Name**: `ckb_db`
|
||||
- **Database Type**: MariaDB 10.6
|
||||
- **Port**: 3306
|
||||
- **Username**: `root` / `laravel`
|
||||
- **Password**: `root` / `password`
|
||||
|
||||
## 🛠️ Available Scripts
|
||||
|
||||
### 1. **backup_db.sh** - Simple Backup
|
||||
|
||||
Script backup sederhana dengan kompresi opsional.
|
||||
|
||||
```bash
|
||||
./backup_db.sh
|
||||
```
|
||||
|
||||
**Features:**
|
||||
|
||||
- ✅ Backup database dengan timestamp
|
||||
- ✅ Kompresi opsional (gzip)
|
||||
- ✅ Validasi container status
|
||||
- ✅ Progress indicator
|
||||
|
||||
### 2. **restore_db.sh** - Database Restore
|
||||
|
||||
Script restore dengan interface interaktif.
|
||||
|
||||
```bash
|
||||
./restore_db.sh
|
||||
```
|
||||
|
||||
**Features:**
|
||||
|
||||
- ✅ List backup files yang tersedia
|
||||
- ✅ Support compressed & uncompressed files
|
||||
- ✅ Konfirmasi sebelum restore
|
||||
- ✅ Automatic decompression
|
||||
|
||||
### 3. **backup_advanced.sh** - Advanced Backup
|
||||
|
||||
Script backup lengkap dengan berbagai opsi.
|
||||
|
||||
```bash
|
||||
./backup_advanced.sh
|
||||
```
|
||||
|
||||
**Features:**
|
||||
|
||||
- ✅ Multiple backup types (Full, Structure, Data)
|
||||
- ✅ Automatic cleanup old backups
|
||||
- ✅ Colored output
|
||||
- ✅ Backup statistics
|
||||
- ✅ Compression with ratio info
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
### Basic Backup
|
||||
|
||||
```bash
|
||||
# Simple backup
|
||||
./backup_db.sh
|
||||
|
||||
# Manual backup command
|
||||
docker exec ckb-mysql-dev mysqldump -u root -proot ckb_db > backup.sql
|
||||
```
|
||||
|
||||
### Advanced Backup
|
||||
|
||||
```bash
|
||||
# Interactive advanced backup
|
||||
./backup_advanced.sh
|
||||
|
||||
# Full backup with all options
|
||||
docker exec ckb-mysql-dev mysqldump -u root -proot \
|
||||
--single-transaction \
|
||||
--routines \
|
||||
--triggers \
|
||||
--add-drop-table \
|
||||
ckb_db > full_backup.sql
|
||||
```
|
||||
|
||||
### Restore Database
|
||||
|
||||
```bash
|
||||
# Interactive restore
|
||||
./restore_db.sh
|
||||
|
||||
# Manual restore
|
||||
docker exec -i ckb-mysql-dev mysql -u root -proot ckb_db < backup.sql
|
||||
|
||||
# Restore compressed backup
|
||||
gunzip -c backup.sql.gz | docker exec -i ckb-mysql-dev mysql -u root -proot ckb_db
|
||||
```
|
||||
|
||||
## 📂 Backup Types
|
||||
|
||||
### 1. **Full Backup** (Default)
|
||||
|
||||
```bash
|
||||
docker exec ckb-mysql-dev mysqldump -u root -proot \
|
||||
--single-transaction \
|
||||
--routines \
|
||||
--triggers \
|
||||
--add-drop-table \
|
||||
ckb_db > full_backup.sql
|
||||
```
|
||||
|
||||
### 2. **Structure Only**
|
||||
|
||||
```bash
|
||||
docker exec ckb-mysql-dev mysqldump -u root -proot \
|
||||
--no-data \
|
||||
--routines \
|
||||
--triggers \
|
||||
ckb_db > structure_backup.sql
|
||||
```
|
||||
|
||||
### 3. **Data Only**
|
||||
|
||||
```bash
|
||||
docker exec ckb-mysql-dev mysqldump -u root -proot \
|
||||
--no-create-info \
|
||||
--single-transaction \
|
||||
ckb_db > data_backup.sql
|
||||
```
|
||||
|
||||
### 4. **Compressed Backup**
|
||||
|
||||
```bash
|
||||
docker exec ckb-mysql-dev mysqldump -u root -proot ckb_db | gzip > backup.sql.gz
|
||||
```
|
||||
|
||||
## ⚙️ Manual Commands
|
||||
|
||||
### Basic Commands
|
||||
|
||||
```bash
|
||||
# Check container status
|
||||
docker ps | grep ckb-mysql-dev
|
||||
|
||||
# Backup with timestamp
|
||||
docker exec ckb-mysql-dev mysqldump -u root -proot ckb_db > ckb_backup_$(date +%Y%m%d_%H%M%S).sql
|
||||
|
||||
# Backup all databases
|
||||
docker exec ckb-mysql-dev mysqldump -u root -proot --all-databases > all_databases.sql
|
||||
|
||||
# Backup specific tables
|
||||
docker exec ckb-mysql-dev mysqldump -u root -proot ckb_db table1 table2 > specific_tables.sql
|
||||
```
|
||||
|
||||
### Advanced Options
|
||||
|
||||
```bash
|
||||
# Backup with extended options
|
||||
docker exec ckb-mysql-dev mysqldump -u root -proot \
|
||||
--single-transaction \
|
||||
--routines \
|
||||
--triggers \
|
||||
--events \
|
||||
--add-drop-table \
|
||||
--add-drop-trigger \
|
||||
--hex-blob \
|
||||
--complete-insert \
|
||||
ckb_db > advanced_backup.sql
|
||||
|
||||
# Backup without locking tables (for MyISAM)
|
||||
docker exec ckb-mysql-dev mysqldump -u root -proot \
|
||||
--lock-tables=false \
|
||||
ckb_db > no_lock_backup.sql
|
||||
|
||||
# Backup with conditions
|
||||
docker exec ckb-mysql-dev mysqldump -u root -proot \
|
||||
--where="created_at >= '2023-01-01'" \
|
||||
ckb_db table_name > conditional_backup.sql
|
||||
```
|
||||
|
||||
## 🔄 Automated Backups
|
||||
|
||||
### Cron Job Setup
|
||||
|
||||
```bash
|
||||
# Edit crontab
|
||||
crontab -e
|
||||
|
||||
# Daily backup at 2 AM
|
||||
0 2 * * * /path/to/backup_db.sh
|
||||
|
||||
# Weekly full backup on Sunday at 3 AM
|
||||
0 3 * * 0 /path/to/backup_advanced.sh
|
||||
|
||||
# Monthly cleanup (keep last 30 days)
|
||||
0 4 1 * * find /path/to/backups -name "*.sql*" -mtime +30 -delete
|
||||
```
|
||||
|
||||
### Systemd Timer (Alternative to Cron)
|
||||
|
||||
Create `/etc/systemd/system/ckb-backup.service`:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=CKB Database Backup
|
||||
After=docker.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/path/to/backup_db.sh
|
||||
User=root
|
||||
```
|
||||
|
||||
Create `/etc/systemd/system/ckb-backup.timer`:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Run CKB backup daily
|
||||
Requires=ckb-backup.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
```
|
||||
|
||||
Enable timer:
|
||||
|
||||
```bash
|
||||
sudo systemctl enable ckb-backup.timer
|
||||
sudo systemctl start ckb-backup.timer
|
||||
```
|
||||
|
||||
## 📊 Backup Management
|
||||
|
||||
### Check Backup Size
|
||||
|
||||
```bash
|
||||
# Show backup directory size
|
||||
du -sh backups/
|
||||
|
||||
# List all backups with sizes
|
||||
ls -lah backups/
|
||||
|
||||
# Show compression ratio
|
||||
for file in backups/*.sql.gz; do
|
||||
original_size=$(gunzip -l "$file" | tail -1 | awk '{print $2}')
|
||||
compressed_size=$(stat -c%s "$file")
|
||||
ratio=$(echo "scale=1; (1 - $compressed_size/$original_size) * 100" | bc)
|
||||
echo "$(basename "$file"): ${ratio}% compression"
|
||||
done
|
||||
```
|
||||
|
||||
### Cleanup Old Backups
|
||||
|
||||
```bash
|
||||
# Delete backups older than 30 days
|
||||
find backups/ -name "*.sql*" -mtime +30 -delete
|
||||
|
||||
# Keep only last 10 backups
|
||||
ls -1t backups/ckb_backup_*.sql* | tail -n +11 | xargs rm -f
|
||||
|
||||
# Clean by size (keep if total < 1GB)
|
||||
total_size=$(du -s backups/ | cut -f1)
|
||||
if [ $total_size -gt 1048576 ]; then
|
||||
# Delete oldest files until under 1GB
|
||||
echo "Cleaning up old backups..."
|
||||
fi
|
||||
```
|
||||
|
||||
## 🚨 Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Container not running**
|
||||
|
||||
```bash
|
||||
# Start container
|
||||
docker-compose up -d db
|
||||
|
||||
# Check logs
|
||||
docker logs ckb-mysql-dev
|
||||
```
|
||||
|
||||
2. **Permission denied**
|
||||
|
||||
```bash
|
||||
# Fix script permissions
|
||||
chmod +x *.sh
|
||||
|
||||
# Fix backup directory permissions
|
||||
sudo chown -R $USER:$USER backups/
|
||||
```
|
||||
|
||||
3. **Out of disk space**
|
||||
|
||||
```bash
|
||||
# Check disk usage
|
||||
df -h
|
||||
|
||||
# Clean old backups
|
||||
find backups/ -name "*.sql*" -mtime +7 -delete
|
||||
```
|
||||
|
||||
4. **MySQL connection error**
|
||||
|
||||
```bash
|
||||
# Test connection
|
||||
docker exec ckb-mysql-dev mysql -u root -proot -e "SELECT 1;"
|
||||
|
||||
# Check MySQL status
|
||||
docker exec ckb-mysql-dev mysqladmin -u root -proot status
|
||||
```
|
||||
|
||||
## 🔐 Security Notes
|
||||
|
||||
1. **Never store passwords in plain text** - Consider using MySQL config files
|
||||
2. **Encrypt sensitive backups** - Use GPG for production environments
|
||||
3. **Secure backup storage** - Store backups in secure, offsite locations
|
||||
4. **Regular restore testing** - Test backups regularly to ensure they work
|
||||
|
||||
## 📈 Best Practices
|
||||
|
||||
1. **Regular Backups**: Daily for production, weekly for development
|
||||
2. **Multiple Backup Types**: Keep both full and incremental backups
|
||||
3. **Offsite Storage**: Store backups in different physical/cloud locations
|
||||
4. **Compression**: Use gzip to save storage space
|
||||
5. **Retention Policy**: Define how long to keep backups
|
||||
6. **Monitoring**: Monitor backup success/failure
|
||||
7. **Documentation**: Document backup procedures and recovery steps
|
||||
8. **Testing**: Regularly test restore procedures
|
||||
|
||||
## 📝 File Structure
|
||||
|
||||
```
|
||||
backups/
|
||||
├── ckb_backup_20231225_143022.sql.gz # Full backup (compressed)
|
||||
├── ckb_structure_20231225_143022.sql # Structure only
|
||||
├── ckb_data_20231225_143022.sql.gz # Data only (compressed)
|
||||
└── README.md # This documentation
|
||||
|
||||
Scripts:
|
||||
├── backup_db.sh # Simple backup script
|
||||
├── backup_advanced.sh # Advanced backup with options
|
||||
├── restore_db.sh # Interactive restore script
|
||||
└── BACKUP_README.md # This documentation
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**Made with ❤️ for CKB Project**
|
||||
@@ -1,169 +0,0 @@
|
||||
# 📊 Database Import Guide untuk CKB Laravel Application
|
||||
|
||||
## 🚀 Quick Start (Paling Mudah)
|
||||
|
||||
Jika Anda baru pertama kali setup aplikasi:
|
||||
|
||||
```bash
|
||||
# Jalankan quick setup yang otomatis import database
|
||||
./docker-quick-setup.sh dev
|
||||
```
|
||||
|
||||
## 📥 Manual Import Database
|
||||
|
||||
### 1. Import ke Development Environment
|
||||
|
||||
```bash
|
||||
# Pastikan containers berjalan terlebih dahulu
|
||||
./docker-start.sh dev up
|
||||
|
||||
# Import database ckb.sql
|
||||
./docker-import-db.sh dev
|
||||
|
||||
# Atau import file SQL lain
|
||||
./docker-import-db.sh dev nama-file-backup.sql
|
||||
```
|
||||
|
||||
### 2. Import ke Production Environment
|
||||
|
||||
```bash
|
||||
# Start production environment
|
||||
./docker-start.sh prod up
|
||||
|
||||
# Import database
|
||||
./docker-import-db.sh prod
|
||||
|
||||
# Atau dengan file khusus
|
||||
./docker-import-db.sh prod production-backup.sql
|
||||
```
|
||||
|
||||
## 🔄 Auto Import (Recommended untuk First Time Setup)
|
||||
|
||||
Ketika Anda menjalankan Docker containers untuk pertama kali, file `ckb.sql` akan otomatis diimport ke database. Ini terjadi karena:
|
||||
|
||||
1. File `ckb.sql` di-mount ke `/docker-entrypoint-initdb.d/01-init.sql` di MySQL container
|
||||
2. MySQL otomatis menjalankan semua file `.sql` di direktori tersebut saat inisialisasi
|
||||
3. Auto import hanya terjadi jika database kosong/belum ada
|
||||
|
||||
## 🛠️ Troubleshooting Import
|
||||
|
||||
### Problem: Database tidak terimport otomatis
|
||||
|
||||
**Solusi:**
|
||||
```bash
|
||||
# 1. Stop containers
|
||||
docker-compose down
|
||||
|
||||
# 2. Hapus volume database (HATI-HATI: akan hapus data!)
|
||||
docker-compose down -v
|
||||
|
||||
# 3. Start ulang (akan trigger auto import)
|
||||
docker-compose up -d
|
||||
|
||||
# 4. Atau import manual
|
||||
./docker-import-db.sh dev
|
||||
```
|
||||
|
||||
### Problem: Permission denied saat import
|
||||
|
||||
**Solusi:**
|
||||
```bash
|
||||
# Pastikan script executable
|
||||
chmod +x docker-import-db.sh
|
||||
chmod +x docker-quick-setup.sh
|
||||
|
||||
# Pastikan file SQL readable
|
||||
chmod 644 ckb.sql
|
||||
```
|
||||
|
||||
### Problem: Database terlalu besar, import timeout
|
||||
|
||||
**Solusi:**
|
||||
```bash
|
||||
# Import langsung ke container dengan timeout yang lebih besar
|
||||
docker-compose exec -T db mysql -u root -proot ckb_db < ckb.sql
|
||||
|
||||
# Atau split file SQL jika sangat besar
|
||||
split -l 10000 ckb.sql ckb_split_
|
||||
# Kemudian import satu per satu
|
||||
```
|
||||
|
||||
## 📋 Verifikasi Import Berhasil
|
||||
|
||||
### 1. Cek via phpMyAdmin
|
||||
- Buka http://localhost:8080
|
||||
- Login dengan: server=db, username=root, password=root
|
||||
- Pilih database `ckb_db`
|
||||
- Lihat tabel yang sudah terimport
|
||||
|
||||
### 2. Cek via Command Line
|
||||
```bash
|
||||
# Lihat daftar tabel
|
||||
docker-compose exec db mysql -u root -proot -e "USE ckb_db; SHOW TABLES;"
|
||||
|
||||
# Hitung jumlah tabel
|
||||
docker-compose exec db mysql -u root -proot -e "USE ckb_db; SELECT COUNT(*) as total_tables FROM information_schema.tables WHERE table_schema='ckb_db';"
|
||||
|
||||
# Lihat contoh data dari salah satu tabel
|
||||
docker-compose exec db mysql -u root -proot -e "USE ckb_db; SELECT * FROM users LIMIT 5;"
|
||||
```
|
||||
|
||||
### 3. Test Aplikasi Laravel
|
||||
```bash
|
||||
# Cek koneksi database dari Laravel
|
||||
docker-compose exec app php artisan tinker
|
||||
# Di dalam tinker:
|
||||
# DB::connection()->getPdo();
|
||||
# \App\Models\User::count();
|
||||
```
|
||||
|
||||
## 💾 Backup Database
|
||||
|
||||
### Backup Development
|
||||
```bash
|
||||
# Backup dengan timestamp
|
||||
docker-compose exec db mysqldump -u root -proot ckb_db > backup_dev_$(date +%Y%m%d_%H%M%S).sql
|
||||
|
||||
# Backup sederhana
|
||||
docker-compose exec db mysqldump -u root -proot ckb_db > backup_current.sql
|
||||
```
|
||||
|
||||
### Backup Production
|
||||
```bash
|
||||
# Backup production database
|
||||
docker-compose -f docker-compose.prod.yml exec db mysqldump -u root -p ckb_production > backup_prod_$(date +%Y%m%d_%H%M%S).sql
|
||||
```
|
||||
|
||||
## 🔄 Replace Database dengan Backup Baru
|
||||
|
||||
```bash
|
||||
# 1. Backup database saat ini (safety)
|
||||
docker-compose exec db mysqldump -u root -proot ckb_db > backup_before_replace.sql
|
||||
|
||||
# 2. Import database baru
|
||||
./docker-import-db.sh dev new-backup.sql
|
||||
|
||||
# 3. Clear Laravel cache
|
||||
docker-compose exec app php artisan cache:clear
|
||||
docker-compose exec app php artisan config:clear
|
||||
```
|
||||
|
||||
## 📝 Notes Penting
|
||||
|
||||
1. **File ckb.sql**: Pastikan file ini selalu ada di root project untuk auto-import
|
||||
2. **Backup Safety**: Script import otomatis membuat backup sebelum replace database
|
||||
3. **Environment**: Selalu pastikan Anda menggunakan environment yang benar (dev/prod)
|
||||
4. **Permissions**: Database user harus punya permission CREATE, DROP, INSERT untuk import
|
||||
5. **Size Limit**: File SQL besar (>100MB) mungkin perlu setting timeout MySQL yang lebih besar
|
||||
|
||||
## 🎯 Best Practices
|
||||
|
||||
1. **Selalu backup** sebelum import database baru
|
||||
2. **Test di development** dulu sebelum import ke production
|
||||
3. **Gunakan quick setup** untuk setup pertama kali
|
||||
4. **Monitor logs** saat import: `docker-compose logs -f db`
|
||||
5. **Verify data** setelah import berhasil
|
||||
|
||||
---
|
||||
|
||||
**Untuk bantuan lebih lanjut, lihat file `DOCKER-README.md` atau `docker-import-db.sh --help`**
|
||||
289
DEPLOYMENT.md
289
DEPLOYMENT.md
@@ -1,289 +0,0 @@
|
||||
# CKB Application Deployment Guide
|
||||
|
||||
## Overview
|
||||
|
||||
This guide explains how to deploy the CKB Laravel application with Docker, SSL certificate, and reverse proxy configuration.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Ubuntu/Debian server
|
||||
- Docker and Docker Compose installed
|
||||
- Domain pointing to server IP
|
||||
- Nginx installed on main server
|
||||
- Root/sudo access
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
Internet → Nginx (Port 80/443) → Docker Container (Port 8082) → Laravel App
|
||||
```
|
||||
|
||||
## File Structure
|
||||
|
||||
```
|
||||
/var/www/ckb/
|
||||
├── docker-compose.prod.yml # Docker services configuration
|
||||
├── Dockerfile # Laravel app container
|
||||
├── docker/
|
||||
│ ├── nginx-proxy.conf # Internal nginx proxy
|
||||
│ ├── php.ini # PHP configuration
|
||||
│ ├── mysql.cnf # MySQL configuration
|
||||
│ └── supervisord.conf # Process manager
|
||||
├── nginx-ckb-reverse-proxy.conf # Main server nginx config
|
||||
├── deploy-ckb.sh # Deployment script
|
||||
├── setup-ssl.sh # SSL certificate setup script
|
||||
└── DEPLOYMENT.md # This file
|
||||
```
|
||||
|
||||
## Container Names and Volumes
|
||||
|
||||
All containers and volumes are prefixed with `ckb-` to avoid conflicts:
|
||||
|
||||
### Containers:
|
||||
|
||||
- `ckb-laravel-app` - Laravel application
|
||||
- `ckb-mariadb` - Database
|
||||
- `ckb-redis` - Cache/Queue
|
||||
- `ckb-nginx-proxy` - Internal nginx proxy
|
||||
|
||||
### Volumes:
|
||||
|
||||
- `ckb_mysql_data` - Database data
|
||||
- `ckb_redis_data` - Redis data
|
||||
- `ckb_nginx_logs` - Nginx logs
|
||||
- `ckb_storage_logs` - Laravel logs
|
||||
- `ckb_storage_cache` - Laravel cache
|
||||
|
||||
## Step-by-Step Deployment
|
||||
|
||||
### Step 1: Prepare the Application
|
||||
|
||||
```bash
|
||||
cd /var/www/ckb
|
||||
|
||||
# Make scripts executable
|
||||
chmod +x deploy-ckb.sh
|
||||
chmod +x setup-ssl.sh
|
||||
```
|
||||
|
||||
### Step 2: Deploy Docker Application
|
||||
|
||||
```bash
|
||||
# Run deployment script
|
||||
./deploy-ckb.sh
|
||||
```
|
||||
|
||||
This script will:
|
||||
|
||||
- Stop existing containers
|
||||
- Build and start new containers
|
||||
- Check if containers are running
|
||||
- Verify port 8082 is accessible
|
||||
|
||||
### Step 3: Setup SSL Certificate
|
||||
|
||||
```bash
|
||||
# Run SSL setup script (requires sudo)
|
||||
sudo ./setup-ssl.sh
|
||||
```
|
||||
|
||||
This script will:
|
||||
|
||||
- Install certbot if not present
|
||||
- Create temporary nginx configuration
|
||||
- Generate Let's Encrypt certificate
|
||||
- Update nginx with SSL configuration
|
||||
- Setup auto-renewal
|
||||
|
||||
### Step 4: Manual Verification
|
||||
|
||||
```bash
|
||||
# Check if containers are running
|
||||
docker ps | grep ckb
|
||||
|
||||
# Check if port 8082 is accessible
|
||||
curl -I http://localhost:8082
|
||||
|
||||
# Check SSL certificate
|
||||
sudo certbot certificates
|
||||
|
||||
# Test HTTPS access
|
||||
curl -I https://bengkel.digitaloasis.xyz
|
||||
```
|
||||
|
||||
## Configuration Files
|
||||
|
||||
### docker-compose.prod.yml
|
||||
|
||||
- Updated container names with `ckb-` prefix
|
||||
- Removed certbot service (handled by main server)
|
||||
- Updated APP_URL to use HTTPS
|
||||
- Specific volume names to avoid conflicts
|
||||
|
||||
### nginx-proxy.conf
|
||||
|
||||
- Simplified configuration (no SSL handling)
|
||||
- Proxy to `ckb-app` container
|
||||
- Rate limiting and security headers
|
||||
- Static file caching
|
||||
|
||||
### nginx-ckb-reverse-proxy.conf
|
||||
|
||||
- Main server nginx configuration
|
||||
- SSL termination
|
||||
- Reverse proxy to port 8082
|
||||
- Security headers and SSL settings
|
||||
|
||||
## Environment Variables
|
||||
|
||||
Create `.env` file in `/var/www/ckb/`:
|
||||
|
||||
```env
|
||||
APP_ENV=production
|
||||
APP_DEBUG=false
|
||||
APP_URL=https://bengkel.digitaloasis.xyz
|
||||
DB_DATABASE=ckb_production
|
||||
DB_USERNAME=laravel
|
||||
DB_PASSWORD=your_password
|
||||
DB_ROOT_PASSWORD=your_root_password
|
||||
REDIS_PASSWORD=your_redis_password
|
||||
```
|
||||
|
||||
## Monitoring and Maintenance
|
||||
|
||||
### View Logs
|
||||
|
||||
```bash
|
||||
# Docker logs
|
||||
docker-compose -f docker-compose.prod.yml logs -f
|
||||
|
||||
# Nginx logs (main server)
|
||||
sudo tail -f /var/log/nginx/access.log
|
||||
sudo tail -f /var/log/nginx/error.log
|
||||
|
||||
# Laravel logs
|
||||
docker exec ckb-laravel-app tail -f /var/www/html/storage/logs/laravel.log
|
||||
```
|
||||
|
||||
### SSL Certificate Renewal
|
||||
|
||||
```bash
|
||||
# Manual renewal
|
||||
sudo certbot renew
|
||||
|
||||
# Check renewal status
|
||||
sudo certbot certificates
|
||||
```
|
||||
|
||||
### Container Management
|
||||
|
||||
```bash
|
||||
# Restart all services
|
||||
docker-compose -f docker-compose.prod.yml restart
|
||||
|
||||
# Update application
|
||||
git pull
|
||||
docker-compose -f docker-compose.prod.yml up -d --build
|
||||
|
||||
# Stop all services
|
||||
docker-compose -f docker-compose.prod.yml down
|
||||
|
||||
# Remove all data (WARNING: This will delete all data)
|
||||
docker-compose -f docker-compose.prod.yml down -v
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Port 8082 Not Accessible
|
||||
|
||||
```bash
|
||||
# Check if container is running
|
||||
docker ps | grep ckb-nginx-proxy
|
||||
|
||||
# Check container logs
|
||||
docker-compose -f docker-compose.prod.yml logs ckb-nginx-proxy
|
||||
|
||||
# Check if port is bound
|
||||
netstat -tlnp | grep 8082
|
||||
```
|
||||
|
||||
### SSL Certificate Issues
|
||||
|
||||
```bash
|
||||
# Check certificate status
|
||||
sudo certbot certificates
|
||||
|
||||
# Test certificate
|
||||
sudo certbot renew --dry-run
|
||||
|
||||
# Check nginx configuration
|
||||
sudo nginx -t
|
||||
```
|
||||
|
||||
### Database Connection Issues
|
||||
|
||||
```bash
|
||||
# Check database container
|
||||
docker exec ckb-mariadb mysql -u root -p -e "SHOW DATABASES;"
|
||||
|
||||
# Check Laravel database connection
|
||||
docker exec ckb-laravel-app php artisan tinker
|
||||
```
|
||||
|
||||
### Permission Issues
|
||||
|
||||
```bash
|
||||
# Fix Laravel permissions
|
||||
docker exec ckb-laravel-app chown -R www-data:www-data /var/www/html
|
||||
docker exec ckb-laravel-app chmod -R 775 /var/www/html/storage
|
||||
docker exec ckb-laravel-app chmod -R 775 /var/www/html/bootstrap/cache
|
||||
```
|
||||
|
||||
## Security Considerations
|
||||
|
||||
1. **Firewall**: Ensure only necessary ports are open
|
||||
2. **SSL**: Certificate auto-renewal is configured
|
||||
3. **Rate Limiting**: Configured for login and API endpoints
|
||||
4. **Security Headers**: HSTS, XSS protection, etc.
|
||||
5. **File Permissions**: Proper Laravel file permissions
|
||||
6. **Database**: Strong passwords and limited access
|
||||
|
||||
## Backup Strategy
|
||||
|
||||
### Database Backup
|
||||
|
||||
```bash
|
||||
# Create backup
|
||||
docker exec ckb-mariadb mysqldump -u root -p ckb_production > backup.sql
|
||||
|
||||
# Restore backup
|
||||
docker exec -i ckb-mariadb mysql -u root -p ckb_production < backup.sql
|
||||
```
|
||||
|
||||
### Application Backup
|
||||
|
||||
```bash
|
||||
# Backup application files
|
||||
tar -czf ckb-backup-$(date +%Y%m%d).tar.gz /var/www/ckb/
|
||||
|
||||
# Backup volumes
|
||||
docker run --rm -v ckb_mysql_data:/data -v $(pwd):/backup alpine tar czf /backup/mysql-backup.tar.gz -C /data .
|
||||
```
|
||||
|
||||
## Performance Optimization
|
||||
|
||||
1. **Nginx**: Gzip compression enabled
|
||||
2. **Laravel**: Production optimizations
|
||||
3. **Database**: Proper indexing
|
||||
4. **Redis**: Caching and session storage
|
||||
5. **Static Files**: Long-term caching headers
|
||||
|
||||
## Support
|
||||
|
||||
For issues or questions:
|
||||
|
||||
1. Check logs first
|
||||
2. Verify configuration files
|
||||
3. Test connectivity step by step
|
||||
4. Check system resources
|
||||
5. Review security settings
|
||||
404
DOCKER-README.md
404
DOCKER-README.md
@@ -1,404 +0,0 @@
|
||||
# Docker Setup untuk CKB Laravel Application
|
||||
|
||||
Dokumentasi ini menjelaskan cara menjalankan aplikasi CKB menggunakan Docker untuk environment local development dan staging/production.
|
||||
|
||||
## Struktur File Docker
|
||||
|
||||
```
|
||||
├── Dockerfile # Production/Staging Docker image
|
||||
├── Dockerfile.dev # Development Docker image
|
||||
├── docker-compose.yml # Local development setup
|
||||
├── docker-compose.prod.yml # Production/Staging setup
|
||||
├── .dockerignore # Files to exclude from build
|
||||
└── docker/
|
||||
├── env.example # Environment variables template
|
||||
├── nginx.conf # Production Nginx config
|
||||
├── nginx.dev.conf # Development Nginx config
|
||||
├── supervisord.conf # Production supervisor config
|
||||
├── supervisord.dev.conf # Development supervisor config
|
||||
├── xdebug.ini # Xdebug configuration
|
||||
├── php.ini # PHP configuration
|
||||
└── mysql.cnf # MySQL configuration
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Docker Engine 20.10+
|
||||
- Docker Compose 2.0+
|
||||
- Git
|
||||
|
||||
## Setup untuk Local Development
|
||||
|
||||
### 1. Quick Setup (Recommended)
|
||||
|
||||
Untuk setup cepat dengan auto-import database:
|
||||
|
||||
```bash
|
||||
# Clone repository
|
||||
git clone <your-repo-url>
|
||||
cd CKB
|
||||
|
||||
# Pastikan file ckb.sql ada di root project
|
||||
ls ckb.sql
|
||||
|
||||
# Jalankan quick setup
|
||||
./docker-quick-setup.sh dev
|
||||
```
|
||||
|
||||
Script ini akan otomatis:
|
||||
|
||||
- Setup environment file
|
||||
- Start semua containers
|
||||
- Import database dari ckb.sql
|
||||
- Generate application key
|
||||
- Setup Laravel application
|
||||
|
||||
### 2. Manual Setup
|
||||
|
||||
Jika Anda ingin setup manual:
|
||||
|
||||
```bash
|
||||
# Setup local environment
|
||||
./docker-setup-env.sh local
|
||||
|
||||
# Start containers
|
||||
docker-compose up -d --build
|
||||
|
||||
# Import database
|
||||
./docker-import-db.sh dev
|
||||
|
||||
# Generate Laravel application key
|
||||
docker-compose exec app php artisan key:generate
|
||||
```
|
||||
|
||||
### 2. Menjalankan Development Environment
|
||||
|
||||
```bash
|
||||
# Build dan jalankan containers
|
||||
docker-compose up -d --build
|
||||
|
||||
# Atau tanpa rebuild
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
### 3. Akses Aplikasi
|
||||
|
||||
- **Web Application**: http://localhost:8000
|
||||
- **Database (phpMyAdmin)**: http://localhost:8080
|
||||
- **Mail Testing (MailHog)**: http://localhost:8025
|
||||
- **MySQL Direct**: localhost:3306
|
||||
- **Redis**: localhost:6379
|
||||
|
||||
### 4. Menjalankan Laravel Commands
|
||||
|
||||
```bash
|
||||
# Masuk ke container aplikasi
|
||||
docker-compose exec app bash
|
||||
|
||||
# Atau jalankan command langsung
|
||||
docker-compose exec app php artisan migrate
|
||||
docker-compose exec app php artisan db:seed
|
||||
docker-compose exec app php artisan cache:clear
|
||||
```
|
||||
|
||||
### 5. Development dengan Hot Reload
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
docker-compose exec app npm install
|
||||
|
||||
# Jalankan webpack dev server
|
||||
docker-compose exec app npm run hot
|
||||
```
|
||||
|
||||
## Setup untuk Staging/Production
|
||||
|
||||
### 1. Persiapan Environment
|
||||
|
||||
```bash
|
||||
# Copy dan edit environment file production
|
||||
cp docker/env.example .env.production
|
||||
|
||||
# Edit file .env.production sesuai kebutuhan production
|
||||
vim .env.production
|
||||
```
|
||||
|
||||
Contoh konfigurasi production:
|
||||
|
||||
```env
|
||||
APP_ENV=production
|
||||
APP_DEBUG=false
|
||||
APP_URL=https://your-domain.com
|
||||
|
||||
DB_HOST=db
|
||||
DB_DATABASE=ckb_production
|
||||
DB_USERNAME=your_db_user
|
||||
DB_PASSWORD=your_secure_password
|
||||
DB_ROOT_PASSWORD=your_root_password
|
||||
|
||||
REDIS_PASSWORD=your_redis_password
|
||||
```
|
||||
|
||||
### 2. Menjalankan Production Environment
|
||||
|
||||
```bash
|
||||
# Build dan jalankan dengan konfigurasi production
|
||||
docker-compose -f docker-compose.prod.yml up -d --build
|
||||
|
||||
# Atau menggunakan environment file spesifik
|
||||
docker-compose -f docker-compose.prod.yml --env-file .env.production up -d --build
|
||||
```
|
||||
|
||||
### 3. Database Migration dan Seeding
|
||||
|
||||
```bash
|
||||
# Jalankan migrations
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan migrate --force
|
||||
|
||||
# Jalankan seeders (jika diperlukan)
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan db:seed --force
|
||||
|
||||
# Optimize aplikasi untuk production
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan config:cache
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan route:cache
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan view:cache
|
||||
```
|
||||
|
||||
## Monitoring dan Debugging
|
||||
|
||||
### 1. Melihat Logs
|
||||
|
||||
```bash
|
||||
# Semua services
|
||||
docker-compose logs -f
|
||||
|
||||
# Service specific
|
||||
docker-compose logs -f app
|
||||
docker-compose logs -f db
|
||||
docker-compose logs -f redis
|
||||
|
||||
# Production
|
||||
docker-compose -f docker-compose.prod.yml logs -f
|
||||
```
|
||||
|
||||
### 2. Debugging dengan Xdebug (Development)
|
||||
|
||||
Xdebug sudah dikonfigurasi untuk development environment:
|
||||
|
||||
- Port: 9003
|
||||
- IDE Key: PHPSTORM
|
||||
- Host: host.docker.internal
|
||||
|
||||
### 3. Monitoring Resources
|
||||
|
||||
```bash
|
||||
# Lihat resource usage
|
||||
docker stats
|
||||
|
||||
# Lihat containers yang berjalan
|
||||
docker-compose ps
|
||||
```
|
||||
|
||||
## Database Management
|
||||
|
||||
### 1. Import Database dari Backup
|
||||
|
||||
Untuk mengimport database dari file backup ckb.sql:
|
||||
|
||||
```bash
|
||||
# Import ke development environment
|
||||
./docker-import-db.sh dev
|
||||
|
||||
# Import ke production environment
|
||||
./docker-import-db.sh prod
|
||||
|
||||
# Import file SQL khusus
|
||||
./docker-import-db.sh dev my-backup.sql
|
||||
```
|
||||
|
||||
Script import akan otomatis:
|
||||
|
||||
- Backup database yang sudah ada (safety)
|
||||
- Drop dan recreate database
|
||||
- Import data dari file SQL
|
||||
- Jalankan migrations jika diperlukan
|
||||
- Clear cache Laravel
|
||||
|
||||
### 2. Backup Database
|
||||
|
||||
```bash
|
||||
# Backup database development
|
||||
docker-compose exec db mysqldump -u root -proot ckb_db > backup_$(date +%Y%m%d).sql
|
||||
|
||||
# Backup database production
|
||||
docker-compose -f docker-compose.prod.yml exec db mysqldump -u root -p ckb_production > backup_prod_$(date +%Y%m%d).sql
|
||||
```
|
||||
|
||||
### 3. Manual Restore Database
|
||||
|
||||
```bash
|
||||
# Restore database development
|
||||
docker-compose exec -T db mysql -u root -proot ckb_db < backup.sql
|
||||
|
||||
# Restore database production
|
||||
docker-compose -f docker-compose.prod.yml exec -T db mysql -u root -p ckb_production < backup.sql
|
||||
```
|
||||
|
||||
### 4. Auto Import saat Pertama Kali Setup
|
||||
|
||||
File `ckb.sql` di root project akan otomatis diimport saat pertama kali menjalankan containers baru. Ini terjadi karena MySQL menggunakan `/docker-entrypoint-initdb.d/` untuk auto-import.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### 1. Docker Build Issues
|
||||
|
||||
Jika mengalami error saat build (seperti PHP extension compilation errors):
|
||||
|
||||
```bash
|
||||
# Clean rebuild dengan script otomatis
|
||||
./docker-rebuild.sh dev
|
||||
|
||||
# Atau manual cleanup dan rebuild
|
||||
docker-compose down
|
||||
docker system prune -a -f
|
||||
docker-compose build --no-cache --pull
|
||||
```
|
||||
|
||||
**Common Build Errors:**
|
||||
|
||||
- **curl extension error**: Fixed dengan menambah `libcurl4-openssl-dev` dan `pkg-config`
|
||||
- **gd extension error**: Pastikan `libfreetype6-dev` dan `libjpeg62-turbo-dev` terinstall
|
||||
- **Out of space**: Jalankan `docker system prune -a -f` untuk cleanup
|
||||
|
||||
### 2. Permission Issues
|
||||
|
||||
**Laravel Storage Permission Errors** (seperti "laravel.log could not be opened"):
|
||||
|
||||
```bash
|
||||
# Quick fix dengan script otomatis
|
||||
./docker-fix-permissions.sh dev
|
||||
|
||||
# Atau manual fix
|
||||
docker-compose exec app chown -R www-data:www-data /var/www/html/storage
|
||||
docker-compose exec app chmod -R 775 /var/www/html/storage
|
||||
docker-compose exec app mkdir -p /var/www/html/storage/logs
|
||||
```
|
||||
|
||||
**Host Permission Issues:**
|
||||
|
||||
```bash
|
||||
# Fix permission di host system
|
||||
sudo chown -R $(id -u):$(id -g) storage/
|
||||
sudo chown -R $(id -u):$(id -g) bootstrap/cache/
|
||||
chmod -R 775 storage/
|
||||
chmod -R 775 bootstrap/cache/
|
||||
```
|
||||
|
||||
### 3. Reset Containers
|
||||
|
||||
```bash
|
||||
# Stop dan remove containers
|
||||
docker-compose down
|
||||
|
||||
# Remove volumes (HATI-HATI: akan menghapus data database)
|
||||
docker-compose down -v
|
||||
|
||||
# Rebuild dari awal
|
||||
docker-compose up -d --build --force-recreate
|
||||
```
|
||||
|
||||
### 4. Cache Issues
|
||||
|
||||
```bash
|
||||
# Clear semua cache Laravel
|
||||
docker-compose exec app php artisan optimize:clear
|
||||
|
||||
# Clear Docker build cache
|
||||
docker system prune -f
|
||||
|
||||
# Clean rebuild everything
|
||||
./docker-rebuild.sh dev
|
||||
```
|
||||
|
||||
### 5. Database Import Issues
|
||||
|
||||
```bash
|
||||
# Jika auto-import gagal
|
||||
./docker-import-db.sh dev
|
||||
|
||||
# Jika database corrupt
|
||||
docker-compose down -v
|
||||
docker-compose up -d
|
||||
./docker-import-db.sh dev
|
||||
```
|
||||
|
||||
### 6. Redis Connection Issues
|
||||
|
||||
Jika mengalami error "Class Redis not found":
|
||||
|
||||
```bash
|
||||
# Test Redis functionality
|
||||
./docker-test-redis.sh dev
|
||||
|
||||
# Rebuild containers dengan Redis extension
|
||||
./docker-rebuild.sh dev
|
||||
|
||||
# Manual fix: Clear cache dan config
|
||||
docker-compose exec app php artisan config:clear
|
||||
docker-compose exec app php artisan cache:clear
|
||||
```
|
||||
|
||||
**Common Redis Errors:**
|
||||
|
||||
- **Class Redis not found**: Fixed dengan install `pecl install redis`
|
||||
- **Connection refused**: Pastikan Redis container berjalan
|
||||
- **Config not loaded**: Jalankan `php artisan config:clear`
|
||||
|
||||
## Security Notes untuk Production
|
||||
|
||||
1. **Environment Variables**: Jangan commit file `.env` ke repository
|
||||
2. **Database Passwords**: Gunakan password yang kuat
|
||||
3. **SSL/TLS**: Setup SSL certificate untuk HTTPS
|
||||
4. **Firewall**: Konfigurasi firewall untuk membatasi akses port
|
||||
5. **Updates**: Regular update Docker images dan dependencies
|
||||
|
||||
## Performance Optimization
|
||||
|
||||
### 1. Production Optimizations
|
||||
|
||||
```bash
|
||||
# Laravel optimizations
|
||||
docker-compose exec app php artisan config:cache
|
||||
docker-compose exec app php artisan route:cache
|
||||
docker-compose exec app php artisan view:cache
|
||||
docker-compose exec app composer install --optimize-autoloader --no-dev
|
||||
```
|
||||
|
||||
### 2. Docker Optimizations
|
||||
|
||||
- Gunakan multi-stage builds untuk image yang lebih kecil
|
||||
- Leverage Docker layer caching
|
||||
- Optimize .dockerignore untuk build speed
|
||||
|
||||
## Backup Strategy
|
||||
|
||||
### 1. Automated Backups
|
||||
|
||||
Buat script backup otomatis:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# backup.sh
|
||||
DATE=$(date +%Y%m%d_%H%M%S)
|
||||
docker-compose exec db mysqldump -u root -p${DB_ROOT_PASSWORD} ckb_production > "backup_${DATE}.sql"
|
||||
tar -czf "backup_${DATE}.tar.gz" backup_${DATE}.sql storage/
|
||||
```
|
||||
|
||||
### 2. Volume Backups
|
||||
|
||||
```bash
|
||||
# Backup Docker volumes
|
||||
docker run --rm -v ckb_mysql_data:/data -v $(pwd):/backup alpine tar czf /backup/mysql_backup.tar.gz /data
|
||||
```
|
||||
|
||||
Untuk pertanyaan lebih lanjut atau issues, silakan buat issue di repository ini.
|
||||
@@ -1,276 +0,0 @@
|
||||
# Environment Setup Guide
|
||||
|
||||
Panduan lengkap untuk setup environment file CKB Laravel Application dengan file template terpisah untuk local dan production.
|
||||
|
||||
## 📂 File Structure
|
||||
|
||||
```
|
||||
docker/
|
||||
├── env.example.local # Template untuk local development
|
||||
├── env.example.production # Template untuk production
|
||||
└── (env.example) # File lama, dapat dihapus
|
||||
```
|
||||
|
||||
## 🔧 Quick Setup
|
||||
|
||||
### Local Development
|
||||
|
||||
```bash
|
||||
# Setup environment untuk local development
|
||||
./docker-setup-env.sh local
|
||||
|
||||
# Atau manual copy
|
||||
cp docker/env.example.local .env
|
||||
```
|
||||
|
||||
### Production Deployment
|
||||
|
||||
```bash
|
||||
# Setup environment untuk production
|
||||
./docker-setup-env.sh production
|
||||
|
||||
# IMPORTANT: Edit .env dan ganti semua CHANGE_THIS_* values!
|
||||
nano .env
|
||||
```
|
||||
|
||||
## 📋 Template Comparison
|
||||
|
||||
### 🏠 Local Development (`env.example.local`)
|
||||
|
||||
| Setting | Value | Description |
|
||||
| ------------------- | ----------------------- | ----------------------- |
|
||||
| `APP_ENV` | `local` | Development environment |
|
||||
| `APP_DEBUG` | `true` | Debug mode enabled |
|
||||
| `APP_URL` | `http://localhost:8000` | Local URL |
|
||||
| `LOG_LEVEL` | `debug` | Verbose logging |
|
||||
| `DB_DATABASE` | `ckb_db` | Development database |
|
||||
| `DB_USERNAME` | `root` | Simple credentials |
|
||||
| `DB_PASSWORD` | `root` | Simple credentials |
|
||||
| `REDIS_PASSWORD` | `null` | No password needed |
|
||||
| `MAIL_HOST` | `mailhog` | Local mail testing |
|
||||
| `QUEUE_CONNECTION` | `sync` | Synchronous queue |
|
||||
| `TELESCOPE_ENABLED` | `true` | Debugging tool enabled |
|
||||
|
||||
### 🚀 Production (`env.example.production`)
|
||||
|
||||
| Setting | Value | Description |
|
||||
| ------------------- | ---------------------------------- | ----------------------- |
|
||||
| `APP_ENV` | `production` | Production environment |
|
||||
| `APP_DEBUG` | `false` | Debug mode disabled |
|
||||
| `APP_URL` | `https://bengkel.digitaloasis.xyz` | Production domain |
|
||||
| `LOG_LEVEL` | `error` | Error-only logging |
|
||||
| `DB_DATABASE` | `ckb_production` | Production database |
|
||||
| `DB_USERNAME` | `ckb_user` | Secure username |
|
||||
| `DB_PASSWORD` | `CHANGE_THIS_*` | **Must be changed!** |
|
||||
| `REDIS_PASSWORD` | `CHANGE_THIS_*` | **Must be changed!** |
|
||||
| `MAIL_HOST` | `smtp.gmail.com` | Real SMTP server |
|
||||
| `QUEUE_CONNECTION` | `redis` | Redis-based queue |
|
||||
| `TELESCOPE_ENABLED` | `false` | Debugging tool disabled |
|
||||
|
||||
## 🔐 Security Configuration for Production
|
||||
|
||||
### Required Changes
|
||||
|
||||
**MUST CHANGE** these values in production `.env`:
|
||||
|
||||
```env
|
||||
# Strong database passwords
|
||||
DB_PASSWORD=your_super_secure_password_here
|
||||
DB_ROOT_PASSWORD=your_root_password_here
|
||||
|
||||
# Redis security
|
||||
REDIS_PASSWORD=your_redis_password_here
|
||||
|
||||
# Mail configuration
|
||||
MAIL_USERNAME=your-email@domain.com
|
||||
MAIL_PASSWORD=your-app-specific-password
|
||||
```
|
||||
|
||||
### Optional but Recommended
|
||||
|
||||
```env
|
||||
# AWS S3 for file storage
|
||||
AWS_ACCESS_KEY_ID=your-aws-key
|
||||
AWS_SECRET_ACCESS_KEY=your-aws-secret
|
||||
|
||||
# Real-time features
|
||||
PUSHER_APP_ID=your-pusher-app-id
|
||||
PUSHER_APP_KEY=your-pusher-key
|
||||
PUSHER_APP_SECRET=your-pusher-secret
|
||||
```
|
||||
|
||||
## 🛠️ Environment Helper Script
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
# Setup local environment
|
||||
./docker-setup-env.sh local
|
||||
|
||||
# Setup production environment
|
||||
./docker-setup-env.sh production
|
||||
|
||||
# Show current environment info
|
||||
./docker-setup-env.sh
|
||||
```
|
||||
|
||||
### Features
|
||||
|
||||
- ✅ **Auto-backup** existing `.env` before changes
|
||||
- ✅ **Environment validation** checks required variables
|
||||
- ✅ **Security warnings** for production misconfiguration
|
||||
- ✅ **Configuration summary** shows current settings
|
||||
- ✅ **Next steps guidance** for deployment
|
||||
|
||||
## 📊 Environment Comparison
|
||||
|
||||
### Local Development Features
|
||||
|
||||
- 🐛 **Debug Mode**: Full error reporting and debugging tools
|
||||
- 📧 **MailHog**: Local email testing server
|
||||
- 🗄️ **Simple DB**: Basic MySQL credentials
|
||||
- 🔓 **No SSL**: HTTP-only for speed
|
||||
- 🧪 **Development Tools**: Telescope, Debugbar enabled
|
||||
- ⚡ **Sync Queue**: Immediate processing for testing
|
||||
|
||||
### Production Features
|
||||
|
||||
- 🔒 **Security First**: Strong passwords and encryption
|
||||
- 📧 **Real SMTP**: Professional email delivery
|
||||
- 🗄️ **Secure DB**: Production-grade credentials
|
||||
- 🔐 **SSL/HTTPS**: Let's Encrypt certificates
|
||||
- 📊 **Monitoring**: Error-only logging
|
||||
- 🚀 **Redis Queue**: Background job processing
|
||||
|
||||
## 🚨 Common Issues & Solutions
|
||||
|
||||
### 1. "CHANGE*THIS*\*" Values in Production
|
||||
|
||||
**Problem**: Forgot to change template values
|
||||
|
||||
```bash
|
||||
# Check for remaining template values
|
||||
grep "CHANGE_THIS" .env
|
||||
```
|
||||
|
||||
**Solution**:
|
||||
|
||||
```bash
|
||||
# Use the helper script to check
|
||||
./docker-setup-env.sh
|
||||
# It will warn about CHANGE_THIS_* values
|
||||
```
|
||||
|
||||
### 2. Wrong Environment File
|
||||
|
||||
**Problem**: Using local config in production
|
||||
|
||||
```bash
|
||||
# Check current environment
|
||||
grep "APP_ENV=" .env
|
||||
```
|
||||
|
||||
**Solution**:
|
||||
|
||||
```bash
|
||||
# Recreate with correct template
|
||||
./docker-setup-env.sh production
|
||||
```
|
||||
|
||||
### 3. Missing Environment Variables
|
||||
|
||||
**Problem**: Laravel errors about missing config
|
||||
|
||||
```bash
|
||||
# Validate current .env
|
||||
./docker-setup-env.sh validate
|
||||
```
|
||||
|
||||
**Solution**: Check required variables list and add missing ones
|
||||
|
||||
## 📝 Environment Variables Reference
|
||||
|
||||
### Core Application
|
||||
|
||||
```env
|
||||
APP_NAME="CKB Bengkel System"
|
||||
APP_ENV=production|local
|
||||
APP_KEY=base64:...
|
||||
APP_DEBUG=true|false
|
||||
APP_URL=https://domain.com
|
||||
```
|
||||
|
||||
### Database
|
||||
|
||||
```env
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=db
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=ckb_production|ckb_db
|
||||
DB_USERNAME=username
|
||||
DB_PASSWORD=password
|
||||
DB_ROOT_PASSWORD=root_password
|
||||
```
|
||||
|
||||
### Cache & Session
|
||||
|
||||
```env
|
||||
REDIS_HOST=redis
|
||||
REDIS_PASSWORD=password|null
|
||||
REDIS_PORT=6379
|
||||
CACHE_DRIVER=redis
|
||||
SESSION_DRIVER=redis
|
||||
QUEUE_CONNECTION=redis|sync
|
||||
```
|
||||
|
||||
### Mail Configuration
|
||||
|
||||
```env
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=smtp.domain.com
|
||||
MAIL_PORT=587
|
||||
MAIL_USERNAME=email@domain.com
|
||||
MAIL_PASSWORD=password
|
||||
MAIL_ENCRYPTION=tls
|
||||
MAIL_FROM_ADDRESS=noreply@domain.com
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
```
|
||||
|
||||
### Security
|
||||
|
||||
```env
|
||||
TRUSTED_PROXIES=*
|
||||
SESSION_SECURE_COOKIE=true
|
||||
SESSION_SAME_SITE=strict
|
||||
```
|
||||
|
||||
## 🔄 Migration Guide
|
||||
|
||||
### From Old Single Template
|
||||
|
||||
If you're migrating from the old `docker/env.example`:
|
||||
|
||||
```bash
|
||||
# Backup current .env
|
||||
cp .env .env.backup
|
||||
|
||||
# Choose appropriate template
|
||||
./docker-setup-env.sh local # for development
|
||||
./docker-setup-env.sh production # for production
|
||||
|
||||
# Compare and migrate custom settings
|
||||
diff .env.backup .env
|
||||
```
|
||||
|
||||
## 📞 Support
|
||||
|
||||
For environment setup issues:
|
||||
|
||||
- **Documentation**: This file
|
||||
- **Helper Script**: `./docker-setup-env.sh`
|
||||
- **Validation**: Built-in security checks
|
||||
- **Backup**: Automatic .env backup before changes
|
||||
|
||||
---
|
||||
|
||||
**💡 Pro Tip**: Always use the helper script `./docker-setup-env.sh` instead of manual copying to ensure proper configuration and security checks!
|
||||
@@ -1,225 +0,0 @@
|
||||
# 🔧 Laravel Permission Fix Guide untuk Docker
|
||||
|
||||
## 🎯 Masalah yang Diselesaikan
|
||||
|
||||
**Error yang umum terjadi:**
|
||||
```
|
||||
The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied
|
||||
```
|
||||
|
||||
**Root Cause:**
|
||||
- Laravel tidak bisa menulis ke direktori `storage/logs/`
|
||||
- Permission dan ownership direktori storage tidak sesuai
|
||||
- Direktori storage yang diperlukan belum dibuat
|
||||
|
||||
## 🚀 Solusi Quick Fix
|
||||
|
||||
### **Option 1: Automatic Fix (Recommended)**
|
||||
```bash
|
||||
# Fix semua permission issues otomatis
|
||||
./docker-fix-permissions.sh dev
|
||||
|
||||
# Untuk production
|
||||
./docker-fix-permissions.sh prod
|
||||
```
|
||||
|
||||
### **Option 2: Manual Fix**
|
||||
```bash
|
||||
# Buat direktori yang diperlukan
|
||||
docker-compose exec app mkdir -p /var/www/html/storage/logs
|
||||
docker-compose exec app mkdir -p /var/www/html/storage/framework/cache
|
||||
docker-compose exec app mkdir -p /var/www/html/storage/framework/sessions
|
||||
docker-compose exec app mkdir -p /var/www/html/storage/framework/views
|
||||
|
||||
# Fix ownership
|
||||
docker-compose exec app chown -R www-data:www-data /var/www/html/storage
|
||||
docker-compose exec app chown -R www-data:www-data /var/www/html/bootstrap/cache
|
||||
|
||||
# Fix permissions
|
||||
docker-compose exec app chmod -R 775 /var/www/html/storage
|
||||
docker-compose exec app chmod -R 775 /var/www/html/bootstrap/cache
|
||||
```
|
||||
|
||||
### **Option 3: Rebuild Containers (Jika masalah persisten)**
|
||||
```bash
|
||||
# Clean rebuild containers
|
||||
./docker-rebuild.sh dev
|
||||
```
|
||||
|
||||
## 🔍 Verifikasi Fix Berhasil
|
||||
|
||||
### **1. Cek Permission Direktori**
|
||||
```bash
|
||||
# Lihat permission storage
|
||||
docker-compose exec app ls -la /var/www/html/storage/
|
||||
|
||||
# Cek ownership logs
|
||||
docker-compose exec app ls -la /var/www/html/storage/logs/
|
||||
```
|
||||
|
||||
**Output yang benar:**
|
||||
```
|
||||
drwxrwxr-x 5 www-data www-data 4096 Jun 10 15:01 storage
|
||||
drwxrwxr-x 2 www-data www-data 4096 Jun 10 15:01 logs
|
||||
```
|
||||
|
||||
### **2. Test Laravel Logging**
|
||||
```bash
|
||||
# Test write ke log
|
||||
docker-compose exec app php -r "file_put_contents('/var/www/html/storage/logs/laravel.log', 'Test log: ' . date('Y-m-d H:i:s') . PHP_EOL, FILE_APPEND);"
|
||||
|
||||
# Cek isi log
|
||||
docker-compose exec app tail -5 /var/www/html/storage/logs/laravel.log
|
||||
```
|
||||
|
||||
### **3. Test Laravel Artisan**
|
||||
```bash
|
||||
# Test cache clear
|
||||
docker-compose exec app php artisan cache:clear
|
||||
|
||||
# Test storage link
|
||||
docker-compose exec app php artisan storage:link
|
||||
|
||||
# Test route cache
|
||||
docker-compose exec app php artisan route:cache
|
||||
```
|
||||
|
||||
## 🛡️ Prevention - Dockerfile Updates
|
||||
|
||||
**Dockerfile sudah diperbarui untuk mencegah masalah ini:**
|
||||
|
||||
```dockerfile
|
||||
# Create necessary directories and set permissions
|
||||
RUN mkdir -p /var/www/html/storage/logs \
|
||||
&& mkdir -p /var/www/html/storage/framework/cache \
|
||||
&& mkdir -p /var/www/html/storage/framework/sessions \
|
||||
&& mkdir -p /var/www/html/storage/framework/views \
|
||||
&& mkdir -p /var/www/html/storage/app \
|
||||
&& mkdir -p /var/www/html/bootstrap/cache \
|
||||
&& chown -R www-data:www-data /var/www/html \
|
||||
&& chmod -R 775 /var/www/html/storage \
|
||||
&& chmod -R 775 /var/www/html/bootstrap/cache
|
||||
```
|
||||
|
||||
## 🔧 Script Features
|
||||
|
||||
### **`docker-fix-permissions.sh`**
|
||||
- ✅ **Auto-detect environment** (dev/prod)
|
||||
- ✅ **Create missing directories**
|
||||
- ✅ **Fix ownership** (www-data:www-data)
|
||||
- ✅ **Set proper permissions** (775 untuk storage)
|
||||
- ✅ **Test logging functionality**
|
||||
- ✅ **Create storage link**
|
||||
- ✅ **Show before/after permissions**
|
||||
|
||||
### **Usage Examples**
|
||||
```bash
|
||||
# Fix development environment
|
||||
./docker-fix-permissions.sh dev
|
||||
|
||||
# Fix production environment
|
||||
./docker-fix-permissions.sh prod
|
||||
|
||||
# Show help
|
||||
./docker-fix-permissions.sh --help
|
||||
```
|
||||
|
||||
## 🚨 Common Issues & Solutions
|
||||
|
||||
### **1. Permission Denied setelah Fix**
|
||||
**Cause:** Volume mounting conflict
|
||||
**Solution:**
|
||||
```bash
|
||||
# Cek volume mounts
|
||||
docker-compose config
|
||||
|
||||
# Restart containers
|
||||
docker-compose restart app
|
||||
|
||||
# Re-run permission fix
|
||||
./docker-fix-permissions.sh dev
|
||||
```
|
||||
|
||||
### **2. Ownership reverted setelah restart**
|
||||
**Cause:** Volume mounting dari host
|
||||
**Solution:**
|
||||
```bash
|
||||
# Fix di host system juga
|
||||
sudo chown -R $(id -u):$(id -g) storage/
|
||||
chmod -R 775 storage/
|
||||
|
||||
# Atau gunakan named volumes di docker-compose
|
||||
```
|
||||
|
||||
### **3. Log file tetap tidak bisa ditulis**
|
||||
**Cause:** Log file sudah ada dengan permission salah
|
||||
**Solution:**
|
||||
```bash
|
||||
# Hapus log file lama
|
||||
docker-compose exec app rm -f /var/www/html/storage/logs/laravel.log
|
||||
|
||||
# Re-run permission fix
|
||||
./docker-fix-permissions.sh dev
|
||||
```
|
||||
|
||||
### **4. Selinux/AppArmor blocking**
|
||||
**Cause:** Security policies
|
||||
**Solution:**
|
||||
```bash
|
||||
# Disable selinux temporarily (CentOS/RHEL)
|
||||
sudo setenforce 0
|
||||
|
||||
# Check AppArmor status (Ubuntu)
|
||||
sudo aa-status
|
||||
```
|
||||
|
||||
## 📁 Directory Structure yang Benar
|
||||
|
||||
Setelah fix, struktur direktori storage harus seperti ini:
|
||||
|
||||
```
|
||||
storage/
|
||||
├── app/
|
||||
│ ├── public/
|
||||
│ └── .gitkeep
|
||||
├── framework/
|
||||
│ ├── cache/
|
||||
│ ├── sessions/
|
||||
│ ├── testing/
|
||||
│ └── views/
|
||||
└── logs/
|
||||
├── laravel.log
|
||||
└── .gitkeep
|
||||
```
|
||||
|
||||
## 🎯 Best Practices
|
||||
|
||||
1. **Always use scripts**: Gunakan `docker-fix-permissions.sh` untuk consistency
|
||||
2. **Regular checks**: Monitor permission setelah update containers
|
||||
3. **Volume strategy**: Gunakan named volumes untuk persistent storage
|
||||
4. **Backup first**: Backup data sebelum fix permission
|
||||
5. **Test thoroughly**: Verify semua Laravel functionality setelah fix
|
||||
|
||||
## 📞 Troubleshooting Commands
|
||||
|
||||
```bash
|
||||
# Debug permission issues
|
||||
docker-compose exec app ls -laR /var/www/html/storage/
|
||||
|
||||
# Check Laravel configuration
|
||||
docker-compose exec app php artisan config:show logging
|
||||
|
||||
# Monitor Laravel logs
|
||||
docker-compose exec app tail -f /var/www/html/storage/logs/laravel.log
|
||||
|
||||
# Test file writing
|
||||
docker-compose exec app touch /var/www/html/storage/test.txt
|
||||
|
||||
# Check container user
|
||||
docker-compose exec app whoami
|
||||
docker-compose exec app id
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**✅ Dengan mengikuti panduan ini, masalah Laravel permission di Docker container akan teratasi.**
|
||||
@@ -1,360 +0,0 @@
|
||||
# CKB Production Deployment Guide
|
||||
|
||||
Panduan deployment aplikasi CKB Laravel ke production server dengan domain `bengkel.digitaloasis.xyz`.
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
### 1. Deploy ke Production
|
||||
|
||||
```bash
|
||||
# Full deployment (recommended untuk pertama kali)
|
||||
./docker-deploy-prod.sh deploy
|
||||
|
||||
# Hanya build containers
|
||||
./docker-deploy-prod.sh build
|
||||
|
||||
# Setup SSL certificate
|
||||
./docker-deploy-prod.sh ssl
|
||||
|
||||
# Check deployment status
|
||||
./docker-deploy-prod.sh status
|
||||
```
|
||||
|
||||
### 2. Akses Aplikasi
|
||||
|
||||
- **Domain**: https://bengkel.digitaloasis.xyz
|
||||
- **Health Check**: https://bengkel.digitaloasis.xyz/health
|
||||
|
||||
## 📋 Prerequisites
|
||||
|
||||
### Server Requirements
|
||||
|
||||
- **OS**: Ubuntu 20.04+ atau CentOS 7+
|
||||
- **Memory**: Minimum 2GB RAM (4GB recommended)
|
||||
- **Storage**: Minimum 20GB SSD
|
||||
- **Docker**: Version 20.10+
|
||||
- **Docker Compose**: Version 2.0+
|
||||
|
||||
### Domain Setup
|
||||
|
||||
1. **DNS Configuration**:
|
||||
|
||||
```
|
||||
A Record: bengkel.digitaloasis.xyz → [Server IP]
|
||||
CNAME: www.bengkel.digitaloasis.xyz → bengkel.digitaloasis.xyz
|
||||
```
|
||||
|
||||
2. **Firewall Configuration**:
|
||||
|
||||
```bash
|
||||
# Allow HTTP/HTTPS traffic
|
||||
sudo ufw allow 80/tcp
|
||||
sudo ufw allow 443/tcp
|
||||
|
||||
# Allow SSH (if needed)
|
||||
sudo ufw allow 22/tcp
|
||||
```
|
||||
|
||||
## 🛡️ Security Configuration
|
||||
|
||||
### 1. Environment Variables
|
||||
|
||||
Edit `.env` file untuk production:
|
||||
|
||||
```env
|
||||
# Application
|
||||
APP_ENV=production
|
||||
APP_DEBUG=false
|
||||
APP_URL=https://bengkel.digitaloasis.xyz
|
||||
APP_KEY=base64:...
|
||||
|
||||
# Database (GANTI dengan credentials yang aman!)
|
||||
DB_HOST=db
|
||||
DB_DATABASE=ckb_production
|
||||
DB_USERNAME=ckb_user
|
||||
DB_PASSWORD=secure_password_here
|
||||
DB_ROOT_PASSWORD=secure_root_password_here
|
||||
|
||||
# Redis
|
||||
REDIS_HOST=redis
|
||||
REDIS_PASSWORD=secure_redis_password
|
||||
|
||||
# Mail
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=your-smtp-host
|
||||
MAIL_PORT=587
|
||||
MAIL_USERNAME=your-email@domain.com
|
||||
MAIL_PASSWORD=your-email-password
|
||||
MAIL_ENCRYPTION=tls
|
||||
|
||||
# Session & Cache
|
||||
SESSION_DRIVER=redis
|
||||
CACHE_DRIVER=redis
|
||||
QUEUE_CONNECTION=redis
|
||||
|
||||
# Trusted Proxies
|
||||
TRUSTED_PROXIES=*
|
||||
```
|
||||
|
||||
### 2. Database Security
|
||||
|
||||
```bash
|
||||
# Setelah deployment, jalankan MySQL secure installation
|
||||
docker-compose -f docker-compose.prod.yml exec db mysql_secure_installation
|
||||
```
|
||||
|
||||
## 🔧 Deployment Process
|
||||
|
||||
### Manual Step-by-Step
|
||||
|
||||
1. **Persiapan Server**:
|
||||
|
||||
```bash
|
||||
# Update system
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
|
||||
# Install Docker
|
||||
curl -fsSL https://get.docker.com -o get-docker.sh
|
||||
sudo sh get-docker.sh
|
||||
|
||||
# Install Docker Compose
|
||||
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||
sudo chmod +x /usr/local/bin/docker-compose
|
||||
```
|
||||
|
||||
2. **Clone Repository**:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/your-repo/ckb.git
|
||||
cd ckb
|
||||
```
|
||||
|
||||
3. **Setup Environment**:
|
||||
|
||||
```bash
|
||||
# For production environment
|
||||
./docker-setup-env.sh production
|
||||
|
||||
# Edit production settings (IMPORTANT!)
|
||||
nano .env
|
||||
# Change all CHANGE_THIS_* values with secure passwords
|
||||
```
|
||||
|
||||
4. **Deploy Application**:
|
||||
|
||||
```bash
|
||||
./docker-deploy-prod.sh deploy
|
||||
```
|
||||
|
||||
5. **Setup SSL Certificate**:
|
||||
```bash
|
||||
./docker-deploy-prod.sh ssl
|
||||
```
|
||||
|
||||
## 📊 Monitoring & Maintenance
|
||||
|
||||
### 1. Health Checks
|
||||
|
||||
```bash
|
||||
# Check application status
|
||||
./docker-deploy-prod.sh status
|
||||
|
||||
# Check specific service logs
|
||||
docker-compose -f docker-compose.prod.yml logs -f app
|
||||
docker-compose -f docker-compose.prod.yml logs -f nginx-proxy
|
||||
docker-compose -f docker-compose.prod.yml logs -f db
|
||||
```
|
||||
|
||||
### 2. Database Backup
|
||||
|
||||
```bash
|
||||
# Manual backup
|
||||
docker-compose -f docker-compose.prod.yml exec -T db mysqldump -u root -p"$DB_ROOT_PASSWORD" ckb_production > backup_$(date +%Y%m%d).sql
|
||||
|
||||
# Automated backup (add to crontab)
|
||||
0 2 * * * /path/to/ckb/docker-backup.sh
|
||||
```
|
||||
|
||||
### 3. SSL Certificate Renewal
|
||||
|
||||
Certificate akan otomatis renewal. Untuk manual renewal:
|
||||
|
||||
```bash
|
||||
# Test renewal
|
||||
docker-compose -f docker-compose.prod.yml run --rm certbot renew --dry-run
|
||||
|
||||
# Manual renewal
|
||||
./docker-ssl-renew.sh
|
||||
|
||||
# Setup auto-renewal (add to crontab)
|
||||
0 12 * * * /path/to/ckb/docker-ssl-renew.sh
|
||||
```
|
||||
|
||||
## 🔍 Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Application Not Loading**:
|
||||
|
||||
```bash
|
||||
# Check container status
|
||||
docker-compose -f docker-compose.prod.yml ps
|
||||
|
||||
# Check application logs
|
||||
docker-compose -f docker-compose.prod.yml logs app
|
||||
|
||||
# Restart application
|
||||
docker-compose -f docker-compose.prod.yml restart app
|
||||
```
|
||||
|
||||
2. **SSL Certificate Issues**:
|
||||
|
||||
```bash
|
||||
# Check certificate status
|
||||
openssl s_client -connect bengkel.digitaloasis.xyz:443 -servername bengkel.digitaloasis.xyz
|
||||
|
||||
# Re-setup SSL
|
||||
./docker-ssl-setup.sh
|
||||
```
|
||||
|
||||
3. **Database Connection Issues**:
|
||||
|
||||
```bash
|
||||
# Check database logs
|
||||
docker-compose -f docker-compose.prod.yml logs db
|
||||
|
||||
# Test database connection
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan tinker
|
||||
>>> DB::connection()->getPdo();
|
||||
```
|
||||
|
||||
4. **Permission Issues**:
|
||||
```bash
|
||||
# Fix Laravel permissions
|
||||
./docker-fix-permissions.sh prod
|
||||
```
|
||||
|
||||
### Performance Issues
|
||||
|
||||
```bash
|
||||
# Check resource usage
|
||||
docker stats
|
||||
|
||||
# Clean up Docker system
|
||||
docker system prune -a -f
|
||||
|
||||
# Optimize Laravel
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan optimize
|
||||
```
|
||||
|
||||
## 🚦 Load Testing
|
||||
|
||||
Before going live, test your application:
|
||||
|
||||
```bash
|
||||
# Install testing tools
|
||||
sudo apt install apache2-utils
|
||||
|
||||
# Basic load test
|
||||
ab -n 1000 -c 10 https://bengkel.digitaloasis.xyz/
|
||||
|
||||
# More comprehensive testing with siege
|
||||
sudo apt install siege
|
||||
siege -c 25 -t 60s https://bengkel.digitaloasis.xyz/
|
||||
```
|
||||
|
||||
## 📈 Performance Optimization
|
||||
|
||||
### 1. Laravel Optimizations
|
||||
|
||||
```bash
|
||||
# Run after each deployment
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan config:cache
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan route:cache
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan view:cache
|
||||
docker-compose -f docker-compose.prod.yml exec app composer install --optimize-autoloader --no-dev
|
||||
```
|
||||
|
||||
### 2. Database Optimization
|
||||
|
||||
```bash
|
||||
# MySQL tuning
|
||||
docker-compose -f docker-compose.prod.yml exec db mysql -u root -p -e "
|
||||
SET GLOBAL innodb_buffer_pool_size = 1073741824;
|
||||
SET GLOBAL query_cache_size = 67108864;
|
||||
SET GLOBAL query_cache_type = 1;
|
||||
"
|
||||
```
|
||||
|
||||
### 3. Nginx Optimization
|
||||
|
||||
Edit `docker/nginx-proxy.conf` untuk mengoptimalkan:
|
||||
|
||||
- Gzip compression
|
||||
- Browser caching
|
||||
- Connection pooling
|
||||
|
||||
## 🔄 Updates & Maintenance
|
||||
|
||||
### Application Updates
|
||||
|
||||
```bash
|
||||
# Pull latest code
|
||||
git pull origin main
|
||||
|
||||
# Backup before update
|
||||
./docker-deploy-prod.sh backup
|
||||
|
||||
# Deploy updates
|
||||
./docker-deploy-prod.sh deploy
|
||||
```
|
||||
|
||||
### Security Updates
|
||||
|
||||
```bash
|
||||
# Update base images
|
||||
docker-compose -f docker-compose.prod.yml pull
|
||||
|
||||
# Rebuild with latest security patches
|
||||
./docker-deploy-prod.sh build
|
||||
```
|
||||
|
||||
## 📞 Support & Contact
|
||||
|
||||
Untuk bantuan deployment atau issues:
|
||||
|
||||
- **Email**: admin@digitaloasis.xyz
|
||||
- **Documentation**: https://github.com/your-repo/ckb/docs
|
||||
- **Issues**: https://github.com/your-repo/ckb/issues
|
||||
|
||||
## 📄 File Structure
|
||||
|
||||
```
|
||||
ckb/
|
||||
├── docker/
|
||||
│ ├── nginx-proxy.conf # Main nginx configuration
|
||||
│ ├── nginx-temp.conf # Temporary config for SSL setup
|
||||
│ ├── env.example # Environment template
|
||||
│ └── ...
|
||||
├── docker-compose.prod.yml # Production compose file
|
||||
├── docker-deploy-prod.sh # Main deployment script
|
||||
├── docker-ssl-setup.sh # SSL certificate setup
|
||||
├── docker-ssl-renew.sh # SSL renewal script
|
||||
└── PRODUCTION-DEPLOYMENT.md # This file
|
||||
```
|
||||
|
||||
## ✅ Production Checklist
|
||||
|
||||
- [ ] Domain DNS configured
|
||||
- [ ] Firewall rules configured
|
||||
- [ ] .env file configured with production values
|
||||
- [ ] Database credentials changed from defaults
|
||||
- [ ] SSL certificate obtained and configured
|
||||
- [ ] Backup system configured
|
||||
- [ ] Monitoring setup
|
||||
- [ ] Load testing completed
|
||||
- [ ] Security audit completed
|
||||
|
||||
---
|
||||
|
||||
**🚨 Remember**: Always test in staging environment before deploying to production!
|
||||
@@ -1,277 +0,0 @@
|
||||
# 🔴 Redis Fix Guide untuk Laravel Docker
|
||||
|
||||
## 🎯 Masalah yang Diselesaikan
|
||||
|
||||
**Error yang dialami:**
|
||||
```
|
||||
Class "Redis" not found
|
||||
```
|
||||
|
||||
**Root Cause:**
|
||||
- PHP Redis extension tidak terinstall di container
|
||||
- Laravel dikonfigurasi untuk menggunakan Redis tetapi extension tidak tersedia
|
||||
- Container perlu rebuild untuk install Redis extension
|
||||
|
||||
## 🚀 Solusi yang Diimplementasi
|
||||
|
||||
### **1. Updated Dockerfiles**
|
||||
|
||||
**Production (Dockerfile):**
|
||||
```dockerfile
|
||||
# Install Redis extension
|
||||
RUN pecl install redis \
|
||||
&& docker-php-ext-enable redis
|
||||
```
|
||||
|
||||
**Development (Dockerfile.dev):**
|
||||
```dockerfile
|
||||
# Install Redis and Xdebug for development
|
||||
RUN pecl install redis xdebug \
|
||||
&& docker-php-ext-enable redis xdebug
|
||||
```
|
||||
|
||||
### **2. Fix Steps yang Dijalankan**
|
||||
|
||||
```bash
|
||||
# 1. Update Dockerfile dengan Redis extension
|
||||
# 2. Rebuild container
|
||||
docker-compose build --no-cache app
|
||||
|
||||
# 3. Restart container dengan image baru
|
||||
docker-compose up -d app
|
||||
|
||||
# 4. Verify Redis extension installed
|
||||
docker-compose exec app php -m | grep redis
|
||||
|
||||
# 5. Test Redis connection
|
||||
docker-compose exec app php -r "
|
||||
\$redis = new Redis();
|
||||
\$redis->connect('redis', 6379);
|
||||
echo 'Redis connected successfully';
|
||||
"
|
||||
|
||||
# 6. Clear Laravel cache
|
||||
docker-compose exec app php artisan config:clear
|
||||
docker-compose exec app php artisan cache:clear
|
||||
```
|
||||
|
||||
## ✅ Verifikasi Fix Berhasil
|
||||
|
||||
### **1. PHP Redis Extension**
|
||||
```bash
|
||||
# Cek extension terinstall
|
||||
docker-compose exec app php -m | grep redis
|
||||
# Output: redis
|
||||
```
|
||||
|
||||
### **2. Redis Connection Test**
|
||||
```bash
|
||||
# Test koneksi Redis
|
||||
./docker-test-redis.sh dev
|
||||
```
|
||||
|
||||
**Expected Output:**
|
||||
```
|
||||
[SUCCESS] PHP Redis extension is installed
|
||||
[SUCCESS] Redis server is responding
|
||||
[SUCCESS] PHP Redis connection working
|
||||
[SUCCESS] Laravel cache operations working
|
||||
```
|
||||
|
||||
### **3. Web Application**
|
||||
```bash
|
||||
# Test web response
|
||||
curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/
|
||||
# Output: 302 (redirect ke login page)
|
||||
```
|
||||
|
||||
### **4. Laravel Cache Operations**
|
||||
```bash
|
||||
# Test Laravel cache dengan Redis
|
||||
docker-compose exec app php artisan tinker --execute="
|
||||
Cache::put('test', 'redis-working', 60);
|
||||
echo Cache::get('test');
|
||||
"
|
||||
# Output: redis-working
|
||||
```
|
||||
|
||||
## 🛠️ Tools dan Scripts
|
||||
|
||||
### **`docker-test-redis.sh`**
|
||||
Comprehensive Redis testing script:
|
||||
- ✅ Test PHP Redis extension
|
||||
- ✅ Test Redis server connection
|
||||
- ✅ Test Laravel cache operations
|
||||
- ✅ Show Redis configuration
|
||||
- ✅ Show server information
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
# Test development environment
|
||||
./docker-test-redis.sh dev
|
||||
|
||||
# Test production environment
|
||||
./docker-test-redis.sh prod
|
||||
```
|
||||
|
||||
### **`docker-rebuild.sh`**
|
||||
Updated untuk include Redis testing:
|
||||
- ✅ Test Redis extension di build process
|
||||
- ✅ Verify Redis connection setelah rebuild
|
||||
- ✅ Comprehensive testing semua extensions
|
||||
|
||||
## 🔧 Laravel Configuration
|
||||
|
||||
### **Environment Variables (.env)**
|
||||
```env
|
||||
# Redis Configuration
|
||||
REDIS_HOST=redis
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
# Cache using Redis
|
||||
CACHE_DRIVER=redis
|
||||
|
||||
# Sessions using Redis
|
||||
SESSION_DRIVER=redis
|
||||
|
||||
# Queue using Redis
|
||||
QUEUE_CONNECTION=redis
|
||||
```
|
||||
|
||||
### **Config Files**
|
||||
Laravel otomatis membaca konfigurasi dari environment variables untuk:
|
||||
- `config/cache.php` - Cache driver
|
||||
- `config/session.php` - Session driver
|
||||
- `config/queue.php` - Queue driver
|
||||
- `config/database.php` - Redis connection
|
||||
|
||||
## 🚨 Common Issues & Solutions
|
||||
|
||||
### **1. Redis Extension Missing**
|
||||
**Symptoms:** `Class "Redis" not found`
|
||||
**Solution:**
|
||||
```bash
|
||||
# Rebuild containers
|
||||
./docker-rebuild.sh dev
|
||||
```
|
||||
|
||||
### **2. Redis Connection Failed**
|
||||
**Symptoms:** `Connection refused`
|
||||
**Solution:**
|
||||
```bash
|
||||
# Check Redis container
|
||||
docker-compose ps | grep redis
|
||||
|
||||
# Restart Redis
|
||||
docker-compose restart redis
|
||||
|
||||
# Test connection
|
||||
./docker-test-redis.sh dev
|
||||
```
|
||||
|
||||
### **3. Laravel Config Not Loading**
|
||||
**Symptoms:** Cache/session tidak menggunakan Redis
|
||||
**Solution:**
|
||||
```bash
|
||||
# Clear Laravel cache
|
||||
docker-compose exec app php artisan config:clear
|
||||
docker-compose exec app php artisan cache:clear
|
||||
docker-compose exec app php artisan view:clear
|
||||
```
|
||||
|
||||
### **4. Permission Issues with Redis**
|
||||
**Symptoms:** Cannot write to cache
|
||||
**Solution:**
|
||||
```bash
|
||||
# Fix permissions
|
||||
./docker-fix-permissions.sh dev
|
||||
|
||||
# Clear cache
|
||||
docker-compose exec app php artisan cache:clear
|
||||
```
|
||||
|
||||
## 📋 Best Practices
|
||||
|
||||
### **1. Container Management**
|
||||
- Always rebuild containers setelah update Dockerfile
|
||||
- Use scripts untuk consistent operations
|
||||
- Test functionality setelah changes
|
||||
|
||||
### **2. Development Workflow**
|
||||
```bash
|
||||
# Complete setup dengan Redis
|
||||
./docker-quick-setup.sh dev
|
||||
|
||||
# Test semua functionality
|
||||
./docker-test-redis.sh dev
|
||||
|
||||
# Fix jika ada issues
|
||||
./docker-fix-permissions.sh dev
|
||||
```
|
||||
|
||||
### **3. Production Deployment**
|
||||
```bash
|
||||
# Build production containers
|
||||
./docker-rebuild.sh prod
|
||||
|
||||
# Verify Redis working
|
||||
./docker-test-redis.sh prod
|
||||
|
||||
# Import database
|
||||
./docker-import-db.sh prod
|
||||
```
|
||||
|
||||
## 🔍 Monitoring & Debugging
|
||||
|
||||
### **Redis Monitoring**
|
||||
```bash
|
||||
# Redis logs
|
||||
docker-compose logs redis
|
||||
|
||||
# Redis CLI access
|
||||
docker-compose exec redis redis-cli
|
||||
|
||||
# Redis info
|
||||
docker-compose exec redis redis-cli info
|
||||
|
||||
# Monitor Redis commands
|
||||
docker-compose exec redis redis-cli monitor
|
||||
```
|
||||
|
||||
### **Laravel Debugging**
|
||||
```bash
|
||||
# Check Laravel logs
|
||||
docker-compose exec app tail -f storage/logs/laravel.log
|
||||
|
||||
# Check cache status
|
||||
docker-compose exec app php artisan cache:table
|
||||
|
||||
# Test cache manually
|
||||
docker-compose exec app php artisan tinker
|
||||
# Cache::put('test', 'value', 60);
|
||||
# Cache::get('test');
|
||||
```
|
||||
|
||||
## 📈 Performance Tips
|
||||
|
||||
### **1. Redis Optimization**
|
||||
- Use appropriate data types
|
||||
- Set proper expiration times
|
||||
- Monitor memory usage
|
||||
|
||||
### **2. Laravel Cache Strategy**
|
||||
```bash
|
||||
# Cache configuration
|
||||
php artisan config:cache
|
||||
|
||||
# Cache routes
|
||||
php artisan route:cache
|
||||
|
||||
# Cache views
|
||||
php artisan view:cache
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**✅ Dengan implementasi fix ini, masalah "Class Redis not found" sudah teratasi dan aplikasi Laravel berjalan normal dengan Redis.**
|
||||
@@ -1,253 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Advanced Database Backup Script for CKB Docker
|
||||
# ===============================================
|
||||
|
||||
# Configuration
|
||||
CONTAINER_NAME="ckb-mysql-dev"
|
||||
DB_NAME="ckb_db"
|
||||
DB_USER="root"
|
||||
DB_PASSWORD="root"
|
||||
BACKUP_DIR="./backups"
|
||||
DATE=$(date +%Y%m%d_%H%M%S)
|
||||
RETENTION_DAYS=30 # Keep backups for 30 days
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Functions
|
||||
print_header() {
|
||||
echo -e "${BLUE}================================================${NC}"
|
||||
echo -e "${BLUE} CKB Database Advanced Backup Tool${NC}"
|
||||
echo -e "${BLUE}================================================${NC}"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}✅ $1${NC}"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}❌ $1${NC}"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||||
}
|
||||
|
||||
print_info() {
|
||||
echo -e "${BLUE}ℹ️ $1${NC}"
|
||||
}
|
||||
|
||||
check_container() {
|
||||
if ! docker ps | grep -q $CONTAINER_NAME; then
|
||||
print_error "Container $CONTAINER_NAME is not running!"
|
||||
exit 1
|
||||
fi
|
||||
print_success "Container $CONTAINER_NAME is running"
|
||||
}
|
||||
|
||||
create_backup_dir() {
|
||||
mkdir -p $BACKUP_DIR
|
||||
print_info "Backup directory: $BACKUP_DIR"
|
||||
}
|
||||
|
||||
cleanup_old_backups() {
|
||||
print_info "Cleaning up backups older than $RETENTION_DAYS days..."
|
||||
|
||||
# Find and delete old backup files
|
||||
old_files=$(find $BACKUP_DIR -name "ckb_backup_*.sql*" -mtime +$RETENTION_DAYS 2>/dev/null)
|
||||
|
||||
if [[ -z "$old_files" ]]; then
|
||||
print_info "No old backup files found"
|
||||
else
|
||||
echo "$old_files" | while read file; do
|
||||
rm -f "$file"
|
||||
print_warning "Deleted old backup: $(basename "$file")"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
backup_full() {
|
||||
local backup_file="$BACKUP_DIR/ckb_backup_${DATE}.sql"
|
||||
print_info "Creating full backup..."
|
||||
|
||||
if docker exec $CONTAINER_NAME mysqldump -u $DB_USER -p$DB_PASSWORD \
|
||||
--single-transaction \
|
||||
--routines \
|
||||
--triggers \
|
||||
--add-drop-table \
|
||||
$DB_NAME > "$backup_file"; then
|
||||
|
||||
print_success "Full backup created: $backup_file"
|
||||
return 0
|
||||
else
|
||||
print_error "Full backup failed!"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
backup_structure_only() {
|
||||
local backup_file="$BACKUP_DIR/ckb_structure_${DATE}.sql"
|
||||
print_info "Creating structure-only backup..."
|
||||
|
||||
if docker exec $CONTAINER_NAME mysqldump -u $DB_USER -p$DB_PASSWORD \
|
||||
--no-data \
|
||||
--routines \
|
||||
--triggers \
|
||||
$DB_NAME > "$backup_file"; then
|
||||
|
||||
print_success "Structure backup created: $backup_file"
|
||||
return 0
|
||||
else
|
||||
print_error "Structure backup failed!"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
backup_data_only() {
|
||||
local backup_file="$BACKUP_DIR/ckb_data_${DATE}.sql"
|
||||
print_info "Creating data-only backup..."
|
||||
|
||||
if docker exec $CONTAINER_NAME mysqldump -u $DB_USER -p$DB_PASSWORD \
|
||||
--no-create-info \
|
||||
--single-transaction \
|
||||
$DB_NAME > "$backup_file"; then
|
||||
|
||||
print_success "Data backup created: $backup_file"
|
||||
return 0
|
||||
else
|
||||
print_error "Data backup failed!"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
compress_backup() {
|
||||
local file="$1"
|
||||
if [[ -f "$file" ]]; then
|
||||
print_info "Compressing backup..."
|
||||
if gzip "$file"; then
|
||||
print_success "Backup compressed: $file.gz"
|
||||
|
||||
# Show compression ratio
|
||||
original_size=$(stat -c%s "$file" 2>/dev/null || echo "0")
|
||||
compressed_size=$(stat -c%s "$file.gz" 2>/dev/null || echo "0")
|
||||
if [[ $original_size -gt 0 ]]; then
|
||||
ratio=$(echo "scale=1; (1 - $compressed_size/$original_size) * 100" | bc -l 2>/dev/null || echo "0")
|
||||
print_info "Compression ratio: ${ratio}%"
|
||||
fi
|
||||
else
|
||||
print_error "Compression failed!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
show_backup_stats() {
|
||||
print_info "Backup Statistics:"
|
||||
echo "----------------------------------------"
|
||||
|
||||
# Count backup files
|
||||
total_backups=$(ls -1 $BACKUP_DIR/ckb_backup_*.sql* 2>/dev/null | wc -l)
|
||||
total_size=$(du -sh $BACKUP_DIR 2>/dev/null | cut -f1)
|
||||
|
||||
echo "Total backups: $total_backups"
|
||||
echo "Total size: $total_size"
|
||||
echo "Newest backup: $(ls -1t $BACKUP_DIR/ckb_backup_*.sql* 2>/dev/null | head -1 | xargs basename 2>/dev/null || echo "None")"
|
||||
echo "Oldest backup: $(ls -1tr $BACKUP_DIR/ckb_backup_*.sql* 2>/dev/null | head -1 | xargs basename 2>/dev/null || echo "None")"
|
||||
}
|
||||
|
||||
# Main Script
|
||||
print_header
|
||||
|
||||
echo "Backup Options:"
|
||||
echo "1. Full backup (structure + data)"
|
||||
echo "2. Structure only backup"
|
||||
echo "3. Data only backup"
|
||||
echo "4. All backup types"
|
||||
echo "5. Show backup statistics"
|
||||
echo "6. Cleanup old backups"
|
||||
echo "7. Exit"
|
||||
echo
|
||||
|
||||
read -p "Choose option (1-7): " -n 1 -r option
|
||||
echo
|
||||
|
||||
case $option in
|
||||
1)
|
||||
check_container
|
||||
create_backup_dir
|
||||
if backup_full; then
|
||||
backup_file="$BACKUP_DIR/ckb_backup_${DATE}.sql"
|
||||
|
||||
read -p "Compress backup? (y/n): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
compress_backup "$backup_file"
|
||||
fi
|
||||
|
||||
cleanup_old_backups
|
||||
show_backup_stats
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
check_container
|
||||
create_backup_dir
|
||||
if backup_structure_only; then
|
||||
backup_file="$BACKUP_DIR/ckb_structure_${DATE}.sql"
|
||||
|
||||
read -p "Compress backup? (y/n): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
compress_backup "$backup_file"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
3)
|
||||
check_container
|
||||
create_backup_dir
|
||||
if backup_data_only; then
|
||||
backup_file="$BACKUP_DIR/ckb_data_${DATE}.sql"
|
||||
|
||||
read -p "Compress backup? (y/n): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
compress_backup "$backup_file"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
4)
|
||||
check_container
|
||||
create_backup_dir
|
||||
|
||||
print_info "Creating all backup types..."
|
||||
|
||||
backup_full && compress_backup "$BACKUP_DIR/ckb_backup_${DATE}.sql"
|
||||
backup_structure_only && compress_backup "$BACKUP_DIR/ckb_structure_${DATE}.sql"
|
||||
backup_data_only && compress_backup "$BACKUP_DIR/ckb_data_${DATE}.sql"
|
||||
|
||||
cleanup_old_backups
|
||||
show_backup_stats
|
||||
;;
|
||||
5)
|
||||
create_backup_dir
|
||||
show_backup_stats
|
||||
;;
|
||||
6)
|
||||
create_backup_dir
|
||||
cleanup_old_backups
|
||||
show_backup_stats
|
||||
;;
|
||||
7)
|
||||
print_info "Goodbye!"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
print_error "Invalid option!"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
print_success "Backup process completed!"
|
||||
48
backup_db.sh
48
backup_db.sh
@@ -1,48 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configuration
|
||||
CONTAINER_NAME="ckb-mysql-dev"
|
||||
DB_NAME="ckb_db"
|
||||
DB_USER="root"
|
||||
DB_PASSWORD="root"
|
||||
BACKUP_DIR="./backups"
|
||||
DATE=$(date +%Y%m%d_%H%M%S)
|
||||
BACKUP_FILE="ckb_backup_${DATE}.sql"
|
||||
|
||||
# Create backup directory if it doesn't exist
|
||||
mkdir -p $BACKUP_DIR
|
||||
|
||||
# Check if container is running
|
||||
if ! docker ps | grep -q $CONTAINER_NAME; then
|
||||
echo "Error: Container $CONTAINER_NAME is not running!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Starting database backup..."
|
||||
echo "Container: $CONTAINER_NAME"
|
||||
echo "Database: $DB_NAME"
|
||||
echo "Backup file: $BACKUP_DIR/$BACKUP_FILE"
|
||||
|
||||
# Create backup
|
||||
if docker exec $CONTAINER_NAME mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME > "$BACKUP_DIR/$BACKUP_FILE"; then
|
||||
echo "✅ Backup completed successfully!"
|
||||
echo "📁 File saved: $BACKUP_DIR/$BACKUP_FILE"
|
||||
|
||||
# Show file size
|
||||
FILE_SIZE=$(du -h "$BACKUP_DIR/$BACKUP_FILE" | cut -f1)
|
||||
echo "📊 File size: $FILE_SIZE"
|
||||
|
||||
# Optional: Compress the backup
|
||||
read -p "Do you want to compress the backup? (y/n): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
gzip "$BACKUP_DIR/$BACKUP_FILE"
|
||||
echo "🗜️ Backup compressed: $BACKUP_DIR/$BACKUP_FILE.gz"
|
||||
fi
|
||||
|
||||
else
|
||||
echo "❌ Backup failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "🎉 Backup process completed!"
|
||||
@@ -1,52 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# CKB Asset Debugging Script
|
||||
echo "🔍 CKB Asset Debugging..."
|
||||
|
||||
echo "🔧 Checking APP_URL configuration:"
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan config:show app.url
|
||||
|
||||
echo ""
|
||||
echo "📁 Checking public directory structure:"
|
||||
docker-compose -f docker-compose.prod.yml exec app ls -la /var/www/html/public/
|
||||
|
||||
echo ""
|
||||
echo "📁 Checking CSS files:"
|
||||
docker-compose -f docker-compose.prod.yml exec app ls -la /var/www/html/public/css/
|
||||
|
||||
echo ""
|
||||
echo "📁 Checking JS files:"
|
||||
docker-compose -f docker-compose.prod.yml exec app ls -la /var/www/html/public/js/
|
||||
|
||||
echo ""
|
||||
echo "🌐 Testing CSS file accessibility:"
|
||||
docker-compose -f docker-compose.prod.yml exec app curl -I http://localhost/css/app.css
|
||||
|
||||
echo ""
|
||||
echo "🌐 Testing JS file accessibility:"
|
||||
docker-compose -f docker-compose.prod.yml exec app curl -I http://localhost/js/app.js
|
||||
|
||||
echo ""
|
||||
echo "📝 Checking nginx error logs:"
|
||||
docker-compose -f docker-compose.prod.yml exec nginx-proxy tail -20 /var/log/nginx/error.log
|
||||
|
||||
echo ""
|
||||
echo "📝 Checking app nginx error logs:"
|
||||
docker-compose -f docker-compose.prod.yml exec app tail -20 /var/log/nginx/error.log
|
||||
|
||||
echo ""
|
||||
echo "🔧 Checking nginx configuration:"
|
||||
docker-compose -f docker-compose.prod.yml exec app nginx -t
|
||||
|
||||
echo ""
|
||||
echo "🔧 Checking proxy nginx configuration:"
|
||||
docker-compose -f docker-compose.prod.yml exec nginx-proxy nginx -t
|
||||
|
||||
echo ""
|
||||
echo "📊 Container status:"
|
||||
docker-compose -f docker-compose.prod.yml ps
|
||||
|
||||
echo ""
|
||||
echo "🌐 Testing external access to CSS:"
|
||||
echo "Try accessing: http://localhost:8082/css/app.css"
|
||||
curl -I http://localhost:8082/css/app.css
|
||||
105
deploy-ckb.sh
105
deploy-ckb.sh
@@ -1,105 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# CKB Application Deployment Script
|
||||
# This script sets up SSL certificate and deploys the CKB application
|
||||
|
||||
set -e
|
||||
|
||||
echo "=== CKB Application Deployment Script ==="
|
||||
echo "Domain: bengkel.digitaloasis.xyz"
|
||||
echo "Port: 8082"
|
||||
echo ""
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if running as root
|
||||
if [[ $EUID -eq 0 ]]; then
|
||||
print_error "This script should not be run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if we're in the correct directory
|
||||
if [ ! -f "docker-compose.prod.yml" ]; then
|
||||
print_error "Please run this script from the CKB application directory (/var/www/ckb)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_status "Starting CKB application deployment..."
|
||||
|
||||
# Step 1: Stop existing containers
|
||||
print_status "Stopping existing containers..."
|
||||
docker-compose -f docker-compose.prod.yml down
|
||||
|
||||
# Step 2: Build and start containers
|
||||
print_status "Building and starting containers..."
|
||||
docker-compose -f docker-compose.prod.yml up -d --build
|
||||
|
||||
# Step 3: Wait for containers to be ready
|
||||
print_status "Waiting for containers to be ready..."
|
||||
sleep 10
|
||||
|
||||
# Step 4: Check if containers are running
|
||||
print_status "Checking container status..."
|
||||
if docker ps | grep -q "ckb-laravel-app"; then
|
||||
print_status "CKB Laravel app is running"
|
||||
else
|
||||
print_error "CKB Laravel app is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if docker ps | grep -q "ckb-nginx-proxy"; then
|
||||
print_status "CKB Nginx proxy is running"
|
||||
else
|
||||
print_error "CKB Nginx proxy is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Step 5: Check if port 8082 is accessible
|
||||
print_status "Checking if port 8082 is accessible..."
|
||||
if curl -s -o /dev/null -w "%{http_code}" http://localhost:8082 | grep -q "200\|301\|302"; then
|
||||
print_status "Port 8082 is accessible"
|
||||
else
|
||||
print_warning "Port 8082 might not be accessible yet, waiting..."
|
||||
sleep 5
|
||||
if curl -s -o /dev/null -w "%{http_code}" http://localhost:8082 | grep -q "200\|301\|302"; then
|
||||
print_status "Port 8082 is now accessible"
|
||||
else
|
||||
print_error "Port 8082 is not accessible"
|
||||
print_status "Checking container logs..."
|
||||
docker-compose -f docker-compose.prod.yml logs ckb-nginx-proxy
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
print_status "CKB application deployment completed successfully!"
|
||||
echo ""
|
||||
print_status "Next steps:"
|
||||
echo "1. Configure Nginx reverse proxy on the main server:"
|
||||
echo " sudo cp nginx-ckb-reverse-proxy.conf /etc/nginx/sites-available/bengkel.digitaloasis.xyz"
|
||||
echo " sudo ln -s /etc/nginx/sites-available/bengkel.digitaloasis.xyz /etc/nginx/sites-enabled/"
|
||||
echo ""
|
||||
echo "2. Generate SSL certificate:"
|
||||
echo " sudo certbot certonly --webroot --webroot-path=/var/www/html --email admin@digitaloasis.xyz --agree-tos --no-eff-email -d bengkel.digitaloasis.xyz -d www.bengkel.digitaloasis.xyz"
|
||||
echo ""
|
||||
echo "3. Test and reload Nginx:"
|
||||
echo " sudo nginx -t"
|
||||
echo " sudo systemctl reload nginx"
|
||||
echo ""
|
||||
print_status "Application will be accessible at: https://bengkel.digitaloasis.xyz"
|
||||
61
deploy.sh
61
deploy.sh
@@ -1,61 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# CKB Production Deployment Script
|
||||
echo "🚀 Starting CKB Production Deployment..."
|
||||
|
||||
# Stop existing containers
|
||||
echo "📦 Stopping existing containers..."
|
||||
docker-compose -f docker-compose.prod.yml down
|
||||
|
||||
# Remove old images to force rebuild
|
||||
echo "🗑️ Removing old images..."
|
||||
docker image prune -f
|
||||
docker rmi ckb-app-prod 2>/dev/null || true
|
||||
|
||||
# Build and start containers
|
||||
echo "🔨 Building and starting containers..."
|
||||
docker-compose -f docker-compose.prod.yml up -d --build
|
||||
|
||||
# Wait for containers to be ready
|
||||
echo "⏳ Waiting for containers to be ready..."
|
||||
sleep 30
|
||||
|
||||
# Clear Laravel caches first
|
||||
echo "🧹 Clearing Laravel caches..."
|
||||
docker-compose -f docker-compose.prod.yml exec -T app php artisan config:clear
|
||||
docker-compose -f docker-compose.prod.yml exec -T app php artisan route:clear
|
||||
docker-compose -f docker-compose.prod.yml exec -T app php artisan view:clear
|
||||
docker-compose -f docker-compose.prod.yml exec -T app php artisan cache:clear
|
||||
|
||||
# Run Laravel optimizations
|
||||
echo "⚡ Running Laravel optimizations..."
|
||||
docker-compose -f docker-compose.prod.yml exec -T app php artisan config:cache
|
||||
docker-compose -f docker-compose.prod.yml exec -T app php artisan route:cache
|
||||
docker-compose -f docker-compose.prod.yml exec -T app php artisan view:cache
|
||||
|
||||
# Run migrations (if needed)
|
||||
echo "🗄️ Running database migrations..."
|
||||
docker-compose -f docker-compose.prod.yml exec -T app php artisan migrate --force
|
||||
|
||||
# Set proper permissions
|
||||
echo "🔐 Setting proper permissions..."
|
||||
docker-compose -f docker-compose.prod.yml exec -T app chown -R www-data:www-data /var/www/html/storage
|
||||
docker-compose -f docker-compose.prod.yml exec -T app chown -R www-data:www-data /var/www/html/bootstrap/cache
|
||||
|
||||
# Show container status
|
||||
echo "📊 Container status:"
|
||||
docker-compose -f docker-compose.prod.yml ps
|
||||
|
||||
# Show logs for debugging
|
||||
echo "📝 Recent logs:"
|
||||
docker-compose -f docker-compose.prod.yml logs --tail=20
|
||||
|
||||
echo "✅ Deployment completed!"
|
||||
echo "🌐 Application should be available at: http://localhost:8082"
|
||||
echo ""
|
||||
echo "🔍 Testing asset URLs:"
|
||||
echo "CSS: http://localhost:8082/assets/css/app.bundle.min.css"
|
||||
echo "JS: http://localhost:8082/assets/js/app.bundle.min.js"
|
||||
echo ""
|
||||
echo "To check logs: docker-compose -f docker-compose.prod.yml logs -f"
|
||||
echo "To check app logs: docker-compose -f docker-compose.prod.yml logs -f app"
|
||||
100
dev-restart.sh
100
dev-restart.sh
@@ -1,100 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Development Restart Script
|
||||
# Usage: ./dev-restart.sh [cache|config|routes|all|container]
|
||||
|
||||
set -e
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
ACTION=${1:-cache}
|
||||
|
||||
print_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
case $ACTION in
|
||||
cache)
|
||||
print_info "Clearing Laravel cache..."
|
||||
docker-compose exec app php artisan cache:clear
|
||||
print_success "Cache cleared!"
|
||||
;;
|
||||
|
||||
config)
|
||||
print_info "Clearing configuration cache..."
|
||||
docker-compose exec app php artisan config:clear
|
||||
print_success "Config cache cleared!"
|
||||
;;
|
||||
|
||||
routes)
|
||||
print_info "Clearing route cache..."
|
||||
docker-compose exec app php artisan route:clear
|
||||
print_success "Route cache cleared!"
|
||||
;;
|
||||
|
||||
all)
|
||||
print_info "Clearing all Laravel caches..."
|
||||
docker-compose exec app php artisan optimize:clear
|
||||
print_success "All caches cleared!"
|
||||
;;
|
||||
|
||||
container)
|
||||
print_info "Restarting app container..."
|
||||
docker-compose restart app
|
||||
print_success "Container restarted!"
|
||||
;;
|
||||
|
||||
build)
|
||||
print_info "Rebuilding app container..."
|
||||
docker-compose up -d --build app
|
||||
print_success "Container rebuilt!"
|
||||
;;
|
||||
|
||||
migrate)
|
||||
print_info "Running database migrations..."
|
||||
docker-compose exec app php artisan migrate
|
||||
print_success "Migrations completed!"
|
||||
;;
|
||||
|
||||
composer)
|
||||
print_info "Installing/updating composer dependencies..."
|
||||
docker-compose exec app composer install --optimize-autoloader
|
||||
print_success "Composer dependencies updated!"
|
||||
;;
|
||||
|
||||
npm)
|
||||
print_info "Installing npm dependencies and building assets..."
|
||||
docker-compose exec app npm install
|
||||
docker-compose exec app npm run dev
|
||||
print_success "Frontend assets built!"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Development Restart Script"
|
||||
echo "Usage: $0 [cache|config|routes|all|container|build|migrate|composer|npm]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " cache - Clear application cache only"
|
||||
echo " config - Clear configuration cache"
|
||||
echo " routes - Clear route cache"
|
||||
echo " all - Clear all Laravel caches"
|
||||
echo " container - Restart app container"
|
||||
echo " build - Rebuild app container"
|
||||
echo " migrate - Run database migrations"
|
||||
echo " composer - Update composer dependencies"
|
||||
echo " npm - Update npm and build assets"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -1,332 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script untuk deploy CKB Laravel Application ke production dengan domain bengkel.digitaloasis.xyz
|
||||
# Usage: ./docker-deploy-prod.sh [build|deploy|ssl|status]
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Configuration
|
||||
DOMAIN="bengkel.digitaloasis.xyz"
|
||||
EMAIL="admin@digitaloasis.xyz"
|
||||
COMPOSE_FILE="docker-compose.prod.yml"
|
||||
ENV_FILE=".env"
|
||||
|
||||
# Default action
|
||||
ACTION="deploy"
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
build)
|
||||
ACTION="build"
|
||||
shift
|
||||
;;
|
||||
deploy)
|
||||
ACTION="deploy"
|
||||
shift
|
||||
;;
|
||||
ssl)
|
||||
ACTION="ssl"
|
||||
shift
|
||||
;;
|
||||
status)
|
||||
ACTION="status"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
echo "Usage: $0 [build|deploy|ssl|status]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to check prerequisites
|
||||
check_prerequisites() {
|
||||
print_status "Checking prerequisites..."
|
||||
|
||||
# Check Docker
|
||||
if ! docker info > /dev/null 2>&1; then
|
||||
print_error "Docker is not running. Please start Docker first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check Docker Compose
|
||||
if ! docker-compose --version > /dev/null 2>&1; then
|
||||
print_error "Docker Compose is not installed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if .env file exists
|
||||
if [[ ! -f $ENV_FILE ]]; then
|
||||
print_warning "Environment file not found. Creating from production template..."
|
||||
if [[ -f docker/env.example.production ]]; then
|
||||
cp docker/env.example.production $ENV_FILE
|
||||
print_warning "⚠️ IMPORTANT: Edit $ENV_FILE and change all CHANGE_THIS_* passwords before continuing!"
|
||||
print_status "Production template copied. Please configure:"
|
||||
echo " - DB_PASSWORD and DB_ROOT_PASSWORD"
|
||||
echo " - REDIS_PASSWORD"
|
||||
echo " - MAIL_* settings"
|
||||
echo " - AWS_* settings (if using S3)"
|
||||
exit 1
|
||||
else
|
||||
print_error "Production environment template not found: docker/env.example.production"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
print_success "Prerequisites check passed!"
|
||||
}
|
||||
|
||||
# Function to setup production environment
|
||||
setup_production_env() {
|
||||
print_status "Setting up production environment variables..."
|
||||
|
||||
# Update .env for production
|
||||
sed -i "s|APP_ENV=.*|APP_ENV=production|g" $ENV_FILE
|
||||
sed -i "s|APP_DEBUG=.*|APP_DEBUG=false|g" $ENV_FILE
|
||||
sed -i "s|APP_URL=.*|APP_URL=https://$DOMAIN|g" $ENV_FILE
|
||||
|
||||
# Check if database credentials are set
|
||||
if grep -q "DB_PASSWORD=password" $ENV_FILE; then
|
||||
print_warning "Please update database credentials in $ENV_FILE for production!"
|
||||
print_warning "Current settings are for development only."
|
||||
fi
|
||||
|
||||
print_success "Production environment configured!"
|
||||
}
|
||||
|
||||
# Function to build containers
|
||||
build_containers() {
|
||||
print_status "Building production containers..."
|
||||
|
||||
# Pull latest images
|
||||
docker-compose -f $COMPOSE_FILE pull
|
||||
|
||||
# Build application container
|
||||
docker-compose -f $COMPOSE_FILE build --no-cache app
|
||||
|
||||
print_success "Containers built successfully!"
|
||||
}
|
||||
|
||||
# Function to deploy application
|
||||
deploy_application() {
|
||||
print_status "Deploying CKB Laravel Application to production..."
|
||||
|
||||
# Stop existing containers
|
||||
print_status "Stopping existing containers..."
|
||||
docker-compose -f $COMPOSE_FILE down || true
|
||||
|
||||
# Start database and redis first
|
||||
print_status "Starting database and Redis..."
|
||||
docker-compose -f $COMPOSE_FILE up -d db redis
|
||||
|
||||
# Wait for database to be ready
|
||||
print_status "Waiting for database to be ready..."
|
||||
sleep 20
|
||||
|
||||
# Start application
|
||||
print_status "Starting application..."
|
||||
docker-compose -f $COMPOSE_FILE up -d app
|
||||
|
||||
# Wait for application to be ready
|
||||
sleep 15
|
||||
|
||||
# Run Laravel setup commands
|
||||
print_status "Running Laravel setup commands..."
|
||||
docker-compose -f $COMPOSE_FILE exec -T app php artisan key:generate --force || true
|
||||
docker-compose -f $COMPOSE_FILE exec -T app php artisan migrate --force
|
||||
docker-compose -f $COMPOSE_FILE exec -T app php artisan config:cache
|
||||
docker-compose -f $COMPOSE_FILE exec -T app php artisan route:cache
|
||||
docker-compose -f $COMPOSE_FILE exec -T app php artisan view:cache
|
||||
docker-compose -f $COMPOSE_FILE exec -T app php artisan storage:link || true
|
||||
|
||||
# Start nginx proxy
|
||||
print_status "Starting nginx proxy..."
|
||||
docker-compose -f $COMPOSE_FILE up -d nginx-proxy
|
||||
|
||||
print_success "Application deployed successfully!"
|
||||
}
|
||||
|
||||
# Function to setup SSL
|
||||
setup_ssl() {
|
||||
print_status "Setting up SSL certificate..."
|
||||
|
||||
if [[ -f docker-ssl-setup.sh ]]; then
|
||||
chmod +x docker-ssl-setup.sh
|
||||
./docker-ssl-setup.sh
|
||||
else
|
||||
print_error "SSL setup script not found!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to show deployment status
|
||||
show_status() {
|
||||
print_status "CKB Production Deployment Status"
|
||||
echo "================================================"
|
||||
|
||||
# Show container status
|
||||
print_status "Container Status:"
|
||||
docker-compose -f $COMPOSE_FILE ps
|
||||
echo ""
|
||||
|
||||
# Show application health
|
||||
print_status "Application Health:"
|
||||
if curl -s --max-time 10 http://localhost/health > /dev/null 2>&1; then
|
||||
print_success "✅ Application is responding on HTTP"
|
||||
else
|
||||
print_warning "❌ Application not responding on HTTP"
|
||||
fi
|
||||
|
||||
if curl -s --max-time 10 https://$DOMAIN/health > /dev/null 2>&1; then
|
||||
print_success "✅ Application is responding on HTTPS"
|
||||
else
|
||||
print_warning "❌ Application not responding on HTTPS"
|
||||
fi
|
||||
|
||||
# Show SSL certificate status
|
||||
print_status "SSL Certificate Status:"
|
||||
if openssl s_client -connect $DOMAIN:443 -servername $DOMAIN < /dev/null 2>/dev/null | openssl x509 -noout -dates 2>/dev/null; then
|
||||
print_success "✅ SSL certificate is active"
|
||||
else
|
||||
print_warning "❌ SSL certificate not found or invalid"
|
||||
fi
|
||||
|
||||
# Show disk usage
|
||||
print_status "Docker Disk Usage:"
|
||||
docker system df
|
||||
echo ""
|
||||
|
||||
# Show logs summary
|
||||
print_status "Recent Application Logs:"
|
||||
docker-compose -f $COMPOSE_FILE logs --tail=10 app || true
|
||||
|
||||
echo ""
|
||||
print_status "Access URLs:"
|
||||
echo " 🌐 Application: https://$DOMAIN"
|
||||
echo " 🔍 Health Check: https://$DOMAIN/health"
|
||||
echo ""
|
||||
|
||||
print_status "Useful Commands:"
|
||||
echo " - View logs: docker-compose -f $COMPOSE_FILE logs -f [service]"
|
||||
echo " - Enter container: docker-compose -f $COMPOSE_FILE exec app bash"
|
||||
echo " - Update SSL: ./docker-ssl-setup.sh"
|
||||
echo " - Restart app: docker-compose -f $COMPOSE_FILE restart app"
|
||||
}
|
||||
|
||||
# Function to backup before deployment
|
||||
backup_before_deploy() {
|
||||
print_status "Creating backup before deployment..."
|
||||
|
||||
BACKUP_DIR="backups/$(date +%Y%m%d_%H%M%S)"
|
||||
mkdir -p $BACKUP_DIR
|
||||
|
||||
# Backup database
|
||||
if docker-compose -f $COMPOSE_FILE ps db | grep -q "Up"; then
|
||||
print_status "Backing up database..."
|
||||
docker-compose -f $COMPOSE_FILE exec -T db mysqldump -u root -p"${DB_ROOT_PASSWORD:-rootpassword}" "${DB_DATABASE:-ckb_production}" > "$BACKUP_DIR/database.sql"
|
||||
print_success "Database backed up to $BACKUP_DIR/database.sql"
|
||||
fi
|
||||
|
||||
# Backup storage
|
||||
if [[ -d storage ]]; then
|
||||
print_status "Backing up storage directory..."
|
||||
tar -czf "$BACKUP_DIR/storage.tar.gz" storage/
|
||||
print_success "Storage backed up to $BACKUP_DIR/storage.tar.gz"
|
||||
fi
|
||||
|
||||
# Backup environment
|
||||
if [[ -f $ENV_FILE ]]; then
|
||||
cp $ENV_FILE "$BACKUP_DIR/env.backup"
|
||||
print_success "Environment backed up to $BACKUP_DIR/env.backup"
|
||||
fi
|
||||
|
||||
print_success "Backup completed in $BACKUP_DIR"
|
||||
}
|
||||
|
||||
# Function to optimize for production
|
||||
optimize_production() {
|
||||
print_status "Optimizing application for production..."
|
||||
|
||||
# Laravel optimizations
|
||||
docker-compose -f $COMPOSE_FILE exec -T app composer install --optimize-autoloader --no-dev --no-interaction
|
||||
docker-compose -f $COMPOSE_FILE exec -T app php artisan config:cache
|
||||
docker-compose -f $COMPOSE_FILE exec -T app php artisan route:cache
|
||||
docker-compose -f $COMPOSE_FILE exec -T app php artisan view:cache
|
||||
|
||||
# Clean up Docker
|
||||
docker system prune -f
|
||||
|
||||
print_success "Production optimization completed!"
|
||||
}
|
||||
|
||||
# Main execution
|
||||
echo "================================================"
|
||||
print_status "🚀 CKB Production Deployment Script"
|
||||
print_status "Domain: $DOMAIN"
|
||||
print_status "Action: $ACTION"
|
||||
echo "================================================"
|
||||
echo ""
|
||||
|
||||
# Check prerequisites
|
||||
check_prerequisites
|
||||
|
||||
case $ACTION in
|
||||
build)
|
||||
print_status "Building containers only..."
|
||||
build_containers
|
||||
print_success "✅ Build completed!"
|
||||
;;
|
||||
|
||||
deploy)
|
||||
print_status "Full deployment process..."
|
||||
backup_before_deploy
|
||||
setup_production_env
|
||||
build_containers
|
||||
deploy_application
|
||||
optimize_production
|
||||
print_success "✅ Deployment completed!"
|
||||
echo ""
|
||||
print_status "Next steps:"
|
||||
echo "1. Setup SSL certificate: ./docker-deploy-prod.sh ssl"
|
||||
echo "2. Check status: ./docker-deploy-prod.sh status"
|
||||
;;
|
||||
|
||||
ssl)
|
||||
print_status "Setting up SSL certificate..."
|
||||
setup_ssl
|
||||
print_success "✅ SSL setup completed!"
|
||||
;;
|
||||
|
||||
status)
|
||||
show_status
|
||||
;;
|
||||
esac
|
||||
|
||||
echo ""
|
||||
print_success "✅ Production deployment script completed!"
|
||||
@@ -1,226 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script untuk memperbaiki permission Laravel storage di Docker container
|
||||
# Usage: ./docker-fix-permissions.sh [dev|prod]
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Default values
|
||||
ENVIRONMENT="dev"
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
dev|development)
|
||||
ENVIRONMENT="dev"
|
||||
shift
|
||||
;;
|
||||
prod|production|staging)
|
||||
ENVIRONMENT="prod"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
echo "Usage: $0 [dev|prod]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to check if containers are running
|
||||
check_containers() {
|
||||
local compose_file=""
|
||||
local app_container=""
|
||||
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
compose_file="docker-compose.yml"
|
||||
app_container="ckb-app-dev"
|
||||
else
|
||||
compose_file="docker-compose.prod.yml"
|
||||
app_container="ckb-app-prod"
|
||||
fi
|
||||
|
||||
if ! docker-compose -f "$compose_file" ps | grep -q "$app_container.*Up"; then
|
||||
print_error "App container is not running!"
|
||||
print_status "Please start the containers first:"
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
echo " ./docker-start.sh dev up"
|
||||
else
|
||||
echo " ./docker-start.sh prod up"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
COMPOSE_FILE="$compose_file"
|
||||
}
|
||||
|
||||
# Function to create necessary directories
|
||||
create_directories() {
|
||||
print_status "Creating necessary Laravel directories..."
|
||||
|
||||
docker-compose -f "$COMPOSE_FILE" exec app mkdir -p /var/www/html/storage/logs
|
||||
docker-compose -f "$COMPOSE_FILE" exec app mkdir -p /var/www/html/storage/framework/cache
|
||||
docker-compose -f "$COMPOSE_FILE" exec app mkdir -p /var/www/html/storage/framework/sessions
|
||||
docker-compose -f "$COMPOSE_FILE" exec app mkdir -p /var/www/html/storage/framework/views
|
||||
docker-compose -f "$COMPOSE_FILE" exec app mkdir -p /var/www/html/storage/app/public
|
||||
docker-compose -f "$COMPOSE_FILE" exec app mkdir -p /var/www/html/bootstrap/cache
|
||||
|
||||
print_success "Directories created!"
|
||||
}
|
||||
|
||||
# Function to fix ownership
|
||||
fix_ownership() {
|
||||
print_status "Fixing ownership to www-data:www-data..."
|
||||
|
||||
docker-compose -f "$COMPOSE_FILE" exec app chown -R www-data:www-data /var/www/html/storage
|
||||
docker-compose -f "$COMPOSE_FILE" exec app chown -R www-data:www-data /var/www/html/bootstrap/cache
|
||||
docker-compose -f "$COMPOSE_FILE" exec app chown -R www-data:www-data /var/www/html/public
|
||||
|
||||
print_success "Ownership fixed!"
|
||||
}
|
||||
|
||||
# Function to fix permissions
|
||||
fix_permissions() {
|
||||
print_status "Setting proper permissions (775)..."
|
||||
|
||||
docker-compose -f "$COMPOSE_FILE" exec app chmod -R 775 /var/www/html/storage
|
||||
docker-compose -f "$COMPOSE_FILE" exec app chmod -R 775 /var/www/html/bootstrap/cache
|
||||
docker-compose -f "$COMPOSE_FILE" exec app chmod -R 755 /var/www/html/public
|
||||
|
||||
print_success "Permissions set!"
|
||||
}
|
||||
|
||||
# Function to create .gitkeep files
|
||||
create_gitkeep() {
|
||||
print_status "Creating .gitkeep files for empty directories..."
|
||||
|
||||
docker-compose -f "$COMPOSE_FILE" exec app touch /var/www/html/storage/logs/.gitkeep
|
||||
docker-compose -f "$COMPOSE_FILE" exec app touch /var/www/html/storage/framework/cache/.gitkeep
|
||||
docker-compose -f "$COMPOSE_FILE" exec app touch /var/www/html/storage/framework/sessions/.gitkeep
|
||||
docker-compose -f "$COMPOSE_FILE" exec app touch /var/www/html/storage/framework/views/.gitkeep
|
||||
docker-compose -f "$COMPOSE_FILE" exec app touch /var/www/html/storage/app/.gitkeep
|
||||
|
||||
print_success ".gitkeep files created!"
|
||||
}
|
||||
|
||||
# Function to test Laravel logging
|
||||
test_logging() {
|
||||
print_status "Testing Laravel logging..."
|
||||
|
||||
# Try to write to Laravel log
|
||||
if docker-compose -f "$COMPOSE_FILE" exec app php -r "file_put_contents('/var/www/html/storage/logs/laravel.log', 'Test log entry: ' . date('Y-m-d H:i:s') . PHP_EOL, FILE_APPEND | LOCK_EX);"; then
|
||||
print_success "Laravel logging test passed!"
|
||||
else
|
||||
print_error "Laravel logging test failed!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Test Laravel cache
|
||||
if docker-compose -f "$COMPOSE_FILE" exec app php artisan cache:clear > /dev/null 2>&1; then
|
||||
print_success "Laravel cache test passed!"
|
||||
else
|
||||
print_warning "Laravel cache test failed (might be normal if no cache driver configured)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to create storage link
|
||||
create_storage_link() {
|
||||
print_status "Creating storage symbolic link..."
|
||||
|
||||
if docker-compose -f "$COMPOSE_FILE" exec app php artisan storage:link > /dev/null 2>&1; then
|
||||
print_success "Storage link created!"
|
||||
else
|
||||
print_warning "Storage link creation failed (might already exist)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to show current permissions
|
||||
show_permissions() {
|
||||
print_status "Current storage permissions:"
|
||||
echo ""
|
||||
|
||||
docker-compose -f "$COMPOSE_FILE" exec app ls -la /var/www/html/storage/
|
||||
echo ""
|
||||
docker-compose -f "$COMPOSE_FILE" exec app ls -la /var/www/html/storage/logs/ || true
|
||||
echo ""
|
||||
docker-compose -f "$COMPOSE_FILE" exec app ls -la /var/www/html/bootstrap/cache/ || true
|
||||
}
|
||||
|
||||
# Function to show troubleshooting tips
|
||||
show_tips() {
|
||||
echo ""
|
||||
print_status "🔧 Troubleshooting Tips:"
|
||||
echo ""
|
||||
echo "1. If you still get permission errors, try rebuilding containers:"
|
||||
echo " ./docker-rebuild.sh $ENVIRONMENT"
|
||||
echo ""
|
||||
echo "2. For persistent permission issues, add this to your docker-compose volumes:"
|
||||
echo " - ./storage:/var/www/html/storage"
|
||||
echo ""
|
||||
echo "3. Check Laravel .env file for correct LOG_CHANNEL setting:"
|
||||
echo " LOG_CHANNEL=stack"
|
||||
echo ""
|
||||
echo "4. Monitor logs for more errors:"
|
||||
echo " docker-compose -f $COMPOSE_FILE logs -f app"
|
||||
echo ""
|
||||
echo "5. Test Laravel application:"
|
||||
echo " docker-compose -f $COMPOSE_FILE exec app php artisan tinker"
|
||||
}
|
||||
|
||||
# Main execution
|
||||
print_status "🔧 Laravel Storage Permission Fix"
|
||||
print_status "Environment: $ENVIRONMENT"
|
||||
echo ""
|
||||
|
||||
# Check prerequisites
|
||||
check_containers
|
||||
|
||||
# Show current state
|
||||
print_status "Before fixing - Current permissions:"
|
||||
show_permissions
|
||||
|
||||
echo ""
|
||||
print_status "Fixing permissions..."
|
||||
|
||||
# Execute fix process
|
||||
create_directories
|
||||
fix_ownership
|
||||
fix_permissions
|
||||
create_gitkeep
|
||||
create_storage_link
|
||||
test_logging
|
||||
|
||||
echo ""
|
||||
print_status "After fixing - Updated permissions:"
|
||||
show_permissions
|
||||
|
||||
# Show final status
|
||||
echo ""
|
||||
print_success "✅ Permission fix completed!"
|
||||
|
||||
# Show troubleshooting tips
|
||||
show_tips
|
||||
@@ -1,209 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script untuk mengimport database backup ke MySQL Docker container
|
||||
# Usage: ./docker-import-db.sh [dev|prod] [database_file.sql]
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Default values
|
||||
ENVIRONMENT="dev"
|
||||
SQL_FILE="ckb.sql"
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
dev|development)
|
||||
ENVIRONMENT="dev"
|
||||
shift
|
||||
;;
|
||||
prod|production|staging)
|
||||
ENVIRONMENT="prod"
|
||||
shift
|
||||
;;
|
||||
*.sql)
|
||||
SQL_FILE="$1"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
echo "Usage: $0 [dev|prod] [database_file.sql]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to check if file exists
|
||||
check_sql_file() {
|
||||
if [[ ! -f "$SQL_FILE" ]]; then
|
||||
print_error "SQL file '$SQL_FILE' not found!"
|
||||
exit 1
|
||||
fi
|
||||
print_status "Found SQL file: $SQL_FILE ($(du -h "$SQL_FILE" | cut -f1))"
|
||||
}
|
||||
|
||||
# Function to check if containers are running
|
||||
check_containers() {
|
||||
local compose_file=""
|
||||
local db_container=""
|
||||
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
compose_file="docker-compose.yml"
|
||||
db_container="ckb-mysql"
|
||||
else
|
||||
compose_file="docker-compose.prod.yml"
|
||||
db_container="ckb-mysql-prod"
|
||||
fi
|
||||
|
||||
if ! docker-compose -f "$compose_file" ps | grep -q "$db_container.*Up"; then
|
||||
print_error "Database container is not running!"
|
||||
print_status "Please start the containers first:"
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
echo " ./docker-start.sh dev up"
|
||||
else
|
||||
echo " ./docker-start.sh prod up"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to get database credentials
|
||||
get_db_credentials() {
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
DB_HOST="ckb-mysql"
|
||||
DB_NAME="ckb_db"
|
||||
DB_USER="root"
|
||||
DB_PASSWORD="root"
|
||||
COMPOSE_FILE="docker-compose.yml"
|
||||
else
|
||||
DB_HOST="ckb-mysql-prod"
|
||||
DB_NAME="ckb_production"
|
||||
DB_USER="root"
|
||||
# For production, we should read from environment or prompt
|
||||
if [[ -f .env.production ]]; then
|
||||
DB_PASSWORD=$(grep DB_ROOT_PASSWORD .env.production | cut -d '=' -f2)
|
||||
else
|
||||
read -s -p "Enter MySQL root password for production: " DB_PASSWORD
|
||||
echo
|
||||
fi
|
||||
COMPOSE_FILE="docker-compose.prod.yml"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to backup existing database
|
||||
backup_existing_db() {
|
||||
local backup_file="backup_before_import_$(date +%Y%m%d_%H%M%S).sql"
|
||||
|
||||
print_status "Creating backup of existing database..."
|
||||
|
||||
if docker-compose -f "$COMPOSE_FILE" exec -T db mysqldump -u "$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" > "$backup_file" 2>/dev/null; then
|
||||
print_success "Existing database backed up to: $backup_file"
|
||||
else
|
||||
print_warning "Could not backup existing database (it might be empty)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to import database
|
||||
import_database() {
|
||||
print_status "Importing database from $SQL_FILE..."
|
||||
print_status "This may take a while for large files..."
|
||||
|
||||
# Drop and recreate database to ensure clean import
|
||||
print_status "Recreating database..."
|
||||
docker-compose -f "$COMPOSE_FILE" exec -T db mysql -u "$DB_USER" -p"$DB_PASSWORD" -e "DROP DATABASE IF EXISTS $DB_NAME;"
|
||||
docker-compose -f "$COMPOSE_FILE" exec -T db mysql -u "$DB_USER" -p"$DB_PASSWORD" -e "CREATE DATABASE $DB_NAME CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
||||
|
||||
# Import the SQL file
|
||||
if docker-compose -f "$COMPOSE_FILE" exec -T db mysql -u "$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" < "$SQL_FILE"; then
|
||||
print_success "Database imported successfully!"
|
||||
else
|
||||
print_error "Failed to import database!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run Laravel migrations (if needed)
|
||||
run_migrations() {
|
||||
print_status "Checking if Laravel migrations need to be run..."
|
||||
|
||||
if docker-compose -f "$COMPOSE_FILE" exec app php artisan migrate:status > /dev/null 2>&1; then
|
||||
print_status "Running any pending migrations..."
|
||||
docker-compose -f "$COMPOSE_FILE" exec app php artisan migrate --force
|
||||
else
|
||||
print_warning "Could not check migration status. Skipping migrations."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to clear Laravel cache
|
||||
clear_cache() {
|
||||
print_status "Clearing Laravel cache..."
|
||||
docker-compose -f "$COMPOSE_FILE" exec app php artisan cache:clear || true
|
||||
docker-compose -f "$COMPOSE_FILE" exec app php artisan config:clear || true
|
||||
docker-compose -f "$COMPOSE_FILE" exec app php artisan view:clear || true
|
||||
}
|
||||
|
||||
# Main execution
|
||||
print_status "Database Import Script for CKB Laravel Application"
|
||||
print_status "Environment: $ENVIRONMENT"
|
||||
print_status "SQL File: $SQL_FILE"
|
||||
echo ""
|
||||
|
||||
# Check prerequisites
|
||||
check_sql_file
|
||||
get_db_credentials
|
||||
check_containers
|
||||
|
||||
# Ask for confirmation
|
||||
echo ""
|
||||
print_warning "This will replace the existing database in $ENVIRONMENT environment!"
|
||||
read -p "Are you sure you want to continue? (y/N): " -n 1 -r
|
||||
echo ""
|
||||
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_status "Import cancelled."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Execute import
|
||||
backup_existing_db
|
||||
import_database
|
||||
|
||||
# Post-import tasks
|
||||
print_status "Running post-import tasks..."
|
||||
run_migrations
|
||||
clear_cache
|
||||
|
||||
echo ""
|
||||
print_success "Database import completed successfully!"
|
||||
print_status "Database: $DB_NAME"
|
||||
print_status "Environment: $ENVIRONMENT"
|
||||
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
echo ""
|
||||
print_status "You can now access your application at:"
|
||||
echo " - Web App: http://localhost:8000"
|
||||
echo " - phpMyAdmin: http://localhost:8080"
|
||||
fi
|
||||
@@ -1,254 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Quick Setup Script untuk CKB Laravel Application dengan Auto Import Database
|
||||
# Usage: ./docker-quick-setup.sh [dev|prod]
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Default values
|
||||
ENVIRONMENT="dev"
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
dev|development)
|
||||
ENVIRONMENT="dev"
|
||||
shift
|
||||
;;
|
||||
prod|production|staging)
|
||||
ENVIRONMENT="prod"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
echo "Usage: $0 [dev|prod]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to check if Docker is running
|
||||
check_docker() {
|
||||
if ! docker info > /dev/null 2>&1; then
|
||||
print_error "Docker is not running. Please start Docker first."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to setup environment file
|
||||
setup_env() {
|
||||
if [[ ! -f .env ]]; then
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
if [[ -f docker/env.example.local ]]; then
|
||||
print_status "Setting up local development environment file..."
|
||||
cp docker/env.example.local .env
|
||||
print_success "Local environment file created: .env"
|
||||
else
|
||||
print_error "Local environment template not found: docker/env.example.local"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [[ -f docker/env.example.production ]]; then
|
||||
print_status "Setting up production environment file..."
|
||||
cp docker/env.example.production .env
|
||||
print_success "Production environment file created: .env"
|
||||
print_warning "⚠️ IMPORTANT: Edit .env and change all CHANGE_THIS_* passwords!"
|
||||
else
|
||||
print_error "Production environment template not found: docker/env.example.production"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
print_status "Environment file already exists: .env"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to check if database file exists
|
||||
check_db_file() {
|
||||
if [[ ! -f ckb.sql ]]; then
|
||||
print_error "Database backup file 'ckb.sql' not found!"
|
||||
print_status "Please make sure you have the ckb.sql file in the project root."
|
||||
exit 1
|
||||
fi
|
||||
print_status "Found database backup: ckb.sql ($(du -h ckb.sql | cut -f1))"
|
||||
}
|
||||
|
||||
# Function to start containers
|
||||
start_containers() {
|
||||
print_status "Starting Docker containers for $ENVIRONMENT environment..."
|
||||
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
print_status "This will start development environment with:"
|
||||
echo " - MySQL with auto-import from ckb.sql"
|
||||
echo " - Redis for caching"
|
||||
echo " - phpMyAdmin for database management"
|
||||
echo " - MailHog for email testing"
|
||||
echo ""
|
||||
|
||||
docker-compose up -d --build
|
||||
|
||||
print_success "Development containers started!"
|
||||
echo ""
|
||||
print_status "Services are starting up... Please wait..."
|
||||
|
||||
# Wait for MySQL to be ready
|
||||
print_status "Waiting for MySQL to be ready..."
|
||||
sleep 20
|
||||
|
||||
# Wait a bit more for MySQL to be fully ready
|
||||
sleep 10
|
||||
|
||||
# Check if database was imported automatically
|
||||
if docker-compose exec -T db mysql -u root -proot -e "USE ckb_db; SHOW TABLES;" > /dev/null 2>&1; then
|
||||
table_count=$(docker-compose exec -T db mysql -u root -proot -e "USE ckb_db; SHOW TABLES;" 2>/dev/null | wc -l)
|
||||
if [[ $table_count -gt 1 ]]; then
|
||||
print_success "Database automatically imported from ckb.sql!"
|
||||
else
|
||||
print_warning "Database not imported automatically. Running manual import..."
|
||||
./docker-import-db.sh dev
|
||||
fi
|
||||
else
|
||||
print_warning "Database not accessible. Running manual import..."
|
||||
sleep 15
|
||||
./docker-import-db.sh dev
|
||||
fi
|
||||
|
||||
else
|
||||
print_status "Starting production environment..."
|
||||
if [[ ! -f .env.production ]]; then
|
||||
print_warning "Creating production environment file..."
|
||||
cp docker/env.example .env.production
|
||||
print_warning "Please edit .env.production with your production settings!"
|
||||
fi
|
||||
|
||||
docker-compose -f docker-compose.prod.yml up -d --build
|
||||
print_success "Production containers started!"
|
||||
|
||||
sleep 15
|
||||
print_status "Importing database for production..."
|
||||
./docker-import-db.sh prod
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to generate application key
|
||||
generate_app_key() {
|
||||
print_status "Generating Laravel application key..."
|
||||
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
docker-compose exec app php artisan key:generate
|
||||
else
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan key:generate
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run Laravel setup commands
|
||||
setup_laravel() {
|
||||
print_status "Setting up Laravel application..."
|
||||
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
COMPOSE_CMD="docker-compose exec app"
|
||||
else
|
||||
COMPOSE_CMD="docker-compose -f docker-compose.prod.yml exec app"
|
||||
fi
|
||||
|
||||
# Clear caches
|
||||
$COMPOSE_CMD php artisan cache:clear || true
|
||||
$COMPOSE_CMD php artisan config:clear || true
|
||||
$COMPOSE_CMD php artisan view:clear || true
|
||||
|
||||
# Set up storage links
|
||||
$COMPOSE_CMD php artisan storage:link || true
|
||||
|
||||
if [[ $ENVIRONMENT == "prod" ]]; then
|
||||
print_status "Optimizing for production..."
|
||||
$COMPOSE_CMD php artisan config:cache
|
||||
$COMPOSE_CMD php artisan route:cache
|
||||
$COMPOSE_CMD php artisan view:cache
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to show access information
|
||||
show_access_info() {
|
||||
echo ""
|
||||
print_success "🎉 CKB Laravel Application is now ready!"
|
||||
echo ""
|
||||
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
print_status "Development Environment Access:"
|
||||
echo " 🌐 Web Application: http://localhost:8000"
|
||||
echo " 📊 phpMyAdmin: http://localhost:8080"
|
||||
echo " - Server: db"
|
||||
echo " - Username: root"
|
||||
echo " - Password: root"
|
||||
echo " - Database: ckb_db"
|
||||
echo ""
|
||||
echo " 📧 MailHog (Email Testing): http://localhost:8025"
|
||||
echo " 🗄️ MySQL Direct: localhost:3306"
|
||||
echo " 🔴 Redis: localhost:6379"
|
||||
echo ""
|
||||
print_status "Useful Commands:"
|
||||
echo " - View logs: docker-compose logs -f"
|
||||
echo " - Access container: docker-compose exec app bash"
|
||||
echo " - Laravel commands: docker-compose exec app php artisan [command]"
|
||||
echo " - Stop containers: docker-compose down"
|
||||
else
|
||||
print_status "Production Environment Access:"
|
||||
echo " 🌐 Web Application: http://localhost (port 80)"
|
||||
echo " 🗄️ Database: localhost:3306"
|
||||
echo ""
|
||||
print_status "Useful Commands:"
|
||||
echo " - View logs: docker-compose -f docker-compose.prod.yml logs -f"
|
||||
echo " - Access container: docker-compose -f docker-compose.prod.yml exec app bash"
|
||||
echo " - Stop containers: docker-compose -f docker-compose.prod.yml down"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
print_status "Database has been imported from ckb.sql successfully!"
|
||||
}
|
||||
|
||||
# Main execution
|
||||
echo "================================================"
|
||||
print_status "🚀 CKB Laravel Application Quick Setup"
|
||||
print_status "Environment: $ENVIRONMENT"
|
||||
echo "================================================"
|
||||
echo ""
|
||||
|
||||
# Check prerequisites
|
||||
check_docker
|
||||
check_db_file
|
||||
|
||||
# Setup process
|
||||
setup_env
|
||||
start_containers
|
||||
generate_app_key
|
||||
setup_laravel
|
||||
|
||||
# Show final information
|
||||
show_access_info
|
||||
|
||||
echo ""
|
||||
print_success "✅ Quick setup completed successfully!"
|
||||
@@ -1,231 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script untuk rebuild Docker containers dari scratch
|
||||
# Usage: ./docker-rebuild.sh [dev|prod]
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Default values
|
||||
ENVIRONMENT="dev"
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
dev|development)
|
||||
ENVIRONMENT="dev"
|
||||
shift
|
||||
;;
|
||||
prod|production|staging)
|
||||
ENVIRONMENT="prod"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
echo "Usage: $0 [dev|prod]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to check if Docker is running
|
||||
check_docker() {
|
||||
if ! docker info > /dev/null 2>&1; then
|
||||
print_error "Docker is not running. Please start Docker first."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to clean up existing containers and images
|
||||
cleanup_containers() {
|
||||
print_status "Cleaning up existing containers and images..."
|
||||
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
COMPOSE_FILE="docker-compose.yml"
|
||||
APP_CONTAINER="ckb-app-dev"
|
||||
else
|
||||
COMPOSE_FILE="docker-compose.prod.yml"
|
||||
APP_CONTAINER="ckb-app-prod"
|
||||
fi
|
||||
|
||||
# Stop and remove containers
|
||||
print_status "Stopping containers..."
|
||||
docker-compose -f "$COMPOSE_FILE" down || true
|
||||
|
||||
# Remove specific containers if they exist
|
||||
if docker ps -a --format "table {{.Names}}" | grep -q "$APP_CONTAINER"; then
|
||||
print_status "Removing existing app container..."
|
||||
docker rm -f "$APP_CONTAINER" || true
|
||||
fi
|
||||
|
||||
# Remove images related to this project
|
||||
print_status "Removing existing images..."
|
||||
docker images | grep "ckb" | awk '{print $3}' | xargs docker rmi -f || true
|
||||
|
||||
print_success "Cleanup completed!"
|
||||
}
|
||||
|
||||
# Function to prune Docker system
|
||||
prune_docker() {
|
||||
print_status "Pruning Docker system to free up space..."
|
||||
|
||||
# Remove unused containers, networks, images
|
||||
docker system prune -f
|
||||
|
||||
# Remove unused volumes (be careful with this)
|
||||
print_warning "Removing unused Docker volumes..."
|
||||
docker volume prune -f
|
||||
|
||||
print_success "Docker system pruned!"
|
||||
}
|
||||
|
||||
# Function to build containers
|
||||
build_containers() {
|
||||
print_status "Building containers for $ENVIRONMENT environment..."
|
||||
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
print_status "Building development container..."
|
||||
docker-compose build --no-cache --pull
|
||||
print_success "Development container built successfully!"
|
||||
else
|
||||
print_status "Building production container..."
|
||||
docker-compose -f docker-compose.prod.yml build --no-cache --pull
|
||||
print_success "Production container built successfully!"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to test build
|
||||
test_build() {
|
||||
print_status "Testing the build..."
|
||||
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
COMPOSE_FILE="docker-compose.yml"
|
||||
else
|
||||
COMPOSE_FILE="docker-compose.prod.yml"
|
||||
fi
|
||||
|
||||
# Start containers to test
|
||||
print_status "Starting containers for testing..."
|
||||
docker-compose -f "$COMPOSE_FILE" up -d
|
||||
|
||||
# Wait for containers to be ready
|
||||
print_status "Waiting for containers to be ready..."
|
||||
sleep 15
|
||||
|
||||
# Test PHP version and extensions
|
||||
print_status "Testing PHP and extensions..."
|
||||
if docker-compose -f "$COMPOSE_FILE" exec -T app php -v; then
|
||||
print_success "PHP is working!"
|
||||
else
|
||||
print_error "PHP test failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test PHP extensions
|
||||
print_status "Checking PHP extensions..."
|
||||
docker-compose -f "$COMPOSE_FILE" exec -T app php -m | grep -E "(curl|gd|zip|dom|mysql|redis)" || true
|
||||
|
||||
# Test Redis connection
|
||||
print_status "Testing Redis connection..."
|
||||
if docker-compose -f "$COMPOSE_FILE" exec -T app php -r "try { \$redis = new Redis(); \$redis->connect('redis', 6379); echo 'OK'; } catch (Exception \$e) { echo 'FAILED'; }" | grep -q "OK"; then
|
||||
print_success "Redis connection test passed!"
|
||||
else
|
||||
print_warning "Redis connection test failed!"
|
||||
fi
|
||||
|
||||
# Test Laravel
|
||||
if docker-compose -f "$COMPOSE_FILE" exec -T app php artisan --version; then
|
||||
print_success "Laravel is working!"
|
||||
else
|
||||
print_error "Laravel test failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_success "Build test completed successfully!"
|
||||
}
|
||||
|
||||
# Function to show next steps
|
||||
show_next_steps() {
|
||||
echo ""
|
||||
print_success "🎉 Rebuild completed successfully!"
|
||||
echo ""
|
||||
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
print_status "Development environment is ready!"
|
||||
echo ""
|
||||
print_status "Next steps:"
|
||||
echo " 1. Import your database:"
|
||||
echo " ./docker-import-db.sh dev"
|
||||
echo ""
|
||||
echo " 2. Access your application:"
|
||||
echo " - Web App: http://localhost:8000"
|
||||
echo " - phpMyAdmin: http://localhost:8080"
|
||||
echo ""
|
||||
echo " 3. Or use quick setup:"
|
||||
echo " ./docker-quick-setup.sh dev"
|
||||
else
|
||||
print_status "Production environment is ready!"
|
||||
echo ""
|
||||
print_status "Next steps:"
|
||||
echo " 1. Import your database:"
|
||||
echo " ./docker-import-db.sh prod"
|
||||
echo ""
|
||||
echo " 2. Access your application:"
|
||||
echo " - Web App: http://localhost"
|
||||
fi
|
||||
}
|
||||
|
||||
# Main execution
|
||||
echo "================================================"
|
||||
print_status "🔄 Docker Clean Rebuild Script"
|
||||
print_status "Environment: $ENVIRONMENT"
|
||||
echo "================================================"
|
||||
echo ""
|
||||
|
||||
# Ask for confirmation
|
||||
print_warning "This will remove all existing containers, images, and volumes!"
|
||||
print_warning "Any data not backed up will be lost!"
|
||||
read -p "Are you sure you want to continue? (y/N): " -n 1 -r
|
||||
echo ""
|
||||
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_status "Rebuild cancelled."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check prerequisites
|
||||
check_docker
|
||||
|
||||
# Execute rebuild process
|
||||
cleanup_containers
|
||||
prune_docker
|
||||
build_containers
|
||||
test_build
|
||||
|
||||
# Show final information
|
||||
show_next_steps
|
||||
|
||||
print_success "✅ Clean rebuild completed successfully!"
|
||||
@@ -1,233 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script untuk setup environment file
|
||||
# Usage: ./docker-setup-env.sh [local|production]
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Default environment
|
||||
ENVIRONMENT="local"
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
local|dev|development)
|
||||
ENVIRONMENT="local"
|
||||
shift
|
||||
;;
|
||||
prod|production)
|
||||
ENVIRONMENT="production"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
echo "Usage: $0 [local|production]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to backup existing .env
|
||||
backup_existing_env() {
|
||||
if [[ -f .env ]]; then
|
||||
local backup_name=".env.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
print_status "Backing up existing .env to $backup_name"
|
||||
cp .env "$backup_name"
|
||||
print_success "Backup created: $backup_name"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to setup local environment
|
||||
setup_local_env() {
|
||||
print_status "Setting up LOCAL development environment..."
|
||||
|
||||
if [[ -f docker/env.example.local ]]; then
|
||||
backup_existing_env
|
||||
cp docker/env.example.local .env
|
||||
print_success "✅ Local environment file created!"
|
||||
echo ""
|
||||
print_status "Local Development Configuration:"
|
||||
echo " 🌐 App URL: http://localhost:8000"
|
||||
echo " 🗄️ Database: ckb_db (MySQL)"
|
||||
echo " 📧 Mail: MailHog (http://localhost:8025)"
|
||||
echo " 🔴 Redis: Session & Cache"
|
||||
echo " 🐛 Debug: Enabled"
|
||||
echo ""
|
||||
print_status "Services will be available at:"
|
||||
echo " - Web App: http://localhost:8000"
|
||||
echo " - phpMyAdmin: http://localhost:8080"
|
||||
echo " - MailHog: http://localhost:8025"
|
||||
echo ""
|
||||
print_success "Ready for local development! Run: ./docker-quick-setup.sh dev"
|
||||
else
|
||||
print_error "Local environment template not found: docker/env.example.local"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to setup production environment
|
||||
setup_production_env() {
|
||||
print_status "Setting up PRODUCTION environment..."
|
||||
|
||||
if [[ -f docker/env.example.production ]]; then
|
||||
backup_existing_env
|
||||
cp docker/env.example.production .env
|
||||
print_success "✅ Production environment file created!"
|
||||
echo ""
|
||||
print_warning "🚨 SECURITY CONFIGURATION REQUIRED!"
|
||||
echo ""
|
||||
print_status "You MUST change these settings in .env file:"
|
||||
echo " 🔐 DB_PASSWORD=CHANGE_THIS_SECURE_PASSWORD"
|
||||
echo " 🔐 DB_ROOT_PASSWORD=CHANGE_THIS_ROOT_PASSWORD"
|
||||
echo " 🔐 REDIS_PASSWORD=CHANGE_THIS_REDIS_PASSWORD"
|
||||
echo ""
|
||||
print_status "Optional but recommended configurations:"
|
||||
echo " 📧 MAIL_HOST, MAIL_USERNAME, MAIL_PASSWORD"
|
||||
echo " ☁️ AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY (for S3)"
|
||||
echo " 📡 PUSHER_* settings (for real-time features)"
|
||||
echo ""
|
||||
print_status "Production Configuration:"
|
||||
echo " 🌐 App URL: https://bengkel.digitaloasis.xyz"
|
||||
echo " 🗄️ Database: ckb_production (MySQL)"
|
||||
echo " 📧 Mail: SMTP (configure in .env)"
|
||||
echo " 🔴 Redis: Session, Cache & Queue"
|
||||
echo " 🐛 Debug: Disabled"
|
||||
echo " 🔒 SSL: Let's Encrypt"
|
||||
echo ""
|
||||
print_warning "Next steps:"
|
||||
echo "1. Edit .env file and change all CHANGE_THIS_* values"
|
||||
echo "2. Run: ./docker-deploy-prod.sh deploy"
|
||||
echo "3. Run: ./docker-deploy-prod.sh ssl"
|
||||
else
|
||||
print_error "Production environment template not found: docker/env.example.production"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to show current environment info
|
||||
show_current_env() {
|
||||
if [[ -f .env ]]; then
|
||||
print_status "Current Environment Information:"
|
||||
echo ""
|
||||
|
||||
# Detect environment type
|
||||
local app_env=$(grep "^APP_ENV=" .env | cut -d '=' -f2)
|
||||
local app_url=$(grep "^APP_URL=" .env | cut -d '=' -f2)
|
||||
local app_debug=$(grep "^APP_DEBUG=" .env | cut -d '=' -f2)
|
||||
local db_host=$(grep "^DB_HOST=" .env | cut -d '=' -f2)
|
||||
local db_name=$(grep "^DB_DATABASE=" .env | cut -d '=' -f2)
|
||||
|
||||
echo " Environment: $app_env"
|
||||
echo " App URL: $app_url"
|
||||
echo " Debug Mode: $app_debug"
|
||||
echo " Database Host: $db_host"
|
||||
echo " Database Name: $db_name"
|
||||
echo ""
|
||||
|
||||
# Check for security issues in production
|
||||
if [[ "$app_env" == "production" ]]; then
|
||||
print_status "Security Check:"
|
||||
if grep -q "CHANGE_THIS" .env; then
|
||||
print_error "❌ Found CHANGE_THIS_* values in production .env!"
|
||||
print_warning "Please update all CHANGE_THIS_* values with secure passwords."
|
||||
else
|
||||
print_success "✅ No CHANGE_THIS_* values found."
|
||||
fi
|
||||
|
||||
if [[ "$app_debug" == "true" ]]; then
|
||||
print_error "❌ Debug mode is enabled in production!"
|
||||
print_warning "Set APP_DEBUG=false for production."
|
||||
else
|
||||
print_success "✅ Debug mode is disabled."
|
||||
fi
|
||||
fi
|
||||
else
|
||||
print_status "No .env file found."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to validate environment file
|
||||
validate_env() {
|
||||
if [[ ! -f .env ]]; then
|
||||
print_error "No .env file found!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
print_status "Validating environment file..."
|
||||
|
||||
# Required variables
|
||||
local required_vars=("APP_NAME" "APP_ENV" "APP_URL" "DB_HOST" "DB_DATABASE" "DB_USERNAME" "DB_PASSWORD")
|
||||
local missing_vars=()
|
||||
|
||||
for var in "${required_vars[@]}"; do
|
||||
if ! grep -q "^${var}=" .env; then
|
||||
missing_vars+=("$var")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#missing_vars[@]} -gt 0 ]]; then
|
||||
print_error "Missing required environment variables:"
|
||||
for var in "${missing_vars[@]}"; do
|
||||
echo " - $var"
|
||||
done
|
||||
return 1
|
||||
fi
|
||||
|
||||
print_success "✅ Environment file validation passed!"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Main execution
|
||||
echo "================================================"
|
||||
print_status "🔧 CKB Environment Setup Helper"
|
||||
print_status "Target Environment: $ENVIRONMENT"
|
||||
echo "================================================"
|
||||
echo ""
|
||||
|
||||
case $ENVIRONMENT in
|
||||
local)
|
||||
setup_local_env
|
||||
;;
|
||||
production)
|
||||
setup_production_env
|
||||
;;
|
||||
esac
|
||||
|
||||
echo ""
|
||||
print_status "Environment file setup completed!"
|
||||
echo ""
|
||||
|
||||
# Show current environment info
|
||||
show_current_env
|
||||
|
||||
echo ""
|
||||
print_status "Available commands:"
|
||||
echo " - Show current env: ./docker-setup-env.sh"
|
||||
echo " - Setup local: ./docker-setup-env.sh local"
|
||||
echo " - Setup production: ./docker-setup-env.sh production"
|
||||
echo " - Quick local setup: ./docker-quick-setup.sh dev"
|
||||
echo " - Production deploy: ./docker-deploy-prod.sh deploy"
|
||||
@@ -1,283 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script untuk setup SSL certificate dengan Let's Encrypt untuk domain bengkel.digitaloasis.xyz
|
||||
# Usage: ./docker-ssl-setup.sh
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Configuration
|
||||
DOMAIN="bengkel.digitaloasis.xyz"
|
||||
WWW_DOMAIN="www.bengkel.digitaloasis.xyz"
|
||||
EMAIL="admin@digitaloasis.xyz"
|
||||
COMPOSE_FILE="docker-compose.prod.yml"
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to check if Docker is running
|
||||
check_docker() {
|
||||
if ! docker info > /dev/null 2>&1; then
|
||||
print_error "Docker is not running. Please start Docker first."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to check if domain is pointing to this server
|
||||
check_domain() {
|
||||
print_status "Checking if domain $DOMAIN is pointing to this server..."
|
||||
|
||||
# Get current server IP
|
||||
SERVER_IP=$(curl -s ifconfig.me || curl -s icanhazip.com || echo "Unable to detect")
|
||||
|
||||
# Get domain IP
|
||||
DOMAIN_IP=$(dig +short $DOMAIN | head -n1)
|
||||
|
||||
print_status "Server IP: $SERVER_IP"
|
||||
print_status "Domain IP: $DOMAIN_IP"
|
||||
|
||||
if [[ "$SERVER_IP" != "$DOMAIN_IP" ]]; then
|
||||
print_warning "Domain might not be pointing to this server!"
|
||||
print_warning "Please make sure DNS is configured correctly before proceeding."
|
||||
read -p "Continue anyway? (y/N): " -n 1 -r
|
||||
echo ""
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_status "SSL setup cancelled."
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
print_success "Domain is correctly pointing to this server!"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to create temporary nginx config for initial certificate
|
||||
create_temp_nginx() {
|
||||
print_status "Creating temporary nginx configuration for initial certificate..."
|
||||
|
||||
cat > docker/nginx-temp.conf << 'EOF'
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
server {
|
||||
listen 80;
|
||||
server_name bengkel.digitaloasis.xyz www.bengkel.digitaloasis.xyz;
|
||||
|
||||
location /.well-known/acme-challenge/ {
|
||||
root /var/www/certbot;
|
||||
}
|
||||
|
||||
location / {
|
||||
return 200 'SSL setup in progress...';
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
# Function to start nginx with temporary config
|
||||
start_temp_nginx() {
|
||||
print_status "Starting nginx with temporary configuration..."
|
||||
|
||||
# Update docker-compose to use temporary config
|
||||
sed -i 's|nginx-proxy.conf|nginx-temp.conf|g' $COMPOSE_FILE
|
||||
|
||||
# Start nginx-proxy
|
||||
docker-compose -f $COMPOSE_FILE up -d nginx-proxy
|
||||
|
||||
# Wait for nginx to be ready
|
||||
sleep 10
|
||||
}
|
||||
|
||||
# Function to obtain SSL certificate
|
||||
obtain_certificate() {
|
||||
print_status "Obtaining SSL certificate from Let's Encrypt..."
|
||||
|
||||
# Run certbot
|
||||
docker-compose -f $COMPOSE_FILE run --rm certbot certonly \
|
||||
--webroot \
|
||||
--webroot-path=/var/www/certbot \
|
||||
--email $EMAIL \
|
||||
--agree-tos \
|
||||
--no-eff-email \
|
||||
--force-renewal \
|
||||
-d $DOMAIN \
|
||||
-d $WWW_DOMAIN
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
print_success "SSL certificate obtained successfully!"
|
||||
else
|
||||
print_error "Failed to obtain SSL certificate!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to setup certificate files
|
||||
setup_certificate_files() {
|
||||
print_status "Setting up certificate files for nginx..."
|
||||
|
||||
# Copy certificates to nginx ssl directory
|
||||
docker run --rm \
|
||||
-v ckb_ssl_certificates:/source \
|
||||
-v ckb_ssl_certificates:/target \
|
||||
alpine sh -c "
|
||||
mkdir -p /target/live/$DOMAIN
|
||||
cp -L /source/live/$DOMAIN/fullchain.pem /target/fullchain.pem
|
||||
cp -L /source/live/$DOMAIN/privkey.pem /target/privkey.pem
|
||||
chmod 644 /target/fullchain.pem
|
||||
chmod 600 /target/privkey.pem
|
||||
"
|
||||
|
||||
print_success "Certificate files setup completed!"
|
||||
}
|
||||
|
||||
# Function to restore production nginx config
|
||||
restore_production_config() {
|
||||
print_status "Restoring production nginx configuration..."
|
||||
|
||||
# Restore original config
|
||||
sed -i 's|nginx-temp.conf|nginx-proxy.conf|g' $COMPOSE_FILE
|
||||
|
||||
# Restart nginx with SSL configuration
|
||||
docker-compose -f $COMPOSE_FILE up -d nginx-proxy
|
||||
|
||||
print_success "Production nginx configuration restored!"
|
||||
}
|
||||
|
||||
# Function to test SSL certificate
|
||||
test_ssl() {
|
||||
print_status "Testing SSL certificate..."
|
||||
|
||||
sleep 10
|
||||
|
||||
# Test HTTPS connection
|
||||
if curl -s --max-time 10 https://$DOMAIN > /dev/null; then
|
||||
print_success "HTTPS is working correctly!"
|
||||
else
|
||||
print_warning "HTTPS test failed. Please check the configuration."
|
||||
fi
|
||||
|
||||
# Test certificate validity
|
||||
if openssl s_client -connect $DOMAIN:443 -servername $DOMAIN < /dev/null 2>/dev/null | openssl x509 -noout -dates; then
|
||||
print_success "Certificate information retrieved successfully!"
|
||||
else
|
||||
print_warning "Could not retrieve certificate information."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to setup certificate renewal
|
||||
setup_renewal() {
|
||||
print_status "Setting up automatic certificate renewal..."
|
||||
|
||||
# Create renewal script
|
||||
cat > docker-ssl-renew.sh << 'EOF'
|
||||
#!/bin/bash
|
||||
|
||||
# SSL Certificate Renewal Script
|
||||
# Add this to crontab: 0 12 * * * /path/to/docker-ssl-renew.sh
|
||||
|
||||
docker-compose -f docker-compose.prod.yml run --rm certbot renew --quiet
|
||||
|
||||
# Reload nginx if certificate was renewed
|
||||
if [[ $? -eq 0 ]]; then
|
||||
# Copy renewed certificates
|
||||
docker run --rm \
|
||||
-v ckb_ssl_certificates:/source \
|
||||
-v ckb_ssl_certificates:/target \
|
||||
alpine sh -c "
|
||||
cp -L /source/live/bengkel.digitaloasis.xyz/fullchain.pem /target/fullchain.pem
|
||||
cp -L /source/live/bengkel.digitaloasis.xyz/privkey.pem /target/privkey.pem
|
||||
"
|
||||
|
||||
# Reload nginx
|
||||
docker-compose -f docker-compose.prod.yml exec nginx-proxy nginx -s reload
|
||||
fi
|
||||
EOF
|
||||
|
||||
chmod +x docker-ssl-renew.sh
|
||||
|
||||
print_success "Certificate renewal script created: docker-ssl-renew.sh"
|
||||
print_status "To setup automatic renewal, add this to crontab:"
|
||||
echo "0 12 * * * $(pwd)/docker-ssl-renew.sh"
|
||||
}
|
||||
|
||||
# Function to show final information
|
||||
show_final_info() {
|
||||
echo ""
|
||||
print_success "🎉 SSL setup completed successfully!"
|
||||
echo ""
|
||||
print_status "Your application is now available at:"
|
||||
echo " 🌐 https://bengkel.digitaloasis.xyz"
|
||||
echo " 🌐 https://www.bengkel.digitaloasis.xyz"
|
||||
echo ""
|
||||
print_status "SSL Certificate Information:"
|
||||
echo " 📅 Domain: $DOMAIN, $WWW_DOMAIN"
|
||||
echo " 📧 Email: $EMAIL"
|
||||
echo " 🔄 Auto-renewal: Setup docker-ssl-renew.sh in crontab"
|
||||
echo ""
|
||||
print_status "Useful Commands:"
|
||||
echo " - Check certificate: openssl s_client -connect $DOMAIN:443 -servername $DOMAIN"
|
||||
echo " - Renew certificate: ./docker-ssl-renew.sh"
|
||||
echo " - View logs: docker-compose -f $COMPOSE_FILE logs nginx-proxy"
|
||||
echo " - Test renewal: docker-compose -f $COMPOSE_FILE run --rm certbot renew --dry-run"
|
||||
}
|
||||
|
||||
# Main execution
|
||||
echo "================================================"
|
||||
print_status "🔒 SSL Certificate Setup for CKB Production"
|
||||
print_status "Domain: $DOMAIN"
|
||||
echo "================================================"
|
||||
echo ""
|
||||
|
||||
# Check prerequisites
|
||||
check_docker
|
||||
check_domain
|
||||
|
||||
# Ask for confirmation
|
||||
print_warning "This will setup SSL certificate for $DOMAIN"
|
||||
print_status "Make sure your application is not currently running."
|
||||
read -p "Continue with SSL setup? (y/N): " -n 1 -r
|
||||
echo ""
|
||||
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_status "SSL setup cancelled."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Execute SSL setup
|
||||
print_status "Starting SSL certificate setup process..."
|
||||
|
||||
create_temp_nginx
|
||||
start_temp_nginx
|
||||
obtain_certificate
|
||||
setup_certificate_files
|
||||
restore_production_config
|
||||
test_ssl
|
||||
setup_renewal
|
||||
|
||||
# Show final information
|
||||
show_final_info
|
||||
|
||||
print_success "✅ SSL setup completed successfully!"
|
||||
218
docker-start.sh
218
docker-start.sh
@@ -1,218 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script untuk menjalankan CKB Laravel Application dengan Docker
|
||||
# Usage: ./docker-start.sh [dev|prod] [up|down|build|logs]
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Default values
|
||||
ENVIRONMENT="dev"
|
||||
ACTION="up"
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
dev|development)
|
||||
ENVIRONMENT="dev"
|
||||
shift
|
||||
;;
|
||||
prod|production|staging)
|
||||
ENVIRONMENT="prod"
|
||||
shift
|
||||
;;
|
||||
up|start)
|
||||
ACTION="up"
|
||||
shift
|
||||
;;
|
||||
down|stop)
|
||||
ACTION="down"
|
||||
shift
|
||||
;;
|
||||
build)
|
||||
ACTION="build"
|
||||
shift
|
||||
;;
|
||||
logs)
|
||||
ACTION="logs"
|
||||
shift
|
||||
;;
|
||||
restart)
|
||||
ACTION="restart"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to check if Docker is running
|
||||
check_docker() {
|
||||
if ! docker info > /dev/null 2>&1; then
|
||||
print_error "Docker is not running. Please start Docker first."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to setup environment file
|
||||
setup_env() {
|
||||
if [[ ! -f .env ]]; then
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
if [[ -f docker/env.example.local ]]; then
|
||||
print_status "Copying local environment file..."
|
||||
cp docker/env.example.local .env
|
||||
print_success "Local development environment configured"
|
||||
else
|
||||
print_error "Local environment template not found: docker/env.example.local"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [[ -f docker/env.example.production ]]; then
|
||||
print_status "Copying production environment file..."
|
||||
cp docker/env.example.production .env
|
||||
print_warning "⚠️ IMPORTANT: Edit .env and change all CHANGE_THIS_* passwords!"
|
||||
print_warning "Please configure production settings before continuing"
|
||||
else
|
||||
print_error "Production environment template not found: docker/env.example.production"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to generate application key
|
||||
generate_key() {
|
||||
if ! grep -q "APP_KEY=base64:" .env; then
|
||||
print_status "Generating Laravel application key..."
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
docker-compose exec app php artisan key:generate || true
|
||||
else
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan key:generate || true
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run migrations
|
||||
run_migrations() {
|
||||
print_status "Running database migrations..."
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
docker-compose exec app php artisan migrate --force
|
||||
else
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan migrate --force
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to optimize for production
|
||||
optimize_production() {
|
||||
if [[ $ENVIRONMENT == "prod" ]]; then
|
||||
print_status "Optimizing for production..."
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan config:cache
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan route:cache
|
||||
docker-compose -f docker-compose.prod.yml exec app php artisan view:cache
|
||||
fi
|
||||
}
|
||||
|
||||
# Main execution
|
||||
print_status "Starting CKB Laravel Application with Docker"
|
||||
print_status "Environment: $ENVIRONMENT"
|
||||
print_status "Action: $ACTION"
|
||||
|
||||
# Check prerequisites
|
||||
check_docker
|
||||
|
||||
case $ACTION in
|
||||
up|start)
|
||||
setup_env
|
||||
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
print_status "Starting development environment..."
|
||||
docker-compose up -d --build
|
||||
print_success "Development environment started!"
|
||||
echo ""
|
||||
print_status "Access your application at:"
|
||||
echo " - Web App: http://localhost:8000"
|
||||
echo " - phpMyAdmin: http://localhost:8080"
|
||||
echo " - MailHog: http://localhost:8025"
|
||||
else
|
||||
print_status "Starting production environment..."
|
||||
docker-compose -f docker-compose.prod.yml up -d --build
|
||||
print_success "Production environment started!"
|
||||
echo ""
|
||||
print_status "Application is running on port 80"
|
||||
fi
|
||||
|
||||
# Wait for containers to be ready
|
||||
sleep 10
|
||||
|
||||
generate_key
|
||||
run_migrations
|
||||
optimize_production
|
||||
;;
|
||||
|
||||
down|stop)
|
||||
print_status "Stopping containers..."
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
docker-compose down
|
||||
else
|
||||
docker-compose -f docker-compose.prod.yml down
|
||||
fi
|
||||
print_success "Containers stopped!"
|
||||
;;
|
||||
|
||||
build)
|
||||
print_status "Building containers..."
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
docker-compose build --no-cache
|
||||
else
|
||||
docker-compose -f docker-compose.prod.yml build --no-cache
|
||||
fi
|
||||
print_success "Build completed!"
|
||||
;;
|
||||
|
||||
logs)
|
||||
print_status "Showing logs..."
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
docker-compose logs -f
|
||||
else
|
||||
docker-compose -f docker-compose.prod.yml logs -f
|
||||
fi
|
||||
;;
|
||||
|
||||
restart)
|
||||
print_status "Restarting containers..."
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
docker-compose restart
|
||||
else
|
||||
docker-compose -f docker-compose.prod.yml restart
|
||||
fi
|
||||
print_success "Containers restarted!"
|
||||
;;
|
||||
esac
|
||||
|
||||
echo ""
|
||||
print_success "Operation completed successfully!"
|
||||
@@ -1,240 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script untuk test Redis functionality di Docker environment
|
||||
# Usage: ./docker-test-redis.sh [dev|prod]
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Default values
|
||||
ENVIRONMENT="dev"
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
dev|development)
|
||||
ENVIRONMENT="dev"
|
||||
shift
|
||||
;;
|
||||
prod|production|staging)
|
||||
ENVIRONMENT="prod"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
echo "Usage: $0 [dev|prod]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to get compose file
|
||||
get_compose_file() {
|
||||
if [[ $ENVIRONMENT == "dev" ]]; then
|
||||
COMPOSE_FILE="docker-compose.yml"
|
||||
else
|
||||
COMPOSE_FILE="docker-compose.prod.yml"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to check if containers are running
|
||||
check_containers() {
|
||||
if ! docker-compose -f "$COMPOSE_FILE" ps | grep -q "redis.*Up"; then
|
||||
print_error "Redis container is not running!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! docker-compose -f "$COMPOSE_FILE" ps | grep -q "app.*Up"; then
|
||||
print_error "App container is not running!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to test PHP Redis extension
|
||||
test_redis_extension() {
|
||||
print_status "Testing PHP Redis extension..."
|
||||
|
||||
if docker-compose -f "$COMPOSE_FILE" exec -T app php -m | grep -q "redis"; then
|
||||
print_success "PHP Redis extension is installed"
|
||||
else
|
||||
print_error "PHP Redis extension is NOT installed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to test Redis server connection
|
||||
test_redis_connection() {
|
||||
print_status "Testing Redis server connection..."
|
||||
|
||||
# Test direct connection to Redis container
|
||||
if docker-compose -f "$COMPOSE_FILE" exec -T redis redis-cli ping | grep -q "PONG"; then
|
||||
print_success "Redis server is responding"
|
||||
else
|
||||
print_error "Redis server is not responding"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Test connection from PHP
|
||||
if docker-compose -f "$COMPOSE_FILE" exec -T app php -r "
|
||||
try {
|
||||
\$redis = new Redis();
|
||||
\$redis->connect('redis', 6379);
|
||||
echo 'OK';
|
||||
} catch (Exception \$e) {
|
||||
echo 'FAILED: ' . \$e->getMessage();
|
||||
}
|
||||
" | grep -q "OK"; then
|
||||
print_success "PHP Redis connection working"
|
||||
else
|
||||
print_error "PHP Redis connection failed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to test Laravel cache with Redis
|
||||
test_laravel_cache() {
|
||||
print_status "Testing Laravel cache with Redis..."
|
||||
|
||||
# Test cache clear
|
||||
if docker-compose -f "$COMPOSE_FILE" exec -T app php artisan cache:clear > /dev/null 2>&1; then
|
||||
print_success "Laravel cache clear working"
|
||||
else
|
||||
print_warning "Laravel cache clear failed"
|
||||
fi
|
||||
|
||||
# Test cache set/get
|
||||
local test_key="test_$(date +%s)"
|
||||
local test_value="redis_test_value"
|
||||
|
||||
if docker-compose -f "$COMPOSE_FILE" exec -T app php artisan tinker --execute="
|
||||
Cache::put('$test_key', '$test_value', 60);
|
||||
echo Cache::get('$test_key');
|
||||
" | grep -q "$test_value"; then
|
||||
print_success "Laravel cache operations working"
|
||||
else
|
||||
print_error "Laravel cache operations failed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to test Redis session storage
|
||||
test_redis_sessions() {
|
||||
print_status "Testing Redis session configuration..."
|
||||
|
||||
# Check session driver in config
|
||||
local session_driver=$(docker-compose -f "$COMPOSE_FILE" exec -T app php -r "echo config('session.driver');")
|
||||
|
||||
if [[ "$session_driver" == "redis" ]]; then
|
||||
print_success "Laravel sessions configured to use Redis"
|
||||
else
|
||||
print_warning "Laravel sessions not using Redis (current: $session_driver)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to test Redis queue configuration
|
||||
test_redis_queue() {
|
||||
print_status "Testing Redis queue configuration..."
|
||||
|
||||
# Check queue driver in config
|
||||
local queue_driver=$(docker-compose -f "$COMPOSE_FILE" exec -T app php -r "echo config('queue.default');")
|
||||
|
||||
if [[ "$queue_driver" == "redis" ]]; then
|
||||
print_success "Laravel queue configured to use Redis"
|
||||
else
|
||||
print_warning "Laravel queue not using Redis (current: $queue_driver)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to show Redis info
|
||||
show_redis_info() {
|
||||
print_status "Redis server information:"
|
||||
echo ""
|
||||
|
||||
docker-compose -f "$COMPOSE_FILE" exec redis redis-cli info server | head -10
|
||||
echo ""
|
||||
|
||||
print_status "Redis memory usage:"
|
||||
docker-compose -f "$COMPOSE_FILE" exec redis redis-cli info memory | grep used_memory_human
|
||||
echo ""
|
||||
|
||||
print_status "Redis connected clients:"
|
||||
docker-compose -f "$COMPOSE_FILE" exec redis redis-cli info clients | grep connected_clients
|
||||
}
|
||||
|
||||
# Function to show Laravel configuration
|
||||
show_laravel_config() {
|
||||
print_status "Laravel Redis configuration:"
|
||||
echo ""
|
||||
|
||||
print_status "Cache driver:"
|
||||
docker-compose -f "$COMPOSE_FILE" exec -T app php -r "echo 'CACHE_DRIVER=' . config('cache.default') . PHP_EOL;"
|
||||
|
||||
print_status "Session driver:"
|
||||
docker-compose -f "$COMPOSE_FILE" exec -T app php -r "echo 'SESSION_DRIVER=' . config('session.driver') . PHP_EOL;"
|
||||
|
||||
print_status "Queue driver:"
|
||||
docker-compose -f "$COMPOSE_FILE" exec -T app php -r "echo 'QUEUE_CONNECTION=' . config('queue.default') . PHP_EOL;"
|
||||
|
||||
print_status "Redis host:"
|
||||
docker-compose -f "$COMPOSE_FILE" exec -T app php -r "echo 'REDIS_HOST=' . config('database.redis.default.host') . PHP_EOL;"
|
||||
}
|
||||
|
||||
# Main execution
|
||||
echo "================================================"
|
||||
print_status "🔴 Redis Functionality Test"
|
||||
print_status "Environment: $ENVIRONMENT"
|
||||
echo "================================================"
|
||||
echo ""
|
||||
|
||||
# Get compose file
|
||||
get_compose_file
|
||||
|
||||
# Check prerequisites
|
||||
check_containers
|
||||
|
||||
# Run tests
|
||||
print_status "Running Redis tests..."
|
||||
echo ""
|
||||
|
||||
test_redis_extension && echo ""
|
||||
test_redis_connection && echo ""
|
||||
test_laravel_cache && echo ""
|
||||
test_redis_sessions && echo ""
|
||||
test_redis_queue && echo ""
|
||||
|
||||
# Show information
|
||||
show_redis_info
|
||||
echo ""
|
||||
show_laravel_config
|
||||
|
||||
echo ""
|
||||
print_success "✅ Redis functionality test completed!"
|
||||
|
||||
print_status "🔧 Troubleshooting commands:"
|
||||
echo " - Redis logs: docker-compose -f $COMPOSE_FILE logs redis"
|
||||
echo " - App logs: docker-compose -f $COMPOSE_FILE logs app"
|
||||
echo " - Redis CLI: docker-compose -f $COMPOSE_FILE exec redis redis-cli"
|
||||
echo " - Test cache: docker-compose -f $COMPOSE_FILE exec app php artisan cache:clear"
|
||||
@@ -1,257 +0,0 @@
|
||||
# Audit Histori Stock
|
||||
|
||||
## Deskripsi
|
||||
|
||||
Fitur Audit Histori Stock memungkinkan untuk melacak semua perubahan stock yang terjadi di sistem. Setiap kali ada perubahan stock (penambahan, pengurangan, penyesuaian), sistem akan mencatat detail perubahan tersebut untuk keperluan audit.
|
||||
|
||||
## Fitur Utama
|
||||
|
||||
### 1. Tracking Otomatis
|
||||
|
||||
- Sistem otomatis mencatat setiap perubahan stock
|
||||
- Mencatat stock sebelum dan sesudah perubahan
|
||||
- Mencatat sumber perubahan (mutasi, opname, dll)
|
||||
- Mencatat user yang melakukan perubahan
|
||||
- Mencatat timestamp perubahan
|
||||
|
||||
### 2. Filter dan Pencarian
|
||||
|
||||
- Filter berdasarkan dealer
|
||||
- Filter berdasarkan produk
|
||||
- Filter berdasarkan jenis perubahan
|
||||
- Filter berdasarkan tanggal
|
||||
- Pencarian realtime pada semua kolom
|
||||
|
||||
### 3. Detail Audit
|
||||
|
||||
- Informasi lengkap perubahan stock
|
||||
- Detail sumber perubahan (mutasi/opname)
|
||||
- History user yang melakukan aksi
|
||||
- Catatan dan keterangan perubahan
|
||||
|
||||
### 4. Export Data
|
||||
|
||||
- Export ke Excel
|
||||
- Export ke PDF
|
||||
- Data yang diekspor dapat disesuaikan
|
||||
|
||||
## Jenis Perubahan Stock
|
||||
|
||||
### 1. Penambahan (Increase)
|
||||
|
||||
- Stock bertambah dari transaksi
|
||||
- Biasanya dari mutasi masuk atau opname correction
|
||||
|
||||
### 2. Pengurangan (Decrease)
|
||||
|
||||
- Stock berkurang dari transaksi
|
||||
- Biasanya dari mutasi keluar atau penjualan
|
||||
|
||||
### 3. Penyesuaian (Adjustment)
|
||||
|
||||
- Penyesuaian stock dari opname
|
||||
- Koreksi stock manual
|
||||
|
||||
### 4. Tidak Ada Perubahan (No Change)
|
||||
|
||||
- Record dibuat tapi tidak ada perubahan quantity
|
||||
- Biasanya untuk tracking purpose
|
||||
|
||||
## Cara Menggunakan
|
||||
|
||||
### 1. Akses Menu
|
||||
|
||||
```
|
||||
Warehouse -> Stock Audit
|
||||
```
|
||||
|
||||
### 2. Menggunakan Filter
|
||||
|
||||
```javascript
|
||||
// Filter dealer
|
||||
$("#filter-dealer").val("Nama Dealer");
|
||||
|
||||
// Filter produk
|
||||
$("#filter-product").val("Nama Produk");
|
||||
|
||||
// Filter jenis perubahan
|
||||
$("#filter-change-type").val("increase"); // increase, decrease, adjustment, no_change
|
||||
|
||||
// Filter tanggal
|
||||
$("#filter-date").val("2024-01-15");
|
||||
|
||||
// Reset semua filter
|
||||
$("#reset-filters").click();
|
||||
```
|
||||
|
||||
### 3. Melihat Detail
|
||||
|
||||
```javascript
|
||||
// Klik tombol Detail pada baris data
|
||||
showAuditDetail(stockLogId);
|
||||
```
|
||||
|
||||
## Setup dan Instalasi
|
||||
|
||||
### 1. Setup Menu dan Privileges
|
||||
|
||||
```bash
|
||||
php artisan setup:stock-audit-menu
|
||||
```
|
||||
|
||||
### 2. Atau Menggunakan Seeder
|
||||
|
||||
```bash
|
||||
php artisan db:seed --class=StockAuditMenuSeeder
|
||||
```
|
||||
|
||||
## Struktur Data
|
||||
|
||||
### Model yang Terlibat
|
||||
|
||||
- **StockLog**: Record audit perubahan stock
|
||||
- **Stock**: Data stock utama
|
||||
- **Product**: Data produk
|
||||
- **Dealer**: Data dealer
|
||||
- **User**: Data user
|
||||
- **Mutation**: Data mutasi stock
|
||||
- **StockOpname**: Data opname stock
|
||||
|
||||
### Relasi Database
|
||||
|
||||
```php
|
||||
StockLog belongsTo Stock
|
||||
StockLog belongsTo User
|
||||
StockLog morphTo Source (Mutation, StockOpname, etc)
|
||||
Stock belongsTo Product
|
||||
Stock belongsTo Dealer
|
||||
```
|
||||
|
||||
## API Endpoints
|
||||
|
||||
### 1. Index (List Data)
|
||||
|
||||
```
|
||||
GET /warehouse/stock-audit
|
||||
```
|
||||
|
||||
### 2. Detail Audit
|
||||
|
||||
```
|
||||
GET /warehouse/stock-audit/{stockLog}/detail
|
||||
```
|
||||
|
||||
## Kustomisasi
|
||||
|
||||
### 1. Menambah Jenis Perubahan
|
||||
|
||||
Edit enum `StockChangeType`:
|
||||
|
||||
```php
|
||||
// app/Enums/StockChangeType.php
|
||||
case NEW_TYPE = 'new_type';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
// ... existing cases
|
||||
self::NEW_TYPE => 'Label Baru',
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Menambah Filter Custom
|
||||
|
||||
Edit controller dan view untuk menambah filter baru:
|
||||
|
||||
```php
|
||||
// Controller
|
||||
->filterColumn('new_field', function($query, $keyword) {
|
||||
$query->where('new_field', 'like', "%{$keyword}%");
|
||||
})
|
||||
|
||||
// View
|
||||
<select class="form-select" id="filter-new-field">
|
||||
<option value="">Semua</option>
|
||||
// ... options
|
||||
</select>
|
||||
```
|
||||
|
||||
### 3. Kustomisasi Export
|
||||
|
||||
Edit DataTables buttons untuk menyesuaikan kolom export:
|
||||
|
||||
```javascript
|
||||
exportOptions: {
|
||||
columns: [1, 2, 3, 4, 5, 6, 7, 8]; // Sesuaikan kolom yang ingin diekspor
|
||||
}
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### 1. Menu Tidak Muncul
|
||||
|
||||
- Pastikan menu sudah di-setup dengan benar
|
||||
- Cek privileges user untuk menu stock-audit.index
|
||||
- Cek role user memiliki akses view = 1
|
||||
|
||||
### 2. Data Tidak Muncul
|
||||
|
||||
- Cek apakah ada data StockLog di database
|
||||
- Cek filter yang aktive
|
||||
- Cek permission user untuk melihat data dealer tertentu
|
||||
|
||||
### 3. Detail Tidak Loading
|
||||
|
||||
- Cek URL endpoint `/warehouse/stock-audit/{id}/detail`
|
||||
- Cek network tab di browser untuk error response
|
||||
- Cek log Laravel untuk error detail
|
||||
|
||||
## Keamanan
|
||||
|
||||
### 1. Filter Berdasarkan Role
|
||||
|
||||
- User dengan `dealer_id` hanya melihat data dealer mereka
|
||||
- Admin dapat melihat semua data
|
||||
|
||||
### 2. View-Only Access
|
||||
|
||||
- Menu ini adalah read-only
|
||||
- Tidak ada aksi create, update, atau delete
|
||||
- Hanya viewing dan export yang diizinkan
|
||||
|
||||
### 3. Audit Trail
|
||||
|
||||
- Setiap akses audit log dapat di-track
|
||||
- User activity dapat dimonitor
|
||||
- Data tidak dapat dimanipulasi
|
||||
|
||||
## Performance Tips
|
||||
|
||||
### 1. Index Database
|
||||
|
||||
Pastikan ada index pada kolom yang sering difilter:
|
||||
|
||||
```sql
|
||||
-- Index untuk performance
|
||||
CREATE INDEX idx_stock_logs_created_at ON stock_logs(created_at);
|
||||
CREATE INDEX idx_stock_logs_change_type ON stock_logs(change_type);
|
||||
CREATE INDEX idx_stock_logs_stock_id ON stock_logs(stock_id);
|
||||
```
|
||||
|
||||
### 2. Pagination
|
||||
|
||||
- DataTables menggunakan server-side processing
|
||||
- Default page length: 25 records
|
||||
- Dapat disesuaikan sesuai kebutuhan
|
||||
|
||||
### 3. Caching
|
||||
|
||||
Jika data sangat besar, pertimbangkan untuk menambah caching:
|
||||
|
||||
```php
|
||||
// Cache dealer dan product data
|
||||
$dealers = Cache::remember('dealers_for_audit', 3600, function () {
|
||||
return Dealer::all();
|
||||
});
|
||||
```
|
||||
@@ -1,297 +0,0 @@
|
||||
# Work Products & Stock Management System
|
||||
|
||||
## Overview
|
||||
|
||||
Sistem ini memungkinkan setiap pekerjaan (work) memiliki relasi dengan banyak produk (products) dan otomatis mengurangi stock di dealer ketika transaksi pekerjaan dilakukan.
|
||||
|
||||
## Fitur Utama
|
||||
|
||||
### 1. Work Products Management
|
||||
|
||||
- Setiap pekerjaan dapat dikonfigurasi untuk memerlukan produk tertentu
|
||||
- Admin dapat mengatur jumlah (quantity) produk yang dibutuhkan per pekerjaan
|
||||
- Mendukung catatan/notes untuk setiap produk
|
||||
|
||||
### 2. Automatic Stock Reduction
|
||||
|
||||
- Stock otomatis dikurangi ketika transaksi pekerjaan dibuat
|
||||
- Validasi stock tersedia sebelum transaksi disimpan
|
||||
- Stock dikembalikan ketika transaksi dihapus
|
||||
|
||||
### 3. Stock Validation & Warning
|
||||
|
||||
- Real-time checking stock availability saat memilih pekerjaan
|
||||
- Warning ketika stock tidak mencukupi
|
||||
- Konfirmasi user sebelum melanjutkan dengan stock negatif
|
||||
|
||||
### 4. Stock Prediction
|
||||
|
||||
- Melihat prediksi penggunaan stock untuk pekerjaan tertentu
|
||||
- Kalkulasi berdasarkan quantity pekerjaan yang akan dilakukan
|
||||
|
||||
## Database Schema
|
||||
|
||||
### Tabel `work_products`
|
||||
|
||||
```sql
|
||||
CREATE TABLE work_products (
|
||||
id BIGINT PRIMARY KEY,
|
||||
work_id BIGINT NOT NULL,
|
||||
product_id BIGINT NOT NULL,
|
||||
quantity_required DECIMAL(10,2) DEFAULT 1.00,
|
||||
notes TEXT NULL,
|
||||
created_at TIMESTAMP,
|
||||
updated_at TIMESTAMP,
|
||||
UNIQUE KEY unique_work_product (work_id, product_id),
|
||||
FOREIGN KEY (work_id) REFERENCES works(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE
|
||||
);
|
||||
```
|
||||
|
||||
### Model Relationships
|
||||
|
||||
#### Work Model
|
||||
|
||||
```php
|
||||
// Relasi many-to-many dengan Product
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class, 'work_products')
|
||||
->withPivot('quantity_required', 'notes')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
// Relasi one-to-many dengan WorkProduct
|
||||
public function workProducts()
|
||||
{
|
||||
return $this->hasMany(WorkProduct::class);
|
||||
}
|
||||
```
|
||||
|
||||
#### Product Model
|
||||
|
||||
```php
|
||||
// Relasi many-to-many dengan Work
|
||||
public function works()
|
||||
{
|
||||
return $this->belongsToMany(Work::class, 'work_products')
|
||||
->withPivot('quantity_required', 'notes')
|
||||
->withTimestamps();
|
||||
}
|
||||
```
|
||||
|
||||
## API Endpoints
|
||||
|
||||
### Work Products Management
|
||||
|
||||
```
|
||||
GET /admin/work/{work}/products - List work products
|
||||
POST /admin/work/{work}/products - Add product to work
|
||||
GET /admin/work/{work}/products/{id} - Show work product
|
||||
PUT /admin/work/{work}/products/{id} - Update work product
|
||||
DELETE /admin/work/{work}/products/{id} - Remove product from work
|
||||
```
|
||||
|
||||
### Stock Operations
|
||||
|
||||
```
|
||||
POST /transaction/check-stock - Check stock availability
|
||||
GET /transaction/stock-prediction - Get stock usage prediction
|
||||
GET /admin/work/{work}/stock-prediction - Get work stock prediction
|
||||
```
|
||||
|
||||
## StockService Methods
|
||||
|
||||
### `checkStockAvailability($workId, $dealerId, $workQuantity)`
|
||||
|
||||
Mengecek apakah dealer memiliki stock yang cukup untuk pekerjaan tertentu.
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `$workId`: ID pekerjaan
|
||||
- `$dealerId`: ID dealer
|
||||
- `$workQuantity`: Jumlah pekerjaan yang akan dilakukan
|
||||
|
||||
**Returns:**
|
||||
|
||||
```php
|
||||
[
|
||||
'available' => bool,
|
||||
'message' => string,
|
||||
'details' => [
|
||||
[
|
||||
'product_id' => int,
|
||||
'product_name' => string,
|
||||
'required_quantity' => float,
|
||||
'available_stock' => float,
|
||||
'is_available' => bool
|
||||
]
|
||||
]
|
||||
]
|
||||
```
|
||||
|
||||
### `reduceStockForTransaction($transaction)`
|
||||
|
||||
Mengurangi stock otomatis berdasarkan transaksi pekerjaan.
|
||||
|
||||
### `restoreStockForTransaction($transaction)`
|
||||
|
||||
Mengembalikan stock ketika transaksi dibatalkan/dihapus.
|
||||
|
||||
### `getStockUsagePrediction($workId, $quantity)`
|
||||
|
||||
Mendapatkan prediksi penggunaan stock untuk pekerjaan.
|
||||
|
||||
## User Interface
|
||||
|
||||
### 1. Work Products Management
|
||||
|
||||
- Akses melalui: **Admin Panel > Master > Pekerjaan > [Pilih Pekerjaan] > Tombol "Produk"**
|
||||
- Fitur:
|
||||
- Tambah/edit/hapus produk yang diperlukan
|
||||
- Set quantity required per produk
|
||||
- Tambah catatan untuk produk
|
||||
- Preview prediksi penggunaan stock
|
||||
|
||||
### 2. Transaction Form dengan Stock Warning
|
||||
|
||||
- Real-time stock checking saat memilih pekerjaan
|
||||
- Warning visual ketika stock tidak mencukupi
|
||||
- Konfirmasi sebelum submit dengan stock negatif
|
||||
|
||||
### 3. Stock Prediction Modal
|
||||
|
||||
- Kalkulasi total produk yang dibutuhkan
|
||||
- Informasi per produk dengan quantity dan satuan
|
||||
|
||||
## Usage Examples
|
||||
|
||||
### 1. Mengatur Produk untuk Pekerjaan "Service Rutin"
|
||||
|
||||
1. Masuk ke Admin Panel > Master > Pekerjaan
|
||||
2. Klik tombol "Produk" pada pekerjaan "Service Rutin"
|
||||
3. Klik "Tambah Produk"
|
||||
4. Pilih produk "Oli Mesin", set quantity 4, notes "4 liter untuk ganti oli"
|
||||
5. Tambah produk "Filter Oli", set quantity 1, notes "Filter standar"
|
||||
6. Simpan
|
||||
|
||||
### 2. Membuat Transaksi dengan Stock Warning
|
||||
|
||||
1. Pada form transaksi, pilih pekerjaan "Service Rutin"
|
||||
2. Set quantity 2 (untuk 2 kendaraan)
|
||||
3. Sistem akan menampilkan warning jika stock tidak cukup:
|
||||
- Oli Mesin: Butuh 8 liter, Tersedia 5 liter
|
||||
- Filter Oli: Butuh 2 unit, Tersedia 3 unit
|
||||
4. User dapat memilih untuk melanjutkan atau membatalkan
|
||||
|
||||
### 3. Melihat Prediksi Stock
|
||||
|
||||
1. Di halaman Work Products, klik "Prediksi Stock"
|
||||
2. Set jumlah pekerjaan (misal: 5)
|
||||
3. Sistem menampilkan:
|
||||
- Oli Mesin: 4 liter/pekerjaan × 5 = 20 liter total
|
||||
- Filter Oli: 1 unit/pekerjaan × 5 = 5 unit total
|
||||
|
||||
## Stock Flow Process
|
||||
|
||||
### Saat Transaksi Dibuat:
|
||||
|
||||
1. User memilih pekerjaan dan quantity
|
||||
2. Sistem check stock availability
|
||||
3. Jika stock tidak cukup, tampilkan warning
|
||||
4. User konfirmasi untuk melanjutkan
|
||||
5. Transaksi disimpan dengan status 'completed'
|
||||
6. Stock otomatis dikurangi sesuai konfigurasi work products
|
||||
|
||||
### Saat Transaksi Dihapus:
|
||||
|
||||
1. Sistem ambil data transaksi
|
||||
2. Kembalikan stock sesuai dengan produk yang digunakan
|
||||
3. Catat dalam stock log
|
||||
4. Hapus transaksi
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Stock Tidak Mencukupi:
|
||||
|
||||
- Tampilkan warning dengan detail produk
|
||||
- Izinkan user untuk melanjutkan dengan konfirmasi
|
||||
- Stock boleh menjadi negatif (business rule)
|
||||
|
||||
### Product Tidak Dikonfigurasi:
|
||||
|
||||
- Jika pekerjaan belum dikonfigurasi produknya, tidak ada pengurangan stock
|
||||
- Transaksi tetap bisa dibuat normal
|
||||
|
||||
### Database Transaction:
|
||||
|
||||
- Semua operasi stock menggunakan database transaction
|
||||
- Rollback otomatis jika ada error
|
||||
|
||||
## Best Practices
|
||||
|
||||
### 1. Konfigurasi Work Products
|
||||
|
||||
- Set quantity required yang akurat
|
||||
- Gunakan notes untuk informasi tambahan
|
||||
- Review berkala konfigurasi produk
|
||||
|
||||
### 2. Stock Management
|
||||
|
||||
- Monitor stock levels secara berkala
|
||||
- Set minimum stock alerts
|
||||
- Koordinasi dengan procurement team
|
||||
|
||||
### 3. Training User
|
||||
|
||||
- Berikan training tentang stock warnings
|
||||
- Edukasi tentang impact stock negatif
|
||||
- Prosedur escalation jika stock habis
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Stock Tidak Berkurang Otomatis:
|
||||
|
||||
1. Cek konfigurasi work products
|
||||
2. Pastikan produk memiliki stock record di dealer
|
||||
3. Check error logs
|
||||
|
||||
### Error Saat Submit Transaksi:
|
||||
|
||||
1. Refresh halaman dan coba lagi
|
||||
2. Check koneksi internet
|
||||
3. Contact admin jika masih error
|
||||
|
||||
### Stock Calculation Salah:
|
||||
|
||||
1. Review konfigurasi quantity di work products
|
||||
2. Check apakah ada duplikasi produk
|
||||
3. Verify stock log untuk audit trail
|
||||
|
||||
## Monitoring & Reporting
|
||||
|
||||
### Stock Logs
|
||||
|
||||
Semua perubahan stock tercatat dalam `stock_logs` table dengan informasi:
|
||||
|
||||
- Source transaction
|
||||
- Previous quantity
|
||||
- New quantity
|
||||
- Change amount
|
||||
- Timestamp
|
||||
- User who made the change
|
||||
|
||||
### Reports Available
|
||||
|
||||
- Stock usage by work type
|
||||
- Stock movement history
|
||||
- Negative stock alerts
|
||||
- Product consumption analysis
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
1. **Automated Stock Alerts**: Email notifications ketika stock di bawah minimum
|
||||
2. **Batch Operations**: Update multiple work products sekaligus
|
||||
3. **Stock Forecasting**: Prediksi kebutuhan stock berdasarkan historical data
|
||||
4. **Mobile Interface**: Mobile-friendly interface untuk stock checking
|
||||
5. **Integration**: Integration dengan sistem procurement/inventory external
|
||||
@@ -1,54 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "🔧 Fixing file permissions and ownership for Docker development..."
|
||||
|
||||
# Stop containers first
|
||||
echo "🛑 Stopping containers..."
|
||||
docker-compose down
|
||||
|
||||
# Fix ownership - change back to current user for development
|
||||
echo "👤 Fixing file ownership..."
|
||||
sudo chown -R $USER:$USER .
|
||||
|
||||
# Set proper permissions for Laravel
|
||||
echo "🔐 Setting Laravel permissions..."
|
||||
chmod -R 755 .
|
||||
chmod -R 775 storage bootstrap/cache
|
||||
chmod 644 .env
|
||||
|
||||
# Ensure public directory is readable
|
||||
chmod -R 755 public
|
||||
|
||||
# Fix specific file permissions
|
||||
chmod 644 public/index.php
|
||||
chmod 644 artisan
|
||||
chmod +x artisan
|
||||
|
||||
echo "📋 Current ownership:"
|
||||
ls -la public/index.php
|
||||
ls -la .env
|
||||
|
||||
# Restart containers
|
||||
echo "🚀 Starting containers..."
|
||||
docker-compose up -d
|
||||
|
||||
# Wait for containers to be ready
|
||||
echo "⏳ Waiting for containers..."
|
||||
sleep 10
|
||||
|
||||
# Test inside container
|
||||
echo "🧪 Testing file access in container..."
|
||||
docker exec ckb-app-dev ls -la /var/www/html/public/index.php
|
||||
|
||||
# Test HTTP access
|
||||
echo "🌐 Testing HTTP access..."
|
||||
sleep 5
|
||||
curl -I http://localhost:8000
|
||||
|
||||
echo ""
|
||||
echo "✅ Permission fix completed!"
|
||||
echo ""
|
||||
echo "If still having issues, try:"
|
||||
echo "1. Check container logs: docker logs ckb-app-dev"
|
||||
echo "2. Test PHP directly: docker exec ckb-app-dev php /var/www/html/public/index.php"
|
||||
echo "3. Check nginx config: docker exec ckb-app-dev nginx -t"
|
||||
33
quick-fix.sh
33
quick-fix.sh
@@ -1,33 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "⚡ Quick fix for Docker development..."
|
||||
|
||||
# Quick permission fix without stopping containers
|
||||
echo "🔐 Quick permission fix..."
|
||||
sudo chmod -R 755 public
|
||||
sudo chmod 644 public/index.php
|
||||
|
||||
# Test if container can read the file
|
||||
echo "🧪 Testing file access..."
|
||||
docker exec ckb-app-dev test -r /var/www/html/public/index.php && echo "✅ File is readable" || echo "❌ File not readable"
|
||||
|
||||
# Test PHP execution
|
||||
echo "🐘 Testing PHP execution..."
|
||||
docker exec ckb-app-dev php -v
|
||||
|
||||
# Test Laravel
|
||||
echo "🎯 Testing Laravel..."
|
||||
docker exec ckb-app-dev php /var/www/html/artisan --version
|
||||
|
||||
# Test HTTP
|
||||
echo "🌐 Testing HTTP..."
|
||||
curl -s -o /dev/null -w "HTTP Status: %{http_code}\n" http://localhost:8000
|
||||
|
||||
echo ""
|
||||
echo "🔍 Debug info:"
|
||||
echo "Host file: $(ls -la public/index.php)"
|
||||
echo "Container file:"
|
||||
docker exec ckb-app-dev ls -la /var/www/html/public/index.php
|
||||
|
||||
echo ""
|
||||
echo "If still not working, run: chmod +x fix-permissions.sh && ./fix-permissions.sh"
|
||||
127
restore_db.sh
127
restore_db.sh
@@ -1,127 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configuration
|
||||
CONTAINER_NAME="ckb-mysql-dev"
|
||||
DB_NAME="ckb_db"
|
||||
DB_USER="root"
|
||||
DB_PASSWORD="root"
|
||||
BACKUP_DIR="./backups"
|
||||
|
||||
# Function to show available backups
|
||||
show_backups() {
|
||||
echo "📁 Available backup files:"
|
||||
echo "----------------------------------------"
|
||||
ls -la "$BACKUP_DIR"/*.sql* 2>/dev/null | awk '{print NR ". " $9 " (" $5 " bytes, " $6 " " $7 " " $8 ")"}'
|
||||
}
|
||||
|
||||
# Function to restore database
|
||||
restore_database() {
|
||||
local backup_file="$1"
|
||||
|
||||
echo "🔄 Starting database restore..."
|
||||
echo "Container: $CONTAINER_NAME"
|
||||
echo "Database: $DB_NAME"
|
||||
echo "Backup file: $backup_file"
|
||||
|
||||
# Check if file exists
|
||||
if [[ ! -f "$backup_file" ]]; then
|
||||
echo "❌ Error: Backup file not found: $backup_file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if container is running
|
||||
if ! docker ps | grep -q $CONTAINER_NAME; then
|
||||
echo "❌ Error: Container $CONTAINER_NAME is not running!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ask for confirmation
|
||||
read -p "⚠️ This will overwrite the current database. Continue? (y/n): " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "🚫 Restore cancelled."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if file is compressed
|
||||
if [[ "$backup_file" == *.gz ]]; then
|
||||
echo "📦 Decompressing backup file..."
|
||||
if gunzip -c "$backup_file" | docker exec -i $CONTAINER_NAME mysql -u $DB_USER -p$DB_PASSWORD $DB_NAME; then
|
||||
echo "✅ Database restored successfully from compressed backup!"
|
||||
else
|
||||
echo "❌ Restore failed!"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "📥 Restoring from uncompressed backup..."
|
||||
if docker exec -i $CONTAINER_NAME mysql -u $DB_USER -p$DB_PASSWORD $DB_NAME < "$backup_file"; then
|
||||
echo "✅ Database restored successfully!"
|
||||
else
|
||||
echo "❌ Restore failed!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Main script
|
||||
echo "🗃️ CKB Database Restore Tool"
|
||||
echo "============================"
|
||||
|
||||
# Check if backup directory exists
|
||||
if [[ ! -d "$BACKUP_DIR" ]]; then
|
||||
echo "❌ Error: Backup directory not found: $BACKUP_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Show available backups
|
||||
show_backups
|
||||
|
||||
# Check if any backup files exist
|
||||
if ! ls "$BACKUP_DIR"/*.sql* 1> /dev/null 2>&1; then
|
||||
echo "❌ No backup files found in $BACKUP_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Options:"
|
||||
echo "1. Select backup file by number"
|
||||
echo "2. Enter custom backup file path"
|
||||
echo "3. Exit"
|
||||
echo
|
||||
|
||||
read -p "Choose option (1-3): " -n 1 -r option
|
||||
echo
|
||||
|
||||
case $option in
|
||||
1)
|
||||
echo "📋 Available backups:"
|
||||
backup_files=($(ls "$BACKUP_DIR"/*.sql* 2>/dev/null))
|
||||
for i in "${!backup_files[@]}"; do
|
||||
echo "$((i+1)). $(basename "${backup_files[$i]}")"
|
||||
done
|
||||
|
||||
read -p "Enter backup number: " backup_number
|
||||
|
||||
if [[ "$backup_number" =~ ^[0-9]+$ ]] && [[ "$backup_number" -ge 1 ]] && [[ "$backup_number" -le "${#backup_files[@]}" ]]; then
|
||||
selected_backup="${backup_files[$((backup_number-1))]}"
|
||||
restore_database "$selected_backup"
|
||||
else
|
||||
echo "❌ Invalid backup number!"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
read -p "Enter backup file path: " custom_backup
|
||||
restore_database "$custom_backup"
|
||||
;;
|
||||
3)
|
||||
echo "👋 Goodbye!"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "❌ Invalid option!"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "🎉 Restore process completed!"
|
||||
28
setup-env.sh
28
setup-env.sh
@@ -1,28 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# CKB Production Environment Setup Script
|
||||
echo "🔧 Setting up CKB Production Environment..."
|
||||
|
||||
# Check if .env file exists
|
||||
if [ -f ".env" ]; then
|
||||
echo "⚠️ .env file already exists. Creating backup..."
|
||||
cp .env .env.backup.$(date +%Y%m%d_%H%M%S)
|
||||
fi
|
||||
|
||||
# Copy from example
|
||||
echo "📋 Copying from production example..."
|
||||
cp docker/env.example.production .env
|
||||
|
||||
# Generate APP_KEY
|
||||
echo "🔑 Generating APP_KEY..."
|
||||
docker-compose -f docker-compose.prod.yml run --rm app php artisan key:generate --force
|
||||
|
||||
echo "✅ Environment setup completed!"
|
||||
echo ""
|
||||
echo "📝 Please edit .env file and update the following:"
|
||||
echo " - DB_PASSWORD (change from CHANGE_THIS_SECURE_PASSWORD)"
|
||||
echo " - DB_ROOT_PASSWORD (change from CHANGE_THIS_ROOT_PASSWORD)"
|
||||
echo " - REDIS_PASSWORD (change from CHANGE_THIS_REDIS_PASSWORD)"
|
||||
echo " - Mail configuration if needed"
|
||||
echo ""
|
||||
echo "🚀 After updating .env, run: ./deploy.sh"
|
||||
191
setup-ssl.sh
191
setup-ssl.sh
@@ -1,191 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# SSL Certificate Setup Script for CKB Application
|
||||
# This script sets up SSL certificate using Let's Encrypt
|
||||
|
||||
set -e
|
||||
|
||||
echo "=== SSL Certificate Setup for CKB Application ==="
|
||||
echo "Domain: bengkel.digitaloasis.xyz"
|
||||
echo ""
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if running as root
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
print_error "This script must be run as root (use sudo)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if certbot is installed
|
||||
if ! command -v certbot &> /dev/null; then
|
||||
print_status "Installing certbot..."
|
||||
apt update
|
||||
apt install -y certbot
|
||||
fi
|
||||
|
||||
# Check if nginx is installed
|
||||
if ! command -v nginx &> /dev/null; then
|
||||
print_error "Nginx is not installed. Please install Nginx first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Step 1: Create temporary Nginx configuration for Let's Encrypt challenge
|
||||
print_status "Creating temporary Nginx configuration for Let's Encrypt challenge..."
|
||||
|
||||
cat > /etc/nginx/sites-available/bengkel.digitaloasis.xyz << 'EOF'
|
||||
server {
|
||||
listen 80;
|
||||
server_name bengkel.digitaloasis.xyz www.bengkel.digitaloasis.xyz;
|
||||
|
||||
# Root directory untuk Let's Encrypt challenge
|
||||
root /var/www/html;
|
||||
|
||||
# Let's Encrypt challenge location
|
||||
location /.well-known/acme-challenge/ {
|
||||
root /var/www/html;
|
||||
}
|
||||
|
||||
# Redirect semua traffic HTTP ke HTTPS (akan diaktifkan setelah SSL)
|
||||
location / {
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Step 2: Enable the site
|
||||
print_status "Enabling Nginx site..."
|
||||
ln -sf /etc/nginx/sites-available/bengkel.digitaloasis.xyz /etc/nginx/sites-enabled/
|
||||
|
||||
# Step 3: Test and reload Nginx
|
||||
print_status "Testing Nginx configuration..."
|
||||
nginx -t
|
||||
|
||||
print_status "Reloading Nginx..."
|
||||
systemctl reload nginx
|
||||
|
||||
# Step 4: Generate SSL certificate
|
||||
print_status "Generating SSL certificate with Let's Encrypt..."
|
||||
certbot certonly --webroot \
|
||||
--webroot-path=/var/www/html \
|
||||
--email admin@digitaloasis.xyz \
|
||||
--agree-tos \
|
||||
--no-eff-email \
|
||||
-d bengkel.digitaloasis.xyz \
|
||||
-d www.bengkel.digitaloasis.xyz
|
||||
|
||||
# Step 5: Check if certificate was generated successfully
|
||||
if [ -f "/etc/letsencrypt/live/bengkel.digitaloasis.xyz/fullchain.pem" ]; then
|
||||
print_status "SSL certificate generated successfully!"
|
||||
else
|
||||
print_error "SSL certificate generation failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Step 6: Update Nginx configuration with SSL
|
||||
print_status "Updating Nginx configuration with SSL..."
|
||||
|
||||
cat > /etc/nginx/sites-available/bengkel.digitaloasis.xyz << 'EOF'
|
||||
# HTTP server (redirect to HTTPS)
|
||||
server {
|
||||
listen 80;
|
||||
server_name bengkel.digitaloasis.xyz www.bengkel.digitaloasis.xyz;
|
||||
|
||||
# Let's Encrypt challenge
|
||||
location /.well-known/acme-challenge/ {
|
||||
root /var/www/html;
|
||||
}
|
||||
|
||||
# Redirect to HTTPS
|
||||
location / {
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
}
|
||||
|
||||
# HTTPS server
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name bengkel.digitaloasis.xyz www.bengkel.digitaloasis.xyz;
|
||||
|
||||
# SSL configuration
|
||||
ssl_certificate /etc/letsencrypt/live/bengkel.digitaloasis.xyz/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/bengkel.digitaloasis.xyz/privkey.pem;
|
||||
|
||||
# SSL security settings
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384;
|
||||
ssl_prefer_server_ciphers off;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
|
||||
# Security headers
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
add_header X-Frame-Options DENY always;
|
||||
add_header X-Content-Type-Options nosniff always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
|
||||
# Proxy to Docker application on port 8082
|
||||
location / {
|
||||
proxy_pass http://localhost:8082;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $server_name;
|
||||
proxy_set_header X-Forwarded-Port $server_port;
|
||||
|
||||
# Proxy timeouts
|
||||
proxy_read_timeout 300;
|
||||
proxy_connect_timeout 300;
|
||||
proxy_send_timeout 300;
|
||||
|
||||
# Buffer settings
|
||||
proxy_buffering on;
|
||||
proxy_buffer_size 4k;
|
||||
proxy_buffers 8 4k;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Step 7: Test and reload Nginx
|
||||
print_status "Testing Nginx configuration with SSL..."
|
||||
nginx -t
|
||||
|
||||
print_status "Reloading Nginx with SSL configuration..."
|
||||
systemctl reload nginx
|
||||
|
||||
# Step 8: Setup auto-renewal
|
||||
print_status "Setting up SSL certificate auto-renewal..."
|
||||
(crontab -l 2>/dev/null; echo "0 12 * * * /usr/bin/certbot renew --quiet") | crontab -
|
||||
|
||||
# Step 9: Test SSL certificate
|
||||
print_status "Testing SSL certificate..."
|
||||
if curl -s -o /dev/null -w "%{http_code}" https://bengkel.digitaloasis.xyz | grep -q "200\|301\|302"; then
|
||||
print_status "SSL certificate is working correctly!"
|
||||
else
|
||||
print_warning "SSL certificate might not be working yet. Please check manually."
|
||||
fi
|
||||
|
||||
print_status "SSL certificate setup completed successfully!"
|
||||
echo ""
|
||||
print_status "Certificate information:"
|
||||
certbot certificates
|
||||
echo ""
|
||||
print_status "Your application should now be accessible at: https://bengkel.digitaloasis.xyz"
|
||||
Reference in New Issue
Block a user