#!/bin/bash # Script to reorganize infrastructure from old structure to new structure # This is a helper script to move files around set -e # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' RED='\033[0;31m' NC='\033[0m' log_info() { echo -e "${BLUE}ℹ️ $1${NC}" } log_success() { echo -e "${GREEN}✅ $1${NC}" } log_warning() { echo -e "${YELLOW}⚠️ $1${NC}" } log_error() { echo -e "${RED}❌ $1${NC}" } # Script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" INFRA_DIR="$(dirname "$SCRIPT_DIR")" PROJECT_ROOT="$(dirname "$INFRA_DIR")" log_info "Reorganizing infrastructure structure..." echo " Infra Dir: $INFRA_DIR" echo "" # Step 1: Create directory structure (already done by mkdir command) log_info "Step 1: Verifying directory structure..." if [ -d "$INFRA_DIR/base" ] && [ -d "$INFRA_DIR/environments" ]; then log_success "Directory structure exists" else log_error "Directory structure not found. Run: mkdir -p infra/{base,environments/{local,development,production},configs/{traefik,grafana,prometheus,loki,vault,authentik},certs/{local,development,production}}" exit 1 fi # Step 2: Move config files log_info "Step 2: Moving configuration files..." # Traefik configs if [ -d "$INFRA_DIR/traefik" ] && [ ! -f "$INFRA_DIR/configs/traefik/.moved" ]; then log_info " Moving Traefik configs..." cp -r "$INFRA_DIR/traefik/"* "$INFRA_DIR/configs/traefik/" 2>/dev/null || true touch "$INFRA_DIR/configs/traefik/.moved" log_success " Traefik configs moved" fi # Grafana configs if [ -d "$INFRA_DIR/grafana" ] && [ ! -f "$INFRA_DIR/configs/grafana/.moved" ]; then log_info " Moving Grafana configs..." cp -r "$INFRA_DIR/grafana/"* "$INFRA_DIR/configs/grafana/" 2>/dev/null || true touch "$INFRA_DIR/configs/grafana/.moved" log_success " Grafana configs moved" fi # Prometheus configs if [ -d "$INFRA_DIR/prometheus" ] && [ ! -f "$INFRA_DIR/configs/prometheus/.moved" ]; then log_info " Moving Prometheus configs..." cp -r "$INFRA_DIR/prometheus/"* "$INFRA_DIR/configs/prometheus/" 2>/dev/null || true touch "$INFRA_DIR/configs/prometheus/.moved" log_success " Prometheus configs moved" fi # Loki configs if [ -d "$INFRA_DIR/loki" ] && [ ! -f "$INFRA_DIR/configs/loki/.moved" ]; then log_info " Moving Loki configs..." cp -r "$INFRA_DIR/loki/"* "$INFRA_DIR/configs/loki/" 2>/dev/null || true touch "$INFRA_DIR/configs/loki/.moved" log_success " Loki configs moved" fi # Promtail configs if [ -d "$INFRA_DIR/promtail" ] && [ ! -f "$INFRA_DIR/configs/promtail/.moved" ]; then log_info " Moving Promtail configs..." mkdir -p "$INFRA_DIR/configs/promtail" cp -r "$INFRA_DIR/promtail/"* "$INFRA_DIR/configs/promtail/" 2>/dev/null || true touch "$INFRA_DIR/configs/promtail/.moved" log_success " Promtail configs moved" fi # Vault configs if [ -d "$INFRA_DIR/vault" ] && [ ! -f "$INFRA_DIR/configs/vault/.moved" ]; then log_info " Moving Vault configs..." cp -r "$INFRA_DIR/vault/"* "$INFRA_DIR/configs/vault/" 2>/dev/null || true touch "$INFRA_DIR/configs/vault/.moved" log_success " Vault configs moved" fi # Authentik configs if [ -d "$INFRA_DIR/authentik" ] && [ ! -f "$INFRA_DIR/configs/authentik/.moved" ]; then log_info " Moving Authentik configs..." cp -r "$INFRA_DIR/authentik/"* "$INFRA_DIR/configs/authentik/" 2>/dev/null || true touch "$INFRA_DIR/configs/authentik/.moved" log_success " Authentik configs moved" fi # Step 3: Move certificates log_info "Step 3: Moving certificates..." if [ -d "$INFRA_DIR/certs" ] && [ -f "$INFRA_DIR/certs/local.crt" ]; then log_info " Moving local certificates..." cp "$INFRA_DIR/certs/local.crt" "$INFRA_DIR/certs/local/" 2>/dev/null || true cp "$INFRA_DIR/certs/local.key" "$INFRA_DIR/certs/local/" 2>/dev/null || true log_success " Certificates moved" fi # Step 4: Update base compose files paths log_info "Step 4: Updating base compose file paths..." # Update infrastructure.yaml if [ -f "$INFRA_DIR/base/infrastructure.yaml" ]; then log_info " Updating infrastructure.yaml paths..." # This would require sed commands to update volume paths # For now, just log that manual update may be needed log_warning " Manual review recommended for volume paths" fi # Step 5: Create .gitignore for sensitive files log_info "Step 5: Creating .gitignore..." cat > "$INFRA_DIR/.gitignore" << 'EOF' # Environment files (contain secrets) environments/*/.env !environments/*/.env.example # Certificates certs/*/ !certs/.gitkeep # Traefik provider credentials configs/traefik/.provider.env # Backup files *.backup *.tmp # Docker volumes (if mounted locally) volumes/ # Logs *.log EOF log_success ".gitignore created" # Step 6: Create .gitkeep files log_info "Step 6: Creating .gitkeep files..." touch "$INFRA_DIR/certs/local/.gitkeep" touch "$INFRA_DIR/certs/development/.gitkeep" touch "$INFRA_DIR/certs/production/.gitkeep" log_success ".gitkeep files created" # Step 7: Summary echo "" log_success "Reorganization complete!" echo "" log_info "Next steps:" echo " 1. Review moved files in configs/ directory" echo " 2. Update compose file paths if needed" echo " 3. Create environment files:" echo " cp infra/environments/local/.env.example infra/environments/local/.env" echo " cp infra/environments/development/.env.example infra/environments/development/.env" echo " 4. Test deployment:" echo " ./infra/scripts/deploy.sh local infrastructure" echo "" log_warning "Old directories (traefik/, grafana/, etc.) are preserved for safety" log_warning "You can remove them after verifying the new structure works" echo ""