diff --git a/core/task/handler/runner.go b/core/task/handler/runner.go index 6bfadba4..13611c1f 100644 --- a/core/task/handler/runner.go +++ b/core/task/handler/runner.go @@ -353,6 +353,14 @@ func (r *Runner) configureNodePath() { _ = os.Setenv("NODE_PATH", nodePath) } +func (r *Runner) configureGoPath() { + // Configure global go path + goPath := utils.GetGoPath() + if goPath != "" { + _ = os.Setenv("GOPATH", goPath) + } +} + // configureEnv sets up the environment variables for the task process, including: // - Node.js paths // - Crawlab-specific variables @@ -361,6 +369,9 @@ func (r *Runner) configureEnv() { // Configure Node.js paths r.configureNodePath() + // Configure Go path + r.configureGoPath() + // Default envs r.cmd.Env = os.Environ() r.cmd.Env = append(r.cmd.Env, "CRAWLAB_TASK_ID="+r.tid.Hex()) diff --git a/core/utils/config.go b/core/utils/config.go index f798c2ff..0b924c0d 100644 --- a/core/utils/config.go +++ b/core/utils/config.go @@ -32,6 +32,7 @@ const ( MetadataConfigName = "config.json" PyenvRoot = "/root/.pyenv" DefaultNodeModulesPath = "/usr/lib/node_modules" + DefaultGoPath = "/root/go" ) func IsDev() bool { @@ -255,3 +256,10 @@ func GetNodeModulesPath() string { } return DefaultNodeModulesPath } + +func GetGoPath() string { + if res := viper.GetString("install.go.path"); res != "" { + return res + } + return DefaultGoPath +}