Skip to content

Commit

Permalink
feat: add Go path configuration to task runner
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Marvin Zhang committed Jan 6, 2025
1 parent 99c6f42 commit 8aa801e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/task/handler/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down
8 changes: 8 additions & 0 deletions core/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
MetadataConfigName = "config.json"
PyenvRoot = "/root/.pyenv"
DefaultNodeModulesPath = "/usr/lib/node_modules"
DefaultGoPath = "/root/go"
)

func IsDev() bool {
Expand Down Expand Up @@ -255,3 +256,10 @@ func GetNodeModulesPath() string {
}
return DefaultNodeModulesPath
}

func GetGoPath() string {
if res := viper.GetString("install.go.path"); res != "" {
return res
}
return DefaultGoPath
}

0 comments on commit 8aa801e

Please sign in to comment.