Browse Source

fix: allow pipMirrorUrl to be configured through envs (#15)

Yeuoly 6 months ago
parent
commit
19ee9fc63d

+ 7 - 1
internal/core/plugin_manager/launcher.go

@@ -129,7 +129,13 @@ func (p *PluginManager) launchLocal(pluginUniqueIdentifier plugin_entities.Plugi
 		return nil, nil, nil, failed(err.Error())
 	}
 
-	localPluginRuntime := local_runtime.NewLocalPluginRuntime(p.pythonInterpreterPath, p.pythonEnvInitTimeout, p.HttpProxy, p.HttpsProxy)
+	localPluginRuntime := local_runtime.NewLocalPluginRuntime(local_runtime.LocalPluginRuntimeConfig{
+		PythonInterpreterPath: p.pythonInterpreterPath,
+		PythonEnvInitTimeout:  p.pythonEnvInitTimeout,
+		HttpProxy:             p.HttpProxy,
+		HttpsProxy:            p.HttpsProxy,
+		PipMirrorUrl:          p.pipMirrorUrl,
+	})
 	localPluginRuntime.PluginRuntime = plugin.runtime
 	localPluginRuntime.BasicChecksum = basic_runtime.BasicChecksum{
 		MediaTransport: basic_runtime.NewMediaTransport(p.mediaBucket),

+ 15 - 1
internal/core/plugin_manager/local_runtime/environment_python.go

@@ -89,7 +89,21 @@ func (p *LocalPluginRuntime) InitPythonEnvironment() error {
 	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
 	defer cancel()
 
-	cmd = exec.CommandContext(ctx, pipPath, "install", "-r", "requirements.txt")
+	args := []string{"install"}
+
+	if p.HttpProxy != "" {
+		args = append(args, "--proxy", p.HttpProxy)
+	} else if p.HttpsProxy != "" {
+		args = append(args, "--proxy", p.HttpsProxy)
+	}
+
+	if p.pipMirrorUrl != "" {
+		args = append(args, "-i", p.pipMirrorUrl)
+	}
+
+	args = append(args, "-r", "requirements.txt")
+
+	cmd = exec.CommandContext(ctx, pipPath, args...)
 	cmd.Dir = p.State.WorkingPath
 
 	// get stdout and stderr

+ 16 - 10
internal/core/plugin_manager/local_runtime/type.go

@@ -24,6 +24,8 @@ type LocalPluginRuntime struct {
 	// by using its venv module
 	defaultPythonInterpreterPath string
 
+	pipMirrorUrl string
+
 	// proxy settings
 	HttpProxy  string
 	HttpsProxy string
@@ -35,16 +37,20 @@ type LocalPluginRuntime struct {
 	isNotFirstStart bool
 }
 
-func NewLocalPluginRuntime(
-	pythonInterpreterPath string,
-	pythonEnvInitTimeout int,
-	HttpProxy string,
-	HttpsProxy string,
-) *LocalPluginRuntime {
+type LocalPluginRuntimeConfig struct {
+	PythonInterpreterPath string
+	PythonEnvInitTimeout  int
+	HttpProxy             string
+	HttpsProxy            string
+	PipMirrorUrl          string
+}
+
+func NewLocalPluginRuntime(config LocalPluginRuntimeConfig) *LocalPluginRuntime {
 	return &LocalPluginRuntime{
-		defaultPythonInterpreterPath: pythonInterpreterPath,
-		pythonEnvInitTimeout:         pythonEnvInitTimeout,
-		HttpProxy:                    HttpProxy,
-		HttpsProxy:                   HttpsProxy,
+		defaultPythonInterpreterPath: config.PythonInterpreterPath,
+		pythonEnvInitTimeout:         config.PythonEnvInitTimeout,
+		HttpProxy:                    config.HttpProxy,
+		HttpsProxy:                   config.HttpsProxy,
+		pipMirrorUrl:                 config.PipMirrorUrl,
 	}
 }

+ 4 - 0
internal/core/plugin_manager/manager.go

@@ -63,6 +63,9 @@ type PluginManager struct {
 	HttpProxy  string
 	HttpsProxy string
 
+	// pip mirror url
+	pipMirrorUrl string
+
 	// remote plugin server
 	remotePluginServer debugging_runtime.RemotePluginServerInterface
 
@@ -102,6 +105,7 @@ func InitGlobalManager(oss oss.OSS, configuration *app.Config) *PluginManager {
 		platform:                 configuration.Platform,
 		HttpProxy:                configuration.HttpProxy,
 		HttpsProxy:               configuration.HttpsProxy,
+		pipMirrorUrl:             configuration.PipMirrorUrl,
 	}
 
 	return manager

+ 1 - 0
internal/types/app/config.go

@@ -83,6 +83,7 @@ type Config struct {
 
 	PythonInterpreterPath string `envconfig:"PYTHON_INTERPRETER_PATH"`
 	PythonEnvInitTimeout  int    `envconfig:"PYTHON_ENV_INIT_TIMEOUT" validate:"required"`
+	PipMirrorUrl          string `envconfig:"PIP_MIRROR_URL"`
 
 	DisplayClusterLog bool `envconfig:"DISPLAY_CLUSTER_LOG"`