2023-05-21 20:37:38 +00:00
|
|
|
package template
|
|
|
|
|
2023-05-21 20:48:38 +00:00
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
)
|
2023-05-21 20:37:38 +00:00
|
|
|
|
|
|
|
const ConfigFileName = "config.json"
|
2023-05-21 20:48:38 +00:00
|
|
|
const schemaFileName = "schema.json"
|
|
|
|
const templateDirName = "template"
|
2023-05-21 20:37:38 +00:00
|
|
|
|
2023-05-23 13:47:48 +00:00
|
|
|
func Materialize(templateRoot, instanceRoot, configPath string) error {
|
2023-05-21 20:37:38 +00:00
|
|
|
// read the file containing schema for template input parameters
|
2023-05-23 13:47:48 +00:00
|
|
|
schema, err := ReadSchema(filepath.Join(templateRoot, schemaFileName))
|
2023-05-21 20:37:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// read user config to initalize the template with
|
2023-05-22 03:58:05 +00:00
|
|
|
config, err := schema.ReadConfig(configPath)
|
2023-05-21 20:37:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// materialize the template
|
2023-05-23 13:47:48 +00:00
|
|
|
return walkFileTree(config, filepath.Join(templateRoot, templateDirName), instanceRoot)
|
2023-05-21 20:37:38 +00:00
|
|
|
}
|