浏览代码

add proxy for runtime

非法操作 6 月之前
父节点
当前提交
7b47d8b79a

+ 4 - 0
.env.example

@@ -65,3 +65,7 @@ PPROF_ENABLED=false
 # FORCE_VERIFYING_SIGNATURE, for security, you should set this to true, pls be sure you know what you are doing
 # FORCE_VERIFYING_SIGNATURE, for security, you should set this to true, pls be sure you know what you are doing
 # if want to install plugin without verifying signature, set this to false
 # if want to install plugin without verifying signature, set this to false
 FORCE_VERIFYING_SIGNATURE=true
 FORCE_VERIFYING_SIGNATURE=true
+
+# proxy settings, example: PROXY_HTTP=http://host.docker.internal:7890
+PROXY_HTTP=
+PROXY_HTTPS=

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

@@ -129,7 +129,7 @@ func (p *PluginManager) launchLocal(pluginUniqueIdentifier plugin_entities.Plugi
 		return nil, nil, nil, failed(err.Error())
 		return nil, nil, nil, failed(err.Error())
 	}
 	}
 
 
-	localPluginRuntime := local_runtime.NewLocalPluginRuntime(p.pythonInterpreterPath)
+	localPluginRuntime := local_runtime.NewLocalPluginRuntime(p.pythonInterpreterPath, p.proxyHttp, p.proxyHttps)
 	localPluginRuntime.PluginRuntime = plugin.runtime
 	localPluginRuntime.PluginRuntime = plugin.runtime
 	localPluginRuntime.BasicChecksum = basic_runtime.BasicChecksum{
 	localPluginRuntime.BasicChecksum = basic_runtime.BasicChecksum{
 		MediaTransport: basic_runtime.NewMediaTransport(p.mediaBucket),
 		MediaTransport: basic_runtime.NewMediaTransport(p.mediaBucket),

+ 6 - 0
internal/core/plugin_manager/local_runtime/run.go

@@ -36,6 +36,12 @@ func (r *LocalPluginRuntime) getCmd() (*exec.Cmd, error) {
 	if r.Config.Meta.Runner.Language == constants.Python {
 	if r.Config.Meta.Runner.Language == constants.Python {
 		cmd := exec.Command(r.pythonInterpreterPath, "-m", r.Config.Meta.Runner.Entrypoint)
 		cmd := exec.Command(r.pythonInterpreterPath, "-m", r.Config.Meta.Runner.Entrypoint)
 		cmd.Dir = r.State.WorkingPath
 		cmd.Dir = r.State.WorkingPath
+		if r.proxyHttps != "" {
+			cmd.Env = append(cmd.Env, fmt.Sprintf("HTTPS_PROXY=%s", r.proxyHttps))
+		}
+		if r.proxyHttp != "" {
+			cmd.Env = append(cmd.Env, fmt.Sprintf("HTTP_PROXY=%s", r.proxyHttp))
+		}
 		return cmd, nil
 		return cmd, nil
 	}
 	}
 
 

+ 8 - 0
internal/core/plugin_manager/local_runtime/type.go

@@ -21,6 +21,10 @@ type LocalPluginRuntime struct {
 	// by using its venv module
 	// by using its venv module
 	defaultPythonInterpreterPath string
 	defaultPythonInterpreterPath string
 
 
+	// proxy settings
+	proxyHttp  string
+	proxyHttps string
+
 	waitChanLock    sync.Mutex
 	waitChanLock    sync.Mutex
 	waitStartedChan []chan bool
 	waitStartedChan []chan bool
 	waitStoppedChan []chan bool
 	waitStoppedChan []chan bool
@@ -30,8 +34,12 @@ type LocalPluginRuntime struct {
 
 
 func NewLocalPluginRuntime(
 func NewLocalPluginRuntime(
 	pythonInterpreterPath string,
 	pythonInterpreterPath string,
+	proxyHttp string,
+	proxyHttps string,
 ) *LocalPluginRuntime {
 ) *LocalPluginRuntime {
 	return &LocalPluginRuntime{
 	return &LocalPluginRuntime{
 		defaultPythonInterpreterPath: pythonInterpreterPath,
 		defaultPythonInterpreterPath: pythonInterpreterPath,
+		proxyHttp:                    proxyHttp,
+		proxyHttps:                   proxyHttps,
 	}
 	}
 }
 }

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

@@ -56,6 +56,10 @@ type PluginManager struct {
 	// python interpreter path
 	// python interpreter path
 	pythonInterpreterPath string
 	pythonInterpreterPath string
 
 
+	// proxy settings
+	proxyHttp  string
+	proxyHttps string
+
 	// remote plugin server
 	// remote plugin server
 	remotePluginServer debugging_runtime.RemotePluginServerInterface
 	remotePluginServer debugging_runtime.RemotePluginServerInterface
 
 
@@ -92,6 +96,8 @@ func InitGlobalManager(oss oss.OSS, configuration *app.Config) *PluginManager {
 		maxLaunchingLock:         make(chan bool, 2), // by default, we allow 2 plugins launching at the same time
 		maxLaunchingLock:         make(chan bool, 2), // by default, we allow 2 plugins launching at the same time
 		pythonInterpreterPath:    configuration.PythonInterpreterPath,
 		pythonInterpreterPath:    configuration.PythonInterpreterPath,
 		platform:                 configuration.Platform,
 		platform:                 configuration.Platform,
+		proxyHttp:                configuration.ProxyHttp,
+		proxyHttps:               configuration.ProxyHttps,
 	}
 	}
 
 
 	return manager
 	return manager

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

@@ -93,6 +93,10 @@ type Config struct {
 	SentryTracingEnabled   bool    `envconfig:"SENTRY_TRACING_ENABLED"`
 	SentryTracingEnabled   bool    `envconfig:"SENTRY_TRACING_ENABLED"`
 	SentryTracesSampleRate float64 `envconfig:"SENTRY_TRACES_SAMPLE_RATE"`
 	SentryTracesSampleRate float64 `envconfig:"SENTRY_TRACES_SAMPLE_RATE"`
 	SentrySampleRate       float64 `envconfig:"SENTRY_SAMPLE_RATE"`
 	SentrySampleRate       float64 `envconfig:"SENTRY_SAMPLE_RATE"`
+
+	// proxy settings
+	ProxyHttp  string `envconfig:"PROXY_HTTP"`
+	ProxyHttps string `envconfig:"PROXY_HTTPS"`
 }
 }
 
 
 func (c *Config) Validate() error {
 func (c *Config) Validate() error {