Erik Osterman (Cloud Posse)
02/05/2025, 2:54 PM!repo-root?
https://github.com/cloudposse/atmos/pull/808/files#r1943095714Andriy Knysh (Cloud Posse)
02/06/2025, 1:37 AM!repo-root YAML tag should doAndriy Knysh (Cloud Posse)
02/06/2025, 1:37 AMHaitham
02/06/2025, 1:41 AMAndriy Knysh (Cloud Posse)
02/06/2025, 1:43 AMHaitham
02/06/2025, 1:45 AMfunc GetGitRoot(startPath string) (string, error) {
// Open the repository starting from the given path
repo, err := git.PlainOpenWithOptions(startPath, &git.PlainOpenOptions{
DetectDotGit: true,
})
if err != nil {
return "", fmt.Errorf("failed to open Git repository: %w", err)
}
// Get the worktree to extract the repository's root directory
worktree, err := repo.Worktree()
if err != nil {
return "", fmt.Errorf("failed to get worktree: %w", err)
}
// Return the absolute path to the root directory
rootPath, err := filepath.Abs(worktree.Filesystem.Root())
if err != nil {
return "", fmt.Errorf("failed to resolve absolute path: %w", err)
}
return rootPath, nil
}Haitham
02/06/2025, 1:47 AMHaitham
02/06/2025, 1:47 AMHaitham
02/06/2025, 1:49 AMHaitham
02/06/2025, 1:51 AMHaitham
02/06/2025, 2:55 AM!repo-root. To handle this, we need to preprocess the YAML file to resolve the !repo-root tag before passing it to ViperHaitham
02/06/2025, 2:56 AMHaitham
02/06/2025, 2:57 AMgopkg.in/yaml.v3 package to parse the YAML file and resolve the !repo-root tag. then merge to ViberAndriy Knysh (Cloud Posse)
02/06/2025, 3:06 AMpkg/utils/yaml_utils.go we have
func UnmarshalYAMLFromFile[T any](atmosConfig *schema.AtmosConfiguration, input string, file string) (T, error) {
var zeroValue T
var node yaml.Node
b := []byte(input)
// Unmarshal into yaml.Node
if err := yaml.Unmarshal(b, &node); err != nil {
return zeroValue, err
}
if err := processCustomTags(atmosConfig, &node, file); err != nil {
return zeroValue, err
}
// Decode the yaml.Node into the desired type T
var data T
if err := node.Decode(&data); err != nil {
return zeroValue, err
}
return data, nil
}Andriy Knysh (Cloud Posse)
02/06/2025, 3:07 AMAndriy Knysh (Cloud Posse)
02/06/2025, 3:08 AM!root-repo to the list and process itErik Osterman (Cloud Posse)
02/06/2025, 3:11 AMAndriy Knysh (Cloud Posse)
02/06/2025, 3:11 AMprocessCustomTags does the following: it detects the custom YAML tags and "preserves" them in the Go structure (w/o "preserving", the YAML parser just removes all the tags)Erik Osterman (Cloud Posse)
02/06/2025, 3:12 AMAndriy Knysh (Cloud Posse)
02/06/2025, 3:12 AMinternal/exec/yaml_func_utils.go we have the code to actially process all the tags by calling the corresponding functionsAndriy Knysh (Cloud Posse)
02/06/2025, 3:14 AM!repo-root processing in these places:Andriy Knysh (Cloud Posse)
02/06/2025, 3:15 AMpkg/utils/yaml_utils.go in the getValueWithTag func - see the example for !include. The !include tag is actually processed WHEN we read the YAML files (Atmos manifests)Andriy Knysh (Cloud Posse)
02/06/2025, 3:16 AMinternal/exec/yaml_func_utils.go in the ProcessCustomYamlTags funcAndriy Knysh (Cloud Posse)
02/06/2025, 3:17 AM!repo-root tag), you probably want to process it when you read the YAML file, similar to the !include tag (see the first case above)Andriy Knysh (Cloud Posse)
02/06/2025, 3:18 AMif tag == AtmosYamlFuncRepoRoot {
// call the func to find repo root
return repoRoot
}Haitham
02/06/2025, 3:18 AMAndriy Knysh (Cloud Posse)
02/06/2025, 3:20 AMHaitham
02/06/2025, 3:22 AMHaitham
02/06/2025, 2:17 PM