# Deployment Template
# Standardized template for application and system deployment across the AI Agentic Data Stack Framework

metadata:
  template_id: "deployment-tmpl"
  name: "Deployment Template"
  version: "1.0.0"
  description: "Comprehensive template for deploying applications and systems with CI/CD pipeline integration"
  category: "technical-implementation"
  tags: ["deployment", "cicd", "automation", "release", "infrastructure"]
  created_by: "AI Agentic Data Stack Framework"
  created_date: "2025-01-23"
template:
  name: "Deployment Template"
  description: "Template for deployment implementation and management"
  version: "1.0.0"


# Deployment Configuration
deployment_config:
  deployment_id: "${deployment_id}"
  deployment_name: "${deployment_name}"
  application_name: "${application_name}"
  version: "${deployment_version}"
  environment: "${target_environment}" # development, staging, production, disaster_recovery
  deployment_type: "${deployment_type}" # blue_green, rolling, canary, recreate

# Application Configuration
application_config:
  # Application Details
  application_details:
    application_id: "${application_id}"
    application_type: "${application_type}" # web_app, api, microservice, batch_job
    runtime_environment: "${runtime_environment}" # docker, kubernetes, serverless
    language_stack: "${language_stack}"
    
  # Build Configuration
  build_config:
    build_tool: "${build_tool}" # maven, gradle, npm, docker
    build_commands: ["${build_commands}"]
    build_artifacts: ["${build_artifacts}"]
    artifact_repository: "${artifact_repository_url}"
    
  # Dependencies
  dependencies:
    runtime_dependencies: ["${runtime_dependencies}"]
    external_services: ["${external_service_dependencies}"]
    database_dependencies: ["${database_dependencies}"]
    infrastructure_dependencies: ["${infrastructure_dependencies}"]

# Environment Configuration
environment_config:
  # Target Environment
  target_environment:
    environment_name: "${environment_name}"
    environment_type: "${environment_type}"
    region: "${deployment_region}"
    availability_zones: ["${deployment_availability_zones}"]
    
  # Infrastructure Resources
  infrastructure_resources:
    compute_resources:
      - resource_type: "${compute_resource_type}"
        instance_type: "${instance_type}"
        instance_count: ${instance_count}
        auto_scaling: ${auto_scaling_enabled}
        
    storage_resources:
      - storage_type: "${storage_type}"
        storage_size: "${storage_size}"
        storage_class: "${storage_class}"
        
    network_resources:
      vpc_id: "${vpc_id}"
      subnet_ids: ["${subnet_ids}"]
      security_groups: ["${security_group_ids}"]
      load_balancer: "${load_balancer_config}"

# Deployment Pipeline
deployment_pipeline:
  # Pipeline Configuration
  pipeline_config:
    pipeline_name: "${pipeline_name}"
    pipeline_tool: "${pipeline_tool}" # jenkins, gitlab_ci, github_actions, azure_devops
    trigger_type: "${pipeline_trigger}" # manual, automatic, scheduled
    
  # Pipeline Stages
  stages:
    # Source Stage
    source_stage:
      source_provider: "${source_provider}" # git, s3, codecommit
      repository_url: "${repository_url}"
      branch: "${source_branch}"
      trigger_events: ["${source_trigger_events}"]
      
    # Build Stage
    build_stage:
      build_provider: "${build_provider}"
      build_spec: "${build_spec_location}"
      build_environment: "${build_environment}"
      build_timeout: ${build_timeout_minutes}
      
    # Test Stage
    test_stage:
      test_types: ["${test_types}"] # unit, integration, security, performance
      test_commands: ["${test_commands}"]
      test_reports: ["${test_report_locations}"]
      quality_gates: ["${quality_gate_criteria}"]
      
    # Deploy Stage
    deploy_stage:
      deployment_provider: "${deployment_provider}"
      deployment_config: "${deployment_configuration}"
      deployment_timeout: ${deployment_timeout_minutes}
      rollback_enabled: ${rollback_enabled}

# Configuration Management
configuration_management:
  # Environment Variables
  environment_variables:
    - name: "${env_var_name}"
      value: "${env_var_value}"
      type: "${env_var_type}" # string, number, boolean, secret
      environment_specific: ${env_var_environment_specific}
      
  # Configuration Files
  configuration_files:
    - file_name: "${config_file_name}"
      file_path: "${config_file_path}"
      file_type: "${config_file_type}" # properties, yaml, json, xml
      template_location: "${config_template_location}"
      
  # Secrets Management
  secrets_management:
    secret_provider: "${secret_provider}" # aws_secrets, azure_keyvault, hashicorp_vault
    secrets:
      - secret_name: "${secret_name}"
        secret_key: "${secret_key}"
        rotation_enabled: ${secret_rotation_enabled}
        
  # Feature Flags
  feature_flags:
    feature_flag_provider: "${feature_flag_provider}"
    flags:
      - flag_name: "${feature_flag_name}"
        flag_description: "${feature_flag_description}"
        default_value: ${feature_flag_default}
        environment_overrides: ["${flag_environment_overrides}"]

# Deployment Strategies
deployment_strategies:
  # Blue-Green Deployment
  blue_green:
    enabled: ${blue_green_enabled}
    blue_environment: "${blue_environment_config}"
    green_environment: "${green_environment_config}"
    switch_strategy: "${blue_green_switch_strategy}"
    rollback_strategy: "${blue_green_rollback_strategy}"
    
  # Rolling Deployment
  rolling:
    enabled: ${rolling_deployment_enabled}
    batch_size: ${rolling_batch_size}
    max_unavailable: "${rolling_max_unavailable}"
    health_check_grace_period: ${rolling_health_check_grace_period}
    
  # Canary Deployment
  canary:
    enabled: ${canary_deployment_enabled}
    canary_percentage: ${canary_percentage}
    canary_duration: ${canary_duration_minutes}
    success_criteria: ["${canary_success_criteria}"]
    auto_promote: ${canary_auto_promote}

# Health Checks and Monitoring
health_monitoring:
  # Health Check Configuration
  health_checks:
    - check_name: "${health_check_name}"
      check_type: "${health_check_type}" # http, tcp, command
      endpoint: "${health_check_endpoint}"
      interval: ${health_check_interval_seconds}
      timeout: ${health_check_timeout_seconds}
      healthy_threshold: ${health_check_healthy_threshold}
      unhealthy_threshold: ${health_check_unhealthy_threshold}
      
  # Readiness Probes
  readiness_probes:
    - probe_name: "${readiness_probe_name}"
      probe_command: "${readiness_probe_command}"
      initial_delay: ${readiness_initial_delay_seconds}
      period: ${readiness_period_seconds}
      
  # Liveness Probes
  liveness_probes:
    - probe_name: "${liveness_probe_name}"
      probe_endpoint: "${liveness_probe_endpoint}"
      failure_threshold: ${liveness_failure_threshold}
      
  # Monitoring Integration
  monitoring_integration:
    metrics_endpoint: "${metrics_endpoint}"
    log_configuration: "${log_configuration}"
    tracing_enabled: ${distributed_tracing_enabled}
    alerting_rules: ["${deployment_alerting_rules}"]

# Security Configuration
security_config:
  # Network Security
  network_security:
    ssl_enabled: ${ssl_enabled}
    ssl_certificate: "${ssl_certificate_arn}"
    firewall_rules: ["${firewall_rules}"]
    network_policies: ["${network_policies}"]
    
  # Container Security
  container_security:
    image_scanning: ${container_image_scanning_enabled}
    vulnerability_threshold: "${vulnerability_threshold}"
    base_image: "${secure_base_image}"
    non_root_user: ${run_as_non_root}
    
  # Access Control
  access_control:
    rbac_enabled: ${rbac_enabled}
    service_account: "${service_account_name}"
    iam_roles: ["${iam_roles}"]
    access_policies: ["${access_policies}"]

# Database Migration
database_migration:
  # Migration Configuration
  migration_config:
    migration_enabled: ${database_migration_enabled}
    migration_tool: "${migration_tool}" # flyway, liquibase, alembic
    migration_scripts_location: "${migration_scripts_location}"
    
  # Migration Steps
  migration_steps:
    - step_name: "${migration_step_name}"
      step_order: ${migration_step_order}
      script_path: "${migration_script_path}"
      rollback_script: "${rollback_script_path}"
      validation_query: "${migration_validation_query}"
      
  # Migration Strategy
  migration_strategy:
    backup_before_migration: ${backup_before_migration}
    test_migration_first: ${test_migration_first}
    migration_timeout: ${migration_timeout_minutes}

# Performance Optimization
performance_optimization:
  # Resource Optimization
  resource_optimization:
    cpu_request: "${cpu_request}"
    cpu_limit: "${cpu_limit}"
    memory_request: "${memory_request}"
    memory_limit: "${memory_limit}"
    
  # Scaling Configuration
  scaling_config:
    horizontal_scaling:
      min_replicas: ${min_replicas}
      max_replicas: ${max_replicas}
      target_cpu_utilization: ${target_cpu_utilization}
      
    vertical_scaling:
      enabled: ${vertical_scaling_enabled}
      min_allowed: "${vertical_scaling_min}"
      max_allowed: "${vertical_scaling_max}"
      
  # Caching Configuration
  caching_config:
    application_cache: "${application_cache_config}"
    cdn_enabled: ${cdn_enabled}
    cache_headers: ["${cache_headers}"]

# Rollback Procedures
rollback_procedures:
  # Rollback Configuration
  rollback_config:
    rollback_enabled: ${rollback_enabled}
    automatic_rollback: ${automatic_rollback_enabled}
    rollback_triggers: ["${rollback_triggers}"]
    
  # Rollback Steps
  rollback_steps:
    - step_name: "${rollback_step_name}"
      step_order: ${rollback_step_order}
      step_command: "${rollback_step_command}"
      verification_command: "${rollback_verification_command}"
      
  # Recovery Procedures
  recovery_procedures:
    data_recovery: "${data_recovery_procedure}"
    configuration_recovery: "${configuration_recovery_procedure}"
    service_recovery: "${service_recovery_procedure}"

# Testing Strategy
testing_strategy:
  # Pre-deployment Testing
  pre_deployment_testing:
    unit_tests: ${unit_tests_enabled}
    integration_tests: ${integration_tests_enabled}
    security_tests: ${security_tests_enabled}
    performance_tests: ${performance_tests_enabled}
    
  # Post-deployment Testing
  post_deployment_testing:
    smoke_tests: ["${smoke_tests}"]
    health_checks: ["${post_deployment_health_checks}"]
    functional_tests: ["${functional_tests}"]
    
  # Testing Tools
  testing_tools:
    unit_test_framework: "${unit_test_framework}"
    integration_test_tool: "${integration_test_tool}"
    performance_test_tool: "${performance_test_tool}"
    security_scanning_tool: "${security_scanning_tool}"

# Documentation and Communication
documentation_communication:
  # Deployment Documentation
  deployment_documentation:
    deployment_guide: "${deployment_guide_location}"
    configuration_documentation: "${configuration_documentation_location}"
    troubleshooting_guide: "${troubleshooting_guide_location}"
    
  # Communication Plan
  communication_plan:
    stakeholder_notification: ["${deployment_stakeholder_notification}"]
    deployment_announcements: ["${deployment_announcements}"]
    status_updates: ["${deployment_status_updates}"]
    
  # Runbooks
  runbooks:
    deployment_runbook: "${deployment_runbook_location}"
    rollback_runbook: "${rollback_runbook_location}"
    troubleshooting_runbook: "${troubleshooting_runbook_location}"

# Validation Rules
validation_rules:
  required_fields:
    - deployment_id
    - deployment_name
    - application_name
    - target_environment
    - deployment_pipeline
    - health_monitoring

# Template Metadata
template_metadata:
  author: "AI Agentic Data Stack Framework"
  maintainer: "DevOps Engineer"
  last_updated: "2025-01-23"

sections:
  - name: "overview"
    description: "Overview and objectives"
    required: true
  - name: "configuration"
    description: "Configuration and setup"
    required: true
  - name: "implementation"
    description: "Implementation details"
    required: true
  - name: "validation"
    description: "Validation and testing"
    required: false
