Skip to content

Commit

Permalink
add DUMP_OVERLAYS_TO env var
Browse files Browse the repository at this point in the history
  • Loading branch information
nxcc committed Aug 28, 2023
1 parent 18331ea commit 4e06223
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ be supported in the future.
"https://$GITLAB_TOKEN@gitlab.noris.net/mcs/components/cuegen/wekan.git?ref=v6.71-mcs.0",
]
debug: false // print some info useful for debugging
dumpOverlays: false // dump overlays for debugging
}

## Environment Variables
Expand All @@ -83,6 +82,7 @@ Some environment variables can help working with cuegen:
CUEGEN_DEBUG turn on debug output with "true"
CUEGEN_HTTP_PASSWORD password for git authentication
CUEGEN_HTTP_USERNAME username for git authentication
DUMP_OVERLAYS_TO directory to dump overlays to (debug only)
SOPS_AGE_KEY age key for decryption
SOPS_AGE_KEY_FILE age key file for decryption
YQ_PRETTYPRINT !="": run yaml output thru `yq -P`
Expand Down Expand Up @@ -200,7 +200,8 @@ Load all files from directory `scripts` as key/values into `configMap.scripts.da
* `v0.7.2` - internal cleanup
* `v0.8.0` - allow remote cuegen directories, rm kustomize plugin support
* `v0.9.0` - upgrade cue to v0.6.0
* `v0.10.0` - add YQ_PRETTYPRINT to filter output thru `yq -P`
* `v0.10.0` - add `YQ_PRETTYPRINT` to filter output thru `yq -P`
* `v0.11.0` - add `DUMP_OVERLAYS_TO` to dump overlays to directory (debug)

[CUE]: https://cuelang.org
[SOPS]: https://github.com/mozilla/sops
Expand Down
1 change: 0 additions & 1 deletion internal/app/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ cuegen: close({
checkPaths?: [ ...string]
secretDataPath: *"" | string
debug: *false | bool
dumpOverlays: *false | bool
components?: [string, ...]
})
9 changes: 7 additions & 2 deletions internal/cuegen/cuegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,13 @@ func (cg Cuegen) buildLoadConfig() (*load.Config, error) {
if cg.Debug {
log.Printf(" * %v -> %v", filename, path)
}
if cg.DumpOverlays {
os.WriteFile(overlayFilename, data, 0644)
if cg.DumpOverlaysTo != "" {
path := filepath.Join(cg.DumpOverlaysTo, overlayFilename)
err := os.WriteFile(path, data, 0644)
if err != nil {
return err
}
fmt.Printf(">>> dumped overlay to %v\n", overlayFilename)
}
} else {
if cg.Debug {
Expand Down
11 changes: 8 additions & 3 deletions internal/cuegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type Config struct {
} `yaml:"metadata"`
Components []string `yaml:"components"`
Debug bool `yaml:"debug"`
DumpOverlays bool `yaml:"dumpOverlays"`
ObjectsPath string `yaml:"objectsPath"`
SecretDataPath string `yaml:"secretDataPath"`
ChartRoot string
Expand All @@ -65,7 +64,7 @@ type Cuegen struct {
SecretDataPath string
CheckPaths []string
ChartRoot string
DumpOverlays bool
DumpOverlaysTo string
RootFS *fs.FS
}

Expand Down Expand Up @@ -93,10 +92,16 @@ func Exec(config Config) error {
ObjectsPath: config.ObjectsPath,
ChartRoot: config.ChartRoot,
SecretDataPath: config.SecretDataPath,
DumpOverlays: config.DumpOverlays,
RootFS: config.RootFS,
}

if dumpDir := os.Getenv("DUMP_OVERLAYS_TO"); dumpDir != "" && strings.HasPrefix(dumpDir, "/") {
if _, err := os.Stat(dumpDir); err != nil {
return fmt.Errorf("Exec: DUMP_OVERLAYS_TO: %v", err)
}
cg.DumpOverlaysTo = dumpDir
}

if config.CheckPath != "" {
cg.CheckPaths = []string{config.CheckPath}
}
Expand Down
16 changes: 9 additions & 7 deletions tests/local/components-dump.txtar
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
### components-dump.txtar

# components: dump overlays
exec cuegen chart
exec find
stdout overlay-ORBY4AOZPH--a.cue
stdout overlay-CUUTIGWCVW--b.cue
cmp chart/overlay-ORBY4AOZPH--a.cue comp_a/a.cue
cmp chart/overlay-CUUTIGWCVW--b.cue comp_b/b.cue

exec mkdir OUT
exec bash '-c' 'DUMP_OVERLAYS_TO=$WORK/OUT cuegen chart'
stdout 'dumped overlay to overlay-CUUTIGWCVW--b.cue'
stdout 'dumped overlay to overlay-remoteRootFS--a.cue'
stdout 'dumped overlay to overlay-ORBY4AOZPH--a.cue'

cmp OUT/overlay-ORBY4AOZPH--a.cue comp_a/a.cue
cmp OUT/overlay-CUUTIGWCVW--b.cue comp_b/b.cue

-- chart/cuegen.yaml --
dumpOverlays: true
components:
- ../comp_a
- ../comp_b
Expand Down

0 comments on commit 4e06223

Please sign in to comment.