I'm trying to cleanup my build by using Workspace APIs from 0.20.5.
We use asdf and mise to control versions of our tools, and I'd like the build to reuse the same metadata.
The code looks something like:
func VersionOf(toolName string, defaultVersion string, ctx context.Context, workspace *dagger.Workspace) (string, error) {
wsPath, err := workspace.Path(ctx)
if err != nil {
return "", err
}
fnames := []string{".tool-versions", ".mise.local.toml", ".mise.toml"}
curDir := wsPath
for {
for _, fname := range fnames {
ffname := filepath.Join(curDir, fname)
fileContents, err := workspace.File("/" + ffname).Contents(ctx)
if err == nil {
...
}
}
if curDir == "" || curDir == "." {
break
}
curDir = filepath.Dir(curDir)
}
if defaultVersion == "" {
return defaultVersion, fmt.Errorf("no %s version found in %s", toolName, wsPath)
}
return defaultVersion, nil
}
It may be just my imagination but the call workspace.File("/" + ffname).Contents(ctx) seems to be trying to sync the entire directory of the file so it's prohibitely expensive.
All these calls are meant to be done during module initialization, is this a valid use-case for the API?