# Scripts Directory **Last Updated**: 2025-01-27 **Purpose**: Automation scripts for workspace integration and streamlining **Structure**: Modular organization with shared libraries --- ## 📁 Directory Structure ``` scripts/ ├── README.md # This file ├── lib/ # Shared libraries │ ├── common/ # Common utilities │ │ ├── colors.sh # Color definitions │ │ ├── logging.sh # Logging functions │ │ ├── utils.sh # Utility functions │ │ ├── validation.sh # Input validation │ │ └── error-handling.sh # Error handling │ ├── config/ # Configuration │ │ └── env.sh # Environment loading │ └── init.sh # Initialize all libraries ├── migration/ # Migration scripts │ ├── migrate-readme.sh │ ├── migrate-terraform.sh │ ├── migrate-to-api-gateway.sh │ ├── migrate-to-k8s.sh │ ├── migrate-to-monitoring.sh │ └── migrate-to-shared-packages.sh ├── metrics/ # Metrics scripts │ ├── collect/ # Collection scripts │ │ ├── collect-code-metrics.sh │ │ ├── collect-deployment-metrics.sh │ │ ├── collect-developer-metrics.sh │ │ ├── collect-infrastructure-metrics.sh │ │ ├── collect-operational-metrics.sh │ │ └── collect-service-metrics.sh │ ├── track-all-metrics.sh │ ├── track-success-metrics.sh │ ├── update-metrics.sh │ └── generate-metrics-report.sh ├── dbis/ # DBIS-specific scripts │ ├── automate-dbis-migration.sh │ ├── migrate-all-dbis-projects.sh │ ├── migrate-dbis-project.sh │ └── test-dbis-migration.sh ├── infrastructure/ # Infrastructure scripts │ ├── setup-shared-infrastructure.sh │ └── setup.sh └── utils/ # Utility scripts ├── analyze-costs.sh ├── optimize-builds.sh ├── deps-analyze.sh ├── deps-audit.sh ├── build-all.sh ├── test-all.sh ├── verify-all.sh └── cleanup.sh ``` --- ## 🚀 Quick Start ### Using Scripts All scripts can be run from the project root: ```bash # Migration scripts ./scripts/migration/migrate-to-k8s.sh my-project # Metrics scripts ./scripts/metrics/update-metrics.sh all # Infrastructure scripts ./scripts/infrastructure/setup.sh ``` ### Using Shared Libraries Scripts can use shared libraries by sourcing `lib/init.sh`: ```bash #!/bin/bash # Example script using shared libraries # Get script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Load all libraries source "$SCRIPT_DIR/../lib/init.sh" # Now you can use library functions log_info "Starting script..." require_command kubectl validate_project_name "$1" ``` --- ## 📚 Shared Libraries ### Common Utilities (`lib/common/`) #### `colors.sh` Color definitions for script output: ```bash source "$SCRIPT_DIR/../lib/common/colors.sh" echo -e "${GREEN}Success!${NC}" ``` #### `logging.sh` Logging functions with levels: ```bash source "$SCRIPT_DIR/../lib/common/logging.sh" log_info "Information message" log_error "Error message" log_warn "Warning message" log_debug "Debug message" ``` #### `utils.sh` Common utility functions: ```bash source "$SCRIPT_DIR/../lib/common/utils.sh" require_command kubectl ensure_dir "/tmp/my-dir" confirm "Continue?" ``` #### `validation.sh` Input validation functions: ```bash source "$SCRIPT_DIR/../lib/common/validation.sh" validate_project_name "my-project" validate_environment "production" validate_url "https://example.com" ``` #### `error-handling.sh` Error handling and cleanup: ```bash source "$SCRIPT_DIR/../lib/common/error-handling.sh" set_error_trap # Cleanup function will be called on error cleanup() { # Cleanup code } ``` ### Configuration (`lib/config/`) #### `env.sh` Environment variable loading: ```bash source "$SCRIPT_DIR/../lib/config/env.sh" load_env ".env" require_env "API_KEY" get_env "PORT" "8080" ``` ### Initialization (`lib/init.sh`) Load all libraries at once: ```bash source "$SCRIPT_DIR/../lib/init.sh" # All libraries are now available ``` --- ## 📖 Script Categories ### Migration Scripts (`migration/`) Scripts for migrating projects to shared infrastructure: - **migrate-to-k8s.sh** - Migrate to Kubernetes - **migrate-to-api-gateway.sh** - Migrate to API Gateway - **migrate-to-monitoring.sh** - Migrate to monitoring - **migrate-to-shared-packages.sh** - Migrate to shared packages - **migrate-terraform.sh** - Migrate Terraform modules - **migrate-readme.sh** - Update README files ### Metrics Scripts (`metrics/`) Scripts for collecting and tracking metrics: - **collect/** - Individual metric collection scripts - **track-all-metrics.sh** - Track all metrics - **update-metrics.sh** - Update metrics data - **generate-metrics-report.sh** - Generate reports ### DBIS Scripts (`dbis/`) DBIS-specific migration and testing scripts: - **automate-dbis-migration.sh** - Automate DBIS migration - **migrate-all-dbis-projects.sh** - Migrate all DBIS projects - **test-dbis-migration.sh** - Test DBIS migration ### Infrastructure Scripts (`infrastructure/`) Infrastructure setup and deployment scripts: - **setup-shared-infrastructure.sh** - Setup shared infrastructure - **setup.sh** - General setup script ### Utility Scripts (`utils/`) General utility scripts: - **analyze-costs.sh** - Cost analysis - **optimize-builds.sh** - Build optimization - **deps-analyze.sh** - Dependency analysis - **deps-audit.sh** - Dependency audit - **build-all.sh** - Build all projects - **test-all.sh** - Test all projects - **verify-all.sh** - Verify all projects - **cleanup.sh** - Cleanup scripts --- ## 🔧 Development Guidelines ### Creating New Scripts 1. **Use shared libraries**: ```bash source "$(dirname "$0")/../lib/init.sh" ``` 2. **Follow naming conventions**: - Use kebab-case: `my-script.sh` - Be descriptive: `migrate-to-k8s.sh` not `migrate.sh` 3. **Include help text**: ```bash if [ -z "$1" ]; then echo "Usage: $0 " exit 1 fi ``` 4. **Use logging functions**: ```bash log_info "Starting migration..." log_success "Migration complete!" ``` 5. **Validate inputs**: ```bash validate_project_name "$1" require_command kubectl ``` ### Best Practices - ✅ Use shared libraries for common functionality - ✅ Validate all inputs - ✅ Provide helpful error messages - ✅ Include usage/help text - ✅ Use logging instead of echo - ✅ Handle errors gracefully - ✅ Document complex logic --- ## 🔄 Migration from Old Structure Scripts are being migrated from the flat structure to the modular structure. For backward compatibility, wrapper scripts may exist in the root `scripts/` directory. ### Migration Status - ✅ Directory structure created - ✅ Shared libraries created - ⏳ Scripts being migrated (in progress) - ⏳ Documentation being updated --- ## 📚 Related Documentation - [Modularization Plan](./SCRIPTS_MODULARIZATION_PLAN.md) - [Integration Plan](../INTEGRATION_STREAMLINING_PLAN.md) - [Migration Guides](../docs/COMPLETE_MIGRATION_GUIDE.md) --- **Last Updated**: 2025-01-27