prvng_platform/scripts/validate-infrastructure.nu

111 lines
3.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env nu
# Infrastructure Validation Script
# Validates generated infrastructure configs using format-specific tools
use std log
def main [--config-dir: string = "provisioning/platform/infrastructure"] {
log info $"Validating infrastructure configs in: ($config_dir)"
let errors = []
let warnings = []
# Validate Docker Compose files
validate_docker_compose $config_dir
# Validate Kubernetes manifests
validate_kubernetes $config_dir
# Validate Nginx configurations
validate_nginx $config_dir
# Validate Prometheus configurations
validate_prometheus $config_dir
log info "✅ Infrastructure validation complete!"
}
def validate_docker_compose [config_dir: string] {
log info "Validating Docker Compose files..."
let dc_files_result = (do { ls -la $"($config_dir)/docker-compose/*.yaml" } | complete)
let dc_files = if $dc_files_result.exit_code == 0 {
($dc_files_result.stdout | lines | each { |line| $line | from json } | each { |file| $file.name })
} else {
[]
}
for file in $dc_files {
let filename = $file | path basename
let r = (do { ^docker-compose -f $file config --quiet } | complete)
if $r.exit_code == 0 {
log info $" ✅ ($filename)"
} else {
log warning $" ⚠️ ($filename): validation error"
}
}
}
def validate_kubernetes [config_dir: string] {
log info "Validating Kubernetes manifests..."
let k8s_files_result = (do { ls -la $"($config_dir)/kubernetes/**/*.yaml" } | complete)
let k8s_files = if $k8s_files_result.exit_code == 0 {
($k8s_files_result.stdout | lines | each { |line| $line | from json } | each { |file| $file.name })
} else {
[]
}
for file in $k8s_files {
let filename = $file | path basename
let r = (do { ^kubectl apply --dry-run=client -f $file out+err> /dev/null } | complete)
if $r.exit_code == 0 {
log info $" ✅ ($filename)"
} else {
log warning $" ⚠️ ($filename): validation error"
}
}
}
def validate_nginx [config_dir: string] {
log info "Validating Nginx configurations..."
let nginx_files_result = (do { ls -la $"($config_dir)/nginx/*.conf" } | complete)
let nginx_files = if $nginx_files_result.exit_code == 0 {
($nginx_files_result.stdout | lines | each { |line| $line | from json } | each { |file| $file.name })
} else {
[]
}
for file in $nginx_files {
let filename = $file | path basename
let r = (do { ^nginx -t -c $file out+err> /dev/null } | complete)
if $r.exit_code == 0 {
log info $" ✅ ($filename)"
} else {
log info $" ($filename): nginx binary not available"
}
}
}
def validate_prometheus [config_dir: string] {
log info "Validating Prometheus configurations..."
let prom_files_result = (do { ls -la $"($config_dir)/prometheus/*.yml" } | complete)
let prom_files = if $prom_files_result.exit_code == 0 {
($prom_files_result.stdout | lines | each { |line| $line | from json } | each { |file| $file.name })
} else {
[]
}
for file in $prom_files {
let filename = $file | path basename
let r = (do { ^promtool check config $file out+err> /dev/null } | complete)
if $r.exit_code == 0 {
log info $" ✅ ($filename)"
} else {
log info $" ($filename): promtool not available"
}
}
}