mirror of
https://github.com/langgenius/dify-ee-helm-chart-values-generator.git
synced 2026-07-01 20:14:02 -04:00
feat: 输出文件带版本号并保存到 out 目录
- 修改输出配置,文件名格式为 values-prd-{version}.yaml
- 所有生成的文件保存到 out/ 目录
- 更新 .gitignore 忽略 out/ 目录
This commit is contained in:
@@ -34,6 +34,7 @@ values-test*.yaml
|
||||
|
||||
# Generated configuration files (may contain sensitive data)
|
||||
values-prd.yaml
|
||||
out/
|
||||
|
||||
# Values template (should be downloaded from Helm Chart repository)
|
||||
values.yaml
|
||||
|
||||
@@ -15,7 +15,8 @@ CACHE_DIR = ".cache"
|
||||
LOCAL_VALUES_FILE = "values.yaml"
|
||||
|
||||
# Output Configuration
|
||||
OUTPUT_FILE = "values-prd.yaml"
|
||||
OUTPUT_DIR = "out"
|
||||
OUTPUT_FILE_PREFIX = "values-prd"
|
||||
|
||||
# Timeout Configuration (in seconds)
|
||||
DOWNLOAD_TIMEOUT = 10
|
||||
|
||||
+34
-25
@@ -8,7 +8,7 @@ Module structure and relationships:
|
||||
2. Infrastructure Module - database, storage, cache (mutually exclusive choices)
|
||||
3. Network Module - Ingress configuration
|
||||
4. Mail Module - email service configuration
|
||||
5. Plugin Module - plugin configuration (3.0+ only)
|
||||
5. Plugin Module - plugin configuration (3.x+ only)
|
||||
6. Service Module - application service configuration
|
||||
"""
|
||||
|
||||
@@ -34,13 +34,13 @@ def main():
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog="""
|
||||
Examples:
|
||||
# Use default settings (auto-download latest version, interactive Dify EE version selection)
|
||||
# Use default settings (auto-download latest version, EE version auto-detected from Chart version)
|
||||
python generate-values-prd.py
|
||||
|
||||
# Specify Helm Chart version and Dify EE version
|
||||
python generate-values-prd.py --chart-version 3.6.0 --ee-version 3.0
|
||||
# Specify Helm Chart version (EE version will be auto-detected)
|
||||
python generate-values-prd.py --chart-version 3.6.0
|
||||
|
||||
# Use local values.yaml
|
||||
# Use local values.yaml (EE version will be auto-detected if Chart version can be determined)
|
||||
python generate-values-prd.py --local
|
||||
|
||||
# Force re-download
|
||||
@@ -56,13 +56,6 @@ Examples:
|
||||
default=None,
|
||||
help="Specify Helm Chart version (default: latest)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--ee-version", "-e",
|
||||
type=str,
|
||||
default=None,
|
||||
choices=VersionManager.get_available_versions(),
|
||||
help=f"Specify Dify EE version (default: interactive selection). Available: {', '.join(VersionManager.get_available_versions())}"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--local", "-l",
|
||||
action="store_true",
|
||||
@@ -119,6 +112,12 @@ Examples:
|
||||
print_info(_t('or_manual_download'))
|
||||
sys.exit(1)
|
||||
print_info(f"{_t('using_local')}: {source_file}")
|
||||
# When using --local, chart version must be specified
|
||||
if not args.chart_version:
|
||||
print_error(_t('chart_version_required_for_local'))
|
||||
print_info(_t('chart_version_required_help'))
|
||||
sys.exit(1)
|
||||
chart_version = args.chart_version
|
||||
else:
|
||||
try:
|
||||
# If chart version is specified via CLI, don't prompt
|
||||
@@ -164,21 +163,31 @@ Examples:
|
||||
print_error(f"{_t('file_not_found')}: {source_file}")
|
||||
sys.exit(1)
|
||||
|
||||
# Select Dify EE version
|
||||
if args.ee_version:
|
||||
ee_version = args.ee_version
|
||||
version_info = VersionManager.get_version_info(ee_version)
|
||||
if version_info:
|
||||
print_info(f"{_t('selected')}: {version_info.get('name', ee_version)}")
|
||||
else:
|
||||
print_error(f"{_t('invalid_version')}: {ee_version}")
|
||||
sys.exit(1)
|
||||
else:
|
||||
# Interactive version selection
|
||||
ee_version = VersionManager.prompt_version_selection()
|
||||
# Auto-detect Dify EE version from Helm Chart version
|
||||
# Helm Chart version determines the EE version automatically
|
||||
if not chart_version:
|
||||
print_error(_t('chart_version_required'))
|
||||
print_info(_t('chart_version_required_help'))
|
||||
sys.exit(1)
|
||||
|
||||
ee_version = VersionManager.map_chart_version_to_ee_version(chart_version)
|
||||
if not ee_version:
|
||||
print_error(f"{_t('cannot_detect_ee_version')}: {chart_version}")
|
||||
print_info(_t('chart_version_required_help'))
|
||||
sys.exit(1)
|
||||
|
||||
version_info = VersionManager.get_version_info(ee_version)
|
||||
if not version_info:
|
||||
print_error(f"{_t('unsupported_chart_version')}: {chart_version} -> {ee_version}")
|
||||
sys.exit(1)
|
||||
|
||||
ee_version_name = version_info.get('name', ee_version)
|
||||
modules = version_info.get('modules', [])
|
||||
print_info(f"{_t('detected_ee_version')}: {ee_version_name}")
|
||||
print_info(f"{_t('will_execute_modules')}: {', '.join(modules)}")
|
||||
|
||||
# Generate configuration
|
||||
generator = ValuesGenerator(source_file, version=ee_version)
|
||||
generator = ValuesGenerator(source_file, version=ee_version, chart_version=chart_version)
|
||||
generator.generate()
|
||||
|
||||
|
||||
|
||||
+51
-8
@@ -4,6 +4,7 @@ import os
|
||||
import sys
|
||||
import re
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
from typing import Dict, Any, Optional
|
||||
|
||||
from utils import print_success, print_error, print_info, print_header, print_warning, prompt, prompt_yes_no
|
||||
@@ -17,13 +18,14 @@ _t = get_translator()
|
||||
class ValuesGenerator:
|
||||
"""Values generator"""
|
||||
|
||||
def __init__(self, source_file: str, version: Optional[str] = None):
|
||||
def __init__(self, source_file: str, version: Optional[str] = None, chart_version: Optional[str] = None):
|
||||
"""Initialize"""
|
||||
self.source_file = source_file
|
||||
self.values = {}
|
||||
self.yaml_data = None # ruamel.yaml data object (preserves comments and format)
|
||||
self.yaml_loader = None # ruamel.yaml loader instance
|
||||
self.version = version or "3.0" # Default version
|
||||
self.version = version or "3.x" # Default version
|
||||
self.chart_version = chart_version # Helm Chart version
|
||||
self.version_modules = VersionManager.get_version_modules(self.version)
|
||||
self.load_template()
|
||||
|
||||
@@ -297,11 +299,27 @@ class ValuesGenerator:
|
||||
|
||||
print_header(_t('generator_title'))
|
||||
print_info(_t('guide_message'))
|
||||
print_info(f"{_t('target_version')}: {VersionManager.get_version_info(self.version).get('name', self.version)}")
|
||||
|
||||
# Display Helm Chart version if available
|
||||
if self.chart_version:
|
||||
print_info(f"{_t('helm_chart_version')}: {self.chart_version}")
|
||||
|
||||
# Display Dify EE version and modules that will be executed
|
||||
version_info = VersionManager.get_version_info(self.version)
|
||||
if version_info:
|
||||
ee_version_name = version_info.get('name', self.version)
|
||||
modules = version_info.get('modules', [])
|
||||
print_info(f"{_t('target_version')}: {ee_version_name}")
|
||||
print_info(f"{_t('will_execute_modules')}: {', '.join(modules)}")
|
||||
else:
|
||||
print_info(f"{_t('target_version')}: {self.version}")
|
||||
print_info(f"{_t('will_execute_modules')}: {', '.join(self.version_modules)}")
|
||||
|
||||
print_info(_t('press_ctrl_c'))
|
||||
|
||||
try:
|
||||
# Dynamically configure modules based on version
|
||||
# Map module names to their configuration functions
|
||||
module_configs = {
|
||||
"global": configure_global,
|
||||
"infrastructure": configure_infrastructure,
|
||||
@@ -311,21 +329,46 @@ class ValuesGenerator:
|
||||
"services": configure_services,
|
||||
}
|
||||
|
||||
# Map module names to function names for display
|
||||
module_function_names = {
|
||||
"global": "configure_global",
|
||||
"infrastructure": "configure_infrastructure",
|
||||
"networking": "configure_networking",
|
||||
"mail": "configure_mail",
|
||||
"plugins": "configure_plugins",
|
||||
"services": "configure_services",
|
||||
}
|
||||
|
||||
# Configure each module in order (based on version support)
|
||||
for module_name in self.version_modules:
|
||||
if module_name in module_configs:
|
||||
function_name = module_function_names.get(module_name, f"configure_{module_name}")
|
||||
print_info(f"{_t('executing_module')}: {module_name} -> {function_name}")
|
||||
module_configs[module_name](self)
|
||||
else:
|
||||
print_warning(f"{_t('module_not_found')} '{module_name}', {_t('skipping')}")
|
||||
|
||||
# Save file
|
||||
output_file = config.OUTPUT_FILE
|
||||
# Generate output filename with version
|
||||
output_dir = Path(config.OUTPUT_DIR)
|
||||
output_dir.mkdir(exist_ok=True)
|
||||
|
||||
if self.chart_version:
|
||||
output_filename = f"{config.OUTPUT_FILE_PREFIX}-{self.chart_version}.yaml"
|
||||
else:
|
||||
output_filename = f"{config.OUTPUT_FILE_PREFIX}.yaml"
|
||||
|
||||
output_file = str(output_dir / output_filename)
|
||||
|
||||
if os.path.exists(output_file):
|
||||
overwrite_prompt = f"{output_file} {_t('file_exists_overwrite')}"
|
||||
if not prompt_yes_no(overwrite_prompt, default=False):
|
||||
output_file = prompt(_t('enter_new_filename'), default=config.OUTPUT_FILE, required=False)
|
||||
if not output_file:
|
||||
output_file = config.OUTPUT_FILE
|
||||
custom_filename = prompt(_t('enter_new_filename'), default=output_filename, required=False)
|
||||
if custom_filename:
|
||||
if not custom_filename.endswith('.yaml'):
|
||||
custom_filename += '.yaml'
|
||||
output_file = str(output_dir / custom_filename)
|
||||
else:
|
||||
output_file = str(output_dir / output_filename)
|
||||
|
||||
self.save(output_file)
|
||||
|
||||
|
||||
@@ -63,7 +63,16 @@ TRANSLATIONS = {
|
||||
# Generator
|
||||
'generator_title': 'Dify Helm Chart Values Generator',
|
||||
'guide_message': 'This tool will guide you through configuring values-prd.yaml',
|
||||
'helm_chart_version': 'Helm Chart version',
|
||||
'target_version': 'Target version',
|
||||
'detected_ee_version': 'Detected Dify EE version',
|
||||
'will_execute_modules': 'Will execute modules',
|
||||
'executing_module': 'Executing module',
|
||||
'chart_version_required': 'Helm Chart version is required to determine Dify EE version',
|
||||
'chart_version_required_for_local': 'Helm Chart version is required when using --local',
|
||||
'chart_version_required_help': 'Please specify --chart-version or download from repository',
|
||||
'cannot_detect_ee_version': 'Cannot detect Dify EE version from Chart version',
|
||||
'unsupported_chart_version': 'Unsupported Chart version',
|
||||
'press_ctrl_c': 'You can press Ctrl+C to exit at any time',
|
||||
'config_complete': 'Configuration Complete!',
|
||||
'config_saved_to': 'Configuration file saved to',
|
||||
@@ -384,7 +393,16 @@ TRANSLATIONS = {
|
||||
# Generator
|
||||
'generator_title': 'Dify Helm Chart Values 生成器',
|
||||
'guide_message': '此工具将引导您完成 values-prd.yaml 的配置',
|
||||
'helm_chart_version': 'Helm Chart 版本',
|
||||
'target_version': '目标版本',
|
||||
'detected_ee_version': '检测到的 Dify EE 版本',
|
||||
'will_execute_modules': '将执行的模块',
|
||||
'executing_module': '正在执行模块',
|
||||
'chart_version_required': '需要 Helm Chart 版本来确定 Dify EE 版本',
|
||||
'chart_version_required_for_local': '使用 --local 时必须指定 Helm Chart 版本',
|
||||
'chart_version_required_help': '请指定 --chart-version 或从仓库下载',
|
||||
'cannot_detect_ee_version': '无法从 Chart 版本检测 Dify EE 版本',
|
||||
'unsupported_chart_version': '不支持的 Chart 版本',
|
||||
'press_ctrl_c': '您可以随时按 Ctrl+C 退出',
|
||||
'config_complete': '配置完成!',
|
||||
'config_saved_to': '配置文件已保存到',
|
||||
|
||||
+51
-7
@@ -13,32 +13,33 @@ class VersionManager:
|
||||
"""Version manager - manages Dify EE configuration modules for different versions"""
|
||||
|
||||
# Version configuration: defines modules supported by each version
|
||||
# Uses major version format (3.x, 2.x) to avoid confusion with specific chart versions (e.g., 3.5.6)
|
||||
VERSION_CONFIGS = {
|
||||
"3.0": {
|
||||
"name": "Dify Enterprise Edition 3.0",
|
||||
"3.x": {
|
||||
"name": "Dify Enterprise Edition 3.x",
|
||||
"modules": [
|
||||
"global",
|
||||
"infrastructure",
|
||||
"networking",
|
||||
"mail",
|
||||
"plugins", # Version 3.0 supports plugin module
|
||||
"plugins", # Version 3.x supports plugin module
|
||||
"services"
|
||||
],
|
||||
"description": "Full version with plugin support"
|
||||
},
|
||||
"2.0": {
|
||||
"name": "Dify Enterprise Edition 2.0",
|
||||
"2.x": {
|
||||
"name": "Dify Enterprise Edition 2.x",
|
||||
"modules": [
|
||||
"global",
|
||||
"infrastructure",
|
||||
"networking",
|
||||
"mail",
|
||||
# Version 2.0 does not support plugin module
|
||||
# Version 2.x does not support plugin module
|
||||
"services"
|
||||
],
|
||||
"description": "Version without plugin support"
|
||||
},
|
||||
# More version configurations can be added here
|
||||
# More version configurations can be added here (e.g., "4.x")
|
||||
}
|
||||
|
||||
@classmethod
|
||||
@@ -122,3 +123,46 @@ class VersionManager:
|
||||
# For now, return None to let user manually select
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def map_chart_version_to_ee_version(cls, chart_version: Optional[str]) -> Optional[str]:
|
||||
"""
|
||||
Map Helm Chart version to Dify EE version
|
||||
|
||||
Mapping rules:
|
||||
- Chart version 3.x.x -> Dify EE 3.x
|
||||
- Chart version 2.x.x -> Dify EE 2.x
|
||||
- Chart version 1.x.x -> Dify EE 2.x (legacy)
|
||||
- Chart version 4.x.x -> Dify EE 4.x (future)
|
||||
- Unknown or None -> None (requires manual selection)
|
||||
|
||||
Args:
|
||||
chart_version: Helm Chart version string (e.g., "3.5.6", "3.6.0-beta.1")
|
||||
|
||||
Returns:
|
||||
Dify EE version string (e.g., "3.x", "2.x") or None if cannot be determined
|
||||
"""
|
||||
if not chart_version:
|
||||
return None
|
||||
|
||||
# Extract major version number
|
||||
try:
|
||||
# Handle versions like "3.5.6", "3.6.0-beta.1", etc.
|
||||
major_version = int(chart_version.split('.')[0])
|
||||
|
||||
# Map major version to EE version (using x format for extensibility)
|
||||
# Future versions (4.x, 5.x, etc.) will automatically map correctly
|
||||
if major_version >= 4:
|
||||
return f"{major_version}.x"
|
||||
elif major_version >= 3:
|
||||
return "3.x"
|
||||
elif major_version >= 2:
|
||||
return "2.x"
|
||||
elif major_version >= 1:
|
||||
# Chart version 1.x maps to EE 2.x (legacy support)
|
||||
return "2.x"
|
||||
else:
|
||||
return None
|
||||
except (ValueError, IndexError):
|
||||
# If version format is unexpected, return None
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user