-
Notifications
You must be signed in to change notification settings - Fork 117
针对windows部分做了更新优化及debug,及导出目录 #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Updated the Dockerfile to install additional build tools and fix line endings for the script.
Modified author attribution and adjusted output directory for repackaging.
📝 WalkthroughWalkthroughThis pull request enhances the Docker build environment with expanded development tools, adds CRLF line-ending normalization, updates the container entrypoint, and refactors the plugin repackaging script to standardize path handling and improve consistency across different packaging workflows. Documentation is also updated with a local execution example. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom Pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🤖 Fix all issues with AI agents
In @Dockerfile:
- Line 27: The Dockerfile uses ENTRYPOINT ["bash", "/app/plugin_repackaging.sh"]
which prevents users from easily overriding the default command; either revert
to CMD ["bash", "/app/plugin_repackaging.sh"] to allow simple docker run
overrides, or keep ENTRYPOINT but update README section 4 to show the proper
override syntax using --entrypoint (e.g., docker run --entrypoint bash ...
/app/plugin_repackaging.sh ...); choose one approach and apply it consistently
(modify the Dockerfile ENTRYPOINT/CMD accordingly and/or update README section
4) so users can run alternative commands as intended.
In @plugin_repackaging.sh:
- Line 122: The script blindly runs cd "$CURR_DIR" which can fail and leave
subsequent commands running in the wrong directory; update the call that returns
to CURR_DIR to check the command result and handle failures (e.g., test the exit
status of cd "$CURR_DIR" and on failure log an error including CURR_DIR and exit
non‑zero or abort the script). Locate the cd "$CURR_DIR" invocation and wrap it
with a conditional check that emits a clear error message and exits when the
directory change fails.
- Line 96: The cd command invocation cd "${CURR_DIR}/${PKG_NAME}" can fail and
leave the script in the wrong directory; before changing directories, validate
the target exists and is accessible (e.g., test -d and test -x) and after
attempting the cd check its exit status and abort (exit non-zero) or handle the
failure (log and return) if it fails; update the invocation of cd
"${CURR_DIR}/${PKG_NAME}" to perform these checks and fail fast so the script
does not continue when the directory change fails.
- Around line 159-164: The case branch calls use unquoted $@ which allows
word-splitting/globbing; update the dispatcher to pass arguments as "$@" to
preserve argument boundaries—change the invocations of market, github, and
_local from market $@, github $@, _local $@ to market "$@", github "$@", and
_local "$@", leaving the default print_usage branch unchanged.
- Around line 87-88: The combined local declarations with command substitution
for PKG_FULL and PKG_NAME can mask the exit status of the command substitution;
change to declare variables first (local PKG_FULL PKG_NAME) and then assign
PKG_FULL="$(basename "$PKG_PATH")" and PKG_NAME="${PKG_FULL%.*}" so any failure
in basename or downstream assignments is detectable and the exit code is
preserved; update the block that references PKG_PATH, PKG_FULL, and PKG_NAME
accordingly.
In @README.md:
- Around line 25-26: Update the example Docker run command so the host current
directory is mounted to /app (matching the Dockerfile's WORKDIR and where the
script runs) and reference the plugin file path relative to /app; change the
mount target from /work to /app and update the file path from
/work/langgenius-modelscope_0.0.8.difypkg to
/app/langgenius-modelscope_0.0.8.difypkg so the container can find the file when
the script runs from /app.
🧹 Nitpick comments (1)
plugin_repackaging.sh (1)
32-51: Consider declaring function variables as local.The function variables (
PLUGIN_AUTHOR,PLUGIN_NAME,PLUGIN_VERSION,PACKAGE_PATH,URL) are not declared withlocal, which could lead to unintended global scope pollution or conflicts.🔎 Suggested improvement
market(){ if [[ -z "$2" || -z "$3" || -z "$4" ]]; then echo "" echo "Usage: $0 market [plugin author] [plugin name] [plugin version]" exit 1 fi echo "From Dify Marketplace downloading ..." - PLUGIN_AUTHOR=$2 - PLUGIN_NAME=$3 - PLUGIN_VERSION=$4 - PACKAGE_PATH="${CURR_DIR}/${PLUGIN_AUTHOR}-${PLUGIN_NAME}_${PLUGIN_VERSION}.difypkg" - URL="${MARKETPLACE_API_URL}/api/v1/plugins/${PLUGIN_AUTHOR}/${PLUGIN_NAME}/${PLUGIN_VERSION}/download" + local PLUGIN_AUTHOR=$2 + local PLUGIN_NAME=$3 + local PLUGIN_VERSION=$4 + local PACKAGE_PATH="${CURR_DIR}/${PLUGIN_AUTHOR}-${PLUGIN_NAME}_${PLUGIN_VERSION}.difypkg" + local URL="${MARKETPLACE_API_URL}/api/v1/plugins/${PLUGIN_AUTHOR}/${PLUGIN_NAME}/${PLUGIN_VERSION}/download" curl -L -o "$PACKAGE_PATH" "$URL" if [[ $? -ne 0 ]]; then echo "Download failed." exit 1 fi repackage "$PACKAGE_PATH" }Apply similar changes to
github()and_local()functions.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
DockerfileREADME.mdplugin_repackaging.sh
🧰 Additional context used
🪛 Shellcheck (0.11.0)
plugin_repackaging.sh
[warning] 87-87: Declare and assign separately to avoid masking return values.
(SC2155)
[warning] 96-96: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
(SC2164)
[warning] 122-122: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
(SC2164)
[error] 160-160: Double quote array expansions to avoid re-splitting elements.
(SC2068)
[error] 161-161: Double quote array expansions to avoid re-splitting elements.
(SC2068)
[error] 162-162: Double quote array expansions to avoid re-splitting elements.
(SC2068)
🔇 Additional comments (11)
Dockerfile (2)
9-17: Good addition of build tools.The expanded toolchain (gcc, cairo, pango, libffi) properly supports Python packages with C extensions, which is essential for plugin repackaging.
23-25: CRLF normalization is a good practice.Using
dos2unixensures the script works correctly regardless of where it was edited (Windows/Linux), preventing line-ending-related issues.plugin_repackaging.sh (9)
16-18: Verify the hardcoded output path works for non-Docker usage.The fixed
/app/outputdirectory works well for the Docker workflow, but the README mentions the script can run on Linux and macOS directly. Ensure that/app/outputis writable in those environments or consider making it configurable for non-containerized usage.
22-22: Clean simplification of OS detection.Consolidating OS type detection with case conversion into a single pipeline is more readable and maintainable.
25-27: Correct handling of ARM64 architecture variants.Checking for both
arm64(macOS) andaarch64(Linux) ensures compatibility across platforms.
53-74: Unified error handling improves consistency.The standardized error messages ("Download failed.") and exit code checks across all download functions make the script more maintainable and user-friendly.
76-83: Good use of realpath for path normalization.Using
realpathensures the script works correctly with relative paths, symbolic links, and.or..references.
101-107: Good handling of sed platform differences.The conditional logic correctly addresses the different behaviors of
sed -ibetween Linux (in-place without extension) and macOS (requires backup extension), ensuring cross-platform compatibility.
125-135: Output directory standardization improves Docker workflow.Writing all output to the fixed
/app/outputlocation and providing clear feedback makes the containerized workflow more predictable and user-friendly.
138-143: Improved portability withcommand -v.Using
command -vinstead ofwhichis more portable and follows POSIX standards.
145-148: Usage message is clear and helpful.The consolidated usage function provides sufficient guidance for users.
|
|
||
| # 设置默认命令 | ||
| CMD ["./plugin_repackaging.sh", "-p", "manylinux_2_17_x86_64", "market", "antv", "visualization", "0.1.7"] | ||
| ENTRYPOINT ["bash", "/app/plugin_repackaging.sh"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ENTRYPOINT reduces container flexibility.
Changing from CMD to ENTRYPOINT means users can no longer easily override the default command (as shown in README section 4). To run alternative commands, users must now use docker run --entrypoint <cmd>, which is less convenient.
Consider whether the added rigidity is worth the trade-off, or document the --entrypoint override pattern.
🔎 Alternative approach
If you want to keep the bash invocation while preserving easy override:
-ENTRYPOINT ["bash", "/app/plugin_repackaging.sh"]
+CMD ["bash", "/app/plugin_repackaging.sh"]Or if ENTRYPOINT is preferred, update README section 4 to show the correct override syntax:
docker run --entrypoint bash -v $(pwd):/app dify-plugin-repackaging /app/plugin_repackaging.sh -p manylinux_2_17_x86_64 market antv visualization 0.1.7📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ENTRYPOINT ["bash", "/app/plugin_repackaging.sh"] | |
| CMD ["bash", "/app/plugin_repackaging.sh"] |
🤖 Prompt for AI Agents
In @Dockerfile at line 27, The Dockerfile uses ENTRYPOINT ["bash",
"/app/plugin_repackaging.sh"] which prevents users from easily overriding the
default command; either revert to CMD ["bash", "/app/plugin_repackaging.sh"] to
allow simple docker run overrides, or keep ENTRYPOINT but update README section
4 to show the proper override syntax using --entrypoint (e.g., docker run
--entrypoint bash ... /app/plugin_repackaging.sh ...); choose one approach and
apply it consistently (modify the Dockerfile ENTRYPOINT/CMD accordingly and/or
update README section 4) so users can run alternative commands as intended.
| local PKG_FULL=$(basename "$PKG_PATH") | ||
| local PKG_NAME="${PKG_FULL%.*}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate variable declaration from assignment.
Combining local declaration with command substitution can mask the exit status of the command, making error detection unreliable.
🔎 Proposed fix
local PKG_PATH=$1
- local PKG_FULL=$(basename "$PKG_PATH")
- local PKG_NAME="${PKG_FULL%.*}"
+ local PKG_FULL
+ PKG_FULL=$(basename "$PKG_PATH")
+ local PKG_NAME="${PKG_FULL%.*}"Based on static analysis hints.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| local PKG_FULL=$(basename "$PKG_PATH") | |
| local PKG_NAME="${PKG_FULL%.*}" | |
| local PKG_FULL | |
| PKG_FULL=$(basename "$PKG_PATH") | |
| local PKG_NAME="${PKG_FULL%.*}" |
🧰 Tools
🪛 Shellcheck (0.11.0)
[warning] 87-87: Declare and assign separately to avoid masking return values.
(SC2155)
🤖 Prompt for AI Agents
In @plugin_repackaging.sh around lines 87 - 88, The combined local declarations
with command substitution for PKG_FULL and PKG_NAME can mask the exit status of
the command substitution; change to declare variables first (local PKG_FULL
PKG_NAME) and then assign PKG_FULL="$(basename "$PKG_PATH")" and
PKG_NAME="${PKG_FULL%.*}" so any failure in basename or downstream assignments
is detectable and the exit code is preserved; update the block that references
PKG_PATH, PKG_FULL, and PKG_NAME accordingly.
| [[ $? -ne 0 ]] && echo "Unzip failed." && exit 1 | ||
|
|
||
| echo "Repackaging ..." | ||
| cd "${CURR_DIR}/${PKG_NAME}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for directory change.
The cd command can fail if the directory doesn't exist or isn't accessible. Add error handling to prevent the script from continuing in the wrong directory.
🔎 Proposed fix
- cd "${CURR_DIR}/${PKG_NAME}"
+ cd "${CURR_DIR}/${PKG_NAME}" || { echo "Failed to enter package directory."; exit 1; }Based on static analysis hints.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| cd "${CURR_DIR}/${PKG_NAME}" | |
| cd "${CURR_DIR}/${PKG_NAME}" || { echo "Failed to enter package directory."; exit 1; } |
🧰 Tools
🪛 Shellcheck (0.11.0)
[warning] 96-96: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
(SC2164)
🤖 Prompt for AI Agents
In @plugin_repackaging.sh at line 96, The cd command invocation cd
"${CURR_DIR}/${PKG_NAME}" can fail and leave the script in the wrong directory;
before changing directories, validate the target exists and is accessible (e.g.,
test -d and test -x) and after attempting the cd check its exit status and abort
(exit non-zero) or handle the failure (log and return) if it fails; update the
invocation of cd "${CURR_DIR}/${PKG_NAME}" to perform these checks and fail fast
so the script does not continue when the directory change fails.
| fi | ||
| fi | ||
|
|
||
| cd "$CURR_DIR" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for directory change.
The cd back to CURR_DIR should verify success to ensure subsequent commands run in the correct location.
🔎 Proposed fix
- cd "$CURR_DIR"
+ cd "$CURR_DIR" || { echo "Failed to return to working directory."; exit 1; }Based on static analysis hints.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| cd "$CURR_DIR" | |
| cd "$CURR_DIR" || { echo "Failed to return to working directory."; exit 1; } |
🧰 Tools
🪛 Shellcheck (0.11.0)
[warning] 122-122: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
(SC2164)
🤖 Prompt for AI Agents
In @plugin_repackaging.sh at line 122, The script blindly runs cd "$CURR_DIR"
which can fail and leave subsequent commands running in the wrong directory;
update the call that returns to CURR_DIR to check the command result and handle
failures (e.g., test the exit status of cd "$CURR_DIR" and on failure log an
error including CURR_DIR and exit non‑zero or abort the script). Locate the cd
"$CURR_DIR" invocation and wrap it with a conditional check that emits a clear
error message and exits when the directory change fails.
| case "$1" in | ||
| 'market') | ||
| market $@ | ||
| ;; | ||
| 'github') | ||
| github $@ | ||
| ;; | ||
| 'local') | ||
| _local $@ | ||
| ;; | ||
| *) | ||
|
|
||
| print_usage | ||
| exit 1 | ||
| market) market $@ ;; | ||
| github) github $@ ;; | ||
| local) _local $@ ;; | ||
| *) print_usage ;; | ||
| esac |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote array expansions to preserve arguments correctly.
The unquoted $@ can cause word splitting and globbing issues when arguments contain spaces or special characters. Use "$@" to preserve argument boundaries.
🔎 Proposed fix
shift $((OPTIND - 1))
case "$1" in
- market) market $@ ;;
- github) github $@ ;;
- local) _local $@ ;;
+ market) market "$@" ;;
+ github) github "$@" ;;
+ local) _local "$@" ;;
*) print_usage ;;
esacBased on static analysis hints.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| case "$1" in | |
| 'market') | |
| market $@ | |
| ;; | |
| 'github') | |
| github $@ | |
| ;; | |
| 'local') | |
| _local $@ | |
| ;; | |
| *) | |
| print_usage | |
| exit 1 | |
| market) market $@ ;; | |
| github) github $@ ;; | |
| local) _local $@ ;; | |
| *) print_usage ;; | |
| esac | |
| case "$1" in | |
| market) market "$@" ;; | |
| github) github "$@" ;; | |
| local) _local "$@" ;; | |
| *) print_usage ;; | |
| esac |
🧰 Tools
🪛 Shellcheck (0.11.0)
[error] 160-160: Double quote array expansions to avoid re-splitting elements.
(SC2068)
[error] 161-161: Double quote array expansions to avoid re-splitting elements.
(SC2068)
[error] 162-162: Double quote array expansions to avoid re-splitting elements.
(SC2068)
🤖 Prompt for AI Agents
In @plugin_repackaging.sh around lines 159 - 164, The case branch calls use
unquoted $@ which allows word-splitting/globbing; update the dispatcher to pass
arguments as "$@" to preserve argument boundaries—change the invocations of
market, github, and _local from market $@, github $@, _local $@ to market "$@",
github "$@", and _local "$@", leaving the default print_usage branch unchanged.
| 本地示例 | ||
| docker run -v %cd%:/work -v %cd%/output:/app/output dify-plugin-repackaging local /work/langgenius-modelscope_0.0.8.difypkg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the volume mount path inconsistency.
The example mounts the current directory to /work, but the Dockerfile sets WORKDIR /app and the script runs from /app. When you reference /work/langgenius-modelscope_0.0.8.difypkg, the script won't find it because it operates relative to /app, not /work.
🔎 Proposed fix
-本地示例
-docker run -v %cd%:/work -v %cd%/output:/app/output dify-plugin-repackaging local /work/langgenius-modelscope_0.0.8.difypkg
+本地示例
+docker run -v %cd%:/app -v %cd%/output:/app/output dify-plugin-repackaging local /app/langgenius-modelscope_0.0.8.difypkgThis ensures the current directory is mounted to /app (matching the WORKDIR), and the plugin file path is relative to /app.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 本地示例 | |
| docker run -v %cd%:/work -v %cd%/output:/app/output dify-plugin-repackaging local /work/langgenius-modelscope_0.0.8.difypkg | |
| 本地示例 | |
| docker run -v %cd%:/app -v %cd%/output:/app/output dify-plugin-repackaging local /app/langgenius-modelscope_0.0.8.difypkg |
🤖 Prompt for AI Agents
In @README.md around lines 25 - 26, Update the example Docker run command so the
host current directory is mounted to /app (matching the Dockerfile's WORKDIR and
where the script runs) and reference the plugin file path relative to /app;
change the mount target from /work to /app and update the file path from
/work/langgenius-modelscope_0.0.8.difypkg to
/app/langgenius-modelscope_0.0.8.difypkg so the container can find the file when
the script runs from /app.
Summary by CodeRabbit
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.