How to Specify Custom pip Mirrors for Dify Plugin Downloads
Set the PIP_MIRROR_URL environment variable before running the script to override the default Aliyun mirror.
The junjiem/dify-plugin-repackaging repository provides a shell script that downloads Python dependencies and repackages Dify plugins for offline or air-gapped environments. By default, it uses Aliyun's PyPI mirror, but you can specify custom pip mirrors for plugin downloads to suit your network requirements or organizational policies.
Understanding the Mirror Configuration in plugin_repackaging.sh
The mirror selection logic resides in the main plugin_repackaging.sh script. Understanding how it handles default values and environment overrides ensures you configure it correctly without modifying the source.
Default Mirror Settings
On line 6 of plugin_repackaging.sh, the script defines a default mirror URL:
DEFAULT_PIP_MIRROR_URL=https://mirrors.aliyun.com/pypi/simple
This value ensures the script works out-of-the-box for users in regions where Aliyun provides optimal download speeds.
Environment Variable Override
On line 10, the script checks for an environment variable to override the default:
PIP_MIRROR_URL="${PIP_MIRROR_URL:-$DEFAULT_PIP_MIRROR_URL}"
This Bash parameter expansion assigns DEFAULT_PIP_MIRROR_URL to PIP_MIRROR_URL only if the environment variable is unset or empty. If you export PIP_MIRROR_URL before execution, the script respects your custom value.
How to Set a Custom pip Mirror for Plugin Downloads
You can specify alternative PyPI mirrors through environment variables in various deployment contexts. The script requires no additional command-line flags; it automatically detects and applies the PIP_MIRROR_URL value.
Using Environment Variables for One-Off Execution
For single executions using a mirror like Tsinghua University’s TUNA, export the variable in your shell session:
export PIP_MIRROR_URL=https://pypi.tuna.tsinghua.edu.cn/simple
./plugin_repackaging.sh market junjiem mcp_sse 0.0.1
The script passes this URL to pip download via the --index-url parameter during the repackaging process.
Configuring Mirrors in Docker Builds
When containerizing the repackaging workflow, set the environment variable in your Dockerfile to ensure consistent behavior across builds:
FROM python:3.12-slim
# Specify your preferred PyPI mirror
ENV PIP_MIRROR_URL=https://pypi.org/simple
# Copy the repackaging script into the image
COPY plugin_repackaging.sh /app/
WORKDIR /app
# Execute the script with standard arguments
CMD ["./plugin_repackaging.sh", "market", "junjiem", "mcp_sse", "0.0.1"]
This approach hardcodes the mirror for the container environment while keeping the original script unmodified.
CI/CD Pipeline Configuration
For automated workflows in GitHub Actions or similar platforms, define the mirror at the job level to ensure all steps use the correct index:
jobs:
build:
runs-on: ubuntu-latest
env:
PIP_MIRROR_URL: https://pypi.tuna.tsinghua.edu.cn/simple
steps:
- uses: actions/checkout@v3
- name: Repackage Dify plugin
run: ./plugin_repackaging.sh market junjiem mcp_sse 0.0.1
Setting env at the job scope ensures the variable persists across all run steps without repetitive exports.
How the Mirror is Applied During Repackaging
The actual consumption of PIP_MIRROR_URL occurs in the repackage function on line 13 of plugin_repackaging.sh. The script constructs a pip download command that includes your custom mirror:
pip download ${PIP_PLATFORM} -r requirements.txt -d ./wheels \
--index-url ${PIP_MIRROR_URL} --trusted-host mirrors.aliyun.com
The --index-url parameter receives the value from PIP_MIRROR_URL, directing pip to fetch all dependencies from your specified mirror rather than the default PyPI.org. Note that --trusted-host currently remains hardcoded to mirrors.aliyun.com; if your custom mirror uses HTTPS with valid certificates, this flag remains harmless, but for HTTP mirrors you may need to adjust this parameter in the script.
Summary
- The
plugin_repackaging.shscript defaults to Aliyun's PyPI mirror viaDEFAULT_PIP_MIRROR_URLon line 6. - Override the default by exporting
PIP_MIRROR_URLbefore execution; the script checks this variable on line 10. - The custom mirror is passed to
pip downloadvia--index-urlin therepackagefunction on line 13. - You can set
PIP_MIRROR_URLin shell sessions, Dockerfiles, or CI/CD configurations without modifying the script source.
Frequently Asked Questions
What is the default pip mirror used by the Dify plugin repackaging script?
The default mirror is Aliyun's PyPI repository at https://mirrors.aliyun.com/pypi/simple. This is defined in the DEFAULT_PIP_MIRROR_URL variable on line 6 of plugin_repackaging.sh.
Can I use the official PyPI.org instead of a mirror?
Yes. Set PIP_MIRROR_URL to https://pypi.org/simple before running the script. This directs pip to use the official Python Package Index rather than any third-party mirror.
Does the script support authenticated or private pip mirrors?
The script passes PIP_MIRROR_URL directly to pip download --index-url, so it supports any URL format that pip accepts, including authenticated URLs like https://username:password@private-mirror.company.com/simple. Ensure you handle credentials securely through environment variables or secret management systems.
Why does the script include --trusted-host mirrors.aliyun.com when using a custom mirror?
This parameter is hardcoded in the repackage function on line 13 and was originally intended to trust the default Aliyun mirror when using HTTP. When using HTTPS mirrors with valid SSL certificates, this flag has no negative effect. However, if your custom mirror uses HTTP and a different hostname, you may need to modify this line in the script to match your --trusted-host requirements.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →