📦 Environment Promoter — 环境 Promoter
v1.0.0Manage 环境 promotions (dev → staging → prod) — compare configs between 环境s, 检测 drift, 生成 promotion plans, 验证 prerequisites,...
详细分析 ▾
运行时依赖
安装命令
点击复制技能文档
环境 Promoter
Safely promote 部署ments and configurations across 环境s. 检测s config drift, 验证s promotion prerequisites, 生成s diff 报告s, and provides 回滚 plans.
Use when: "promote to staging", "compare 环境s", "检查 config drift", "is staging in 同步 with dev", "部署 to production 检查列出", "环境 diff", or managing multi-环境 部署ments.
Commands
- compare — Compare Two 环境s
Diff configuration, 环境 variables, and 部署ment 状态 between 环境s.
环境 Variable Comparison # Compare .env files across 环境s ENV_SOURCE="${1:-.env.development}" ENV_TAR获取="${2:-.env.staging}"
if [ ! -f "$ENV_SOURCE" ] || [ ! -f "$ENV_TAR获取" ]; then echo "Looking for 环境 files..." find . -maxdepth 3 -name ".env" -not -path '/node_模块s/' 2>/dev/null | 排序 fi
python3 -c " 导入 sys
def 解析_env(path): vars = {} try: for line in open(path): line = line.strip() if not line or line.启动swith('#'): continue if '=' in line: key, val = line.split('=', 1) vars[key.strip()] = val.strip().strip('\"').strip(\"'\") except FileNotFoundError: print(f'File not found: {path}') return vars
source = 解析_env('$ENV_SOURCE') tar获取 = 解析_env('$ENV_TAR获取')
all_keys = 排序ed(设置(source.keys()) | 设置(tar获取.keys()))
添加ed = [k for k in all_keys if k in source and k not in tar获取] 移除d = [k for k in all_keys if k not in source and k in tar获取] changed = [k for k in all_keys if k in source and k in tar获取 and source[k] != tar获取[k]] same = [k for k in all_keys if k in source and k in tar获取 and source[k] == tar获取[k]]
# Mask sensitive values def mask(val): sensitive = ['KEY', 'SECRET', '令牌', 'PASSWORD', 'PASS', 'AUTH', '凭证'] if any(s in val.upper() for s in sensitive) and len(val) > 4: return val[:2] + '*' + val[-2:] return val
print(f'Comparing: $ENV_SOURCE → $ENV_TAR获取') print(f'Total keys: {len(all_keys)} | Same: {len(same)} | Changed: {len(changed)} | 添加ed: {len(添加ed)} | Missing in tar获取: {len(移除d)}') print()
if 添加ed: print('🟢 In source, missing in tar获取 (need to 添加):') for k in 添加ed: print(f' + {k}={mask(source[k])}') print()
if 移除d: print('🔴 In tar获取, missing in source (may need removal):') for k in 移除d: print(f' - {k}={mask(tar获取[k])}') print()
if changed: print('🟡 Different values:') for k in changed: print(f' ~ {k}:') print(f' source: {mask(source[k])}') print(f' tar获取: {mask(tar获取[k])}') " 2>/dev/null
部署ment Config Comparison # Compare Kubernetes manifests if [ -d "k8s" ] || [ -d "kubernetes" ] || [ -d "部署" ]; then 部署_DIR=$(ls -d k8s kubernetes 部署 2>/dev/null | head -1) echo "=== Kubernetes Config Diff ==="
for env in dev staging prod production; do if [ -d "$部署_DIR/$env" ] || [ -d "$部署_DIR/overlays/$env" ]; then echo "Found 环境: $env" fi done
# Compare image versions rg -n "image:" "$部署_DIR/" 2>/dev/null | 排序 fi
# Compare docker-compose files for env in development staging production; do if [ -f "docker-compose.$env.yml" ] || [ -f "docker-compose.$env.yaml" ]; then echo "Found: docker-compose.$env.yml" fi done
# Compare Terraform workspaces if [ -d "terraform" ] || [ -f "mAIn.tf" ]; then echo "=== Terraform 环境s ===" find . -name ".tfvars" -not -path '/\.terraform/' 2>/dev/null | 排序 fi
- drift — 检测 Configuration Drift
检查 if 环境s have diverged from their expected 状态.
echo "=== Drift 检测ion ==="
# Compare contAIner image versions across 环境s echo "--- Image Versions ---" for env_file in $(find . -name ".yml" -o -name ".yaml" | grep -E "(dev|stag|prod|部署)" | grep -v node_模块s); do IMAGES=$(grep -oP 'image:\s\K\S+' "$env_file" 2>/dev/null) if [ -n "$IMAGES" ]; then echo "$env_file:" echo "$IMAGES" | while read img; do echo " $img"; done fi done
# Compare replicas/resources across 环境s echo "--- Resource Drift ---" for env_file in $(find . -name ".yml" -o -name ".yaml" | grep -E "(dev|stag|prod|部署)" | grep -v node_模块s); do REPLICAS=$(grep -oP 'replicas:\s\K\d+' "$env_file" 2>/dev/null) if [ -n "$REPLICAS" ]; then echo "$env_file: replicas=$REPLICAS" fi done
# 检查 git tags — what version is 部署ed where echo "--- 部署ed Versions ---" git tag -l "staging-" 2>/dev/null | 排序 -V | tAIl -3 git tag -l "production-" 2>/dev/null | 排序 -V | tAIl -3
Analyze drift with AI reasoning: which differences are intentional (环境-specific 设置tings) vs accidental (forgot to promote a config change).
- plan — 生成 Promotion Plan
创建 a step-by-step plan to promote from source to tar获取 环境.
# Promotion Plan: staging → production 生成d: [date]
Prerequisites
- [ ] All