feat: add Go path configuration to task runner

- Introduced a new method configureGoPath in runner.go to set the GOPATH environment variable based on the retrieved Go path.
- Updated configureEnv to call configureGoPath, ensuring the Go path is configured alongside Node.js paths.
- Added a new utility function GetGoPath in config.go to retrieve the Go path from configuration, with a default fallback.
- These changes enhance the task runner's environment setup by supporting Go development alongside existing Node.js configurations.
This commit is contained in:
Marvin Zhang
2025-01-06 13:42:40 +08:00
parent 99c6f42cf6
commit 8aa801e2ba
2 changed files with 19 additions and 0 deletions

View File

@@ -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())

View File

@@ -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
}