refactor: extract all generators into independent TOOLS/ modules
Each generator is now a standalone Go module with its own go.mod: TOOLS/ ├── yaml-generator/ ← service_spec_gen (API → YAML) ├── resource-generator/ ← gen_v2 (YAML → Go resources) ├── docs-generator/ ← docs_template_gen_v2 (YAML → Markdown) ├── ops-generator/ ← ops_docs_gen (ops documentation) └── bin/ ← pre-built binaries All scripts updated to use TOOLS/bin/* binaries. Removed old universal_rebuild/tools/ and universal_rebuild/bin/.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// generate_resources_v2 — главный генератор Terraform-провайдера Nubes.
|
||||
//
|
||||
// ⛔ ПОДЧИНЯЕТСЯ devops/ARCHITECTURE.md — все правила генерации прописаны там.
|
||||
//
|
||||
// Пайплайн: YAML-спеки сервисов → Go-ресурсы + registry.go.
|
||||
//
|
||||
// На вход: resources_yaml/*.yaml (сгенерированы service_spec_gen из API).
|
||||
// На выход: internal/resources_gen/*.go (CRUD-ресурсы, subresource'ы, registry).
|
||||
//
|
||||
// Три вида ресурсов:
|
||||
// - instance → nubes_{service} (основной CRUD инстанса)
|
||||
// - subresource → nubes_{service}_{sub} (пользователи, базы, ...)
|
||||
// - action → ТОЛЬКО redeploy встроен как git_revision.
|
||||
// restart/recovery/reconcile исключены (ARCHITECTURE.md).
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"resource-generator/loader"
|
||||
"resource-generator/writers"
|
||||
)
|
||||
|
||||
func main() {
|
||||
root, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
resourcesDir := strings.TrimSpace(os.Getenv("NUBES_RESOURCES_DIR"))
|
||||
if resourcesDir == "" {
|
||||
resourcesDir = filepath.Join(root, "resources_yaml")
|
||||
}
|
||||
outDir := strings.TrimSpace(os.Getenv("NUBES_RESOURCES_GEN_DIR"))
|
||||
if outDir == "" {
|
||||
outDir = filepath.Join(root, "internal", "resources_gen")
|
||||
}
|
||||
|
||||
instanceResources, subresources, actions, err := loader.LoadSpecs(resourcesDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, svc := range instanceResources {
|
||||
if err := writers.WriteInstanceResource(outDir, svc); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
for _, sr := range subresources {
|
||||
if err := writers.WriteSubresource(outDir, sr); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
for _, act := range actions {
|
||||
if err := writers.WriteActionResource(outDir, act); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
if err := writers.WriteRegistry(outDir, instanceResources, subresources, actions); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user