Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ WORKDIR /workspace
COPY pull_plugins.py plugins.properties ./

# 执行构建操作
RUN python3 pull_plugins.py
RUN python3 pull_plugins.py --download-v2

# 运行阶段:最终镜像
FROM $NGINX_IMAGE
Expand Down
27 changes: 19 additions & 8 deletions pull_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import shutil
import hashlib
from datetime import datetime

def calculate_md5(file_path, chunk_size=4096):
"""计算文件的 MD5 值"""
md5_hash = hashlib.md5()
Expand Down Expand Up @@ -96,6 +97,8 @@ def main():
parser = argparse.ArgumentParser(description='处理插件配置文件')
parser.add_argument('properties_path', nargs='?', default=None,
help='properties文件路径(默认:脚本所在目录下的plugins.properties)')
parser.add_argument('--download-v2', action='store_true',
help='是否下载 2.0.0 版本插件')
args = parser.parse_args()

# 用户未提供路径时,使用默认逻辑
Expand All @@ -116,27 +119,35 @@ def main():

for plugin_name, plugin_url in properties.items():
print(f"\n正在处理插件: {plugin_name}")
success = process_plugin(base_path, plugin_name, plugin_url)
# 处理原始版本(1.0.0)
success = process_plugin(base_path, plugin_name, plugin_url, "1.0.0")
if not success:
failed_plugins.append(plugin_name)
failed_plugins.append(f"{plugin_name}:1.0.0")

# 如果指定了 --download-v2 参数,则额外处理 2.0.0 版本
if args.download_v2:
v2_url = plugin_url.replace(":1.0.0", ":2.0.0")
print(f"\n正在处理插件 {plugin_name} 的 2.0.0 版本")
success = process_plugin(base_path, plugin_name, v2_url, "2.0.0")
if not success:
failed_plugins.append(f"{plugin_name}:2.0.0")

if failed_plugins:
print("\n以下插件未成功处理:")
for plugin in failed_plugins:
print(f"- {plugin}")

def process_plugin(base_path, plugin_name, plugin_url):
def process_plugin(base_path, plugin_name, plugin_url, version):
"""
处理单个插件下载和信息获取
"""
version = plugin_url.split(':')[-1]
plugins_base_path = os.path.join(base_path, 'plugins')
os.makedirs(plugins_base_path, exist_ok=True)

plugin_dir = os.path.join(plugins_base_path, plugin_name, version)
os.makedirs(plugin_dir, exist_ok=True)

temp_download_dir = os.path.join(plugins_base_path, f"{plugin_name}_temp")
temp_download_dir = os.path.join(plugins_base_path, f"{plugin_name}_{version}_temp")
os.makedirs(temp_download_dir, exist_ok=True)

wasm_found = False
Expand Down Expand Up @@ -169,10 +180,10 @@ def process_plugin(base_path, plugin_name, plugin_url):
wasm_found = handle_wasm_layer(wasm_path, plugin_dir)

except subprocess.CalledProcessError as e:
print(f"{plugin_name} 命令执行失败: {e}")
print(f"{plugin_name} ({version}) 命令执行失败: {e}")
return False
except Exception as e:
print(f"{plugin_name} 处理过程中发生错误: {e}")
print(f"{plugin_name} ({version}) 处理过程中发生错误: {e}")
Comment on lines +183 to +186
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缺少对异常信息的具体记录,不利于调试排查问题。

🟢 Minor | 🧹 Code Smells

📋 问题详情

当捕获到 subprocess.CalledProcessError 或通用异常时,仅输出了基本错误消息,但缺乏上下文如命令本身、返回码等关键细节,这会增加调试难度。应该补充这些有助于诊断问题的日志内容。

💡 解决方案

添加更多有用的调试信息到错误日志中。

-        except subprocess.CalledProcessError as e:
-            print(f"{plugin_name} ({version}) 命令执行失败: {e}")
+        except subprocess.CalledProcessError as e:
+            print(f"{plugin_name} ({version}) 命令执行失败: {e.cmd} 返回码: {e.returncode}, 输出: {e.output}")
         return False
-        except Exception as e:
-            print(f"{plugin_name} ({version}) 处理过程中发生错误: {e}")
+        except Exception as e:
+            import traceback
+            print(f"{plugin_name} ({version}) 处理过程中发生错误: {e}")
+            print(traceback.format_exc())
         return False

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌

return False
finally:
shutil.rmtree(temp_download_dir, ignore_errors=True)
Expand All @@ -183,4 +194,4 @@ def process_plugin(base_path, plugin_name, plugin_url):
return wasm_found

if __name__ == '__main__':
main()
main()
Loading