From 09c3585fcfa0d8e078a423f5a52108d1bf31cd8c Mon Sep 17 00:00:00 2001 From: Coleman McFarland Date: Sat, 8 Oct 2022 18:55:06 -0400 Subject: [PATCH] Improve logging during build --- provisioner/cue_export/provisioner.go | 30 +++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/provisioner/cue_export/provisioner.go b/provisioner/cue_export/provisioner.go index 46505c0..2a90003 100644 --- a/provisioner/cue_export/provisioner.go +++ b/provisioner/cue_export/provisioner.go @@ -10,6 +10,7 @@ import ( "os" "cuelang.org/go/cue" + "cuelang.org/go/cue/build" "cuelang.org/go/cue/cuecontext" "cuelang.org/go/cue/load" "github.com/BurntSushi/toml" @@ -54,6 +55,10 @@ type Provisioner struct { // Serialization methods set this buffer, which is then passed to Upload buf *bytes.Buffer + + // cue instanances and value created in Prepare and used in Provision + instances []*build.Instance + value cue.Value } // ConfigSpec is called by Packer to get the HCL version of our config. @@ -89,15 +94,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { } } - // - // TODO: load CUE instances here instead of in Provision()? - // - - return nil -} - -func (p *Provisioner) Provision(_ context.Context, ui packer.Ui, comm packer.Communicator, _generatedData map[string]interface{}) error { - ui.Say("cue provisioner") ctx := cuecontext.New() // load the cue package @@ -121,6 +117,7 @@ func (p *Provisioner) Provision(_ context.Context, ui packer.Ui, comm packer.Com Overlay: nil, Stdin: nil, }) + p.instances = instances if err := instances[0].Err; err != nil { return fmt.Errorf("loading instances: %w", err) } @@ -133,6 +130,17 @@ func (p *Provisioner) Provision(_ context.Context, ui packer.Ui, comm packer.Com expr := cue.ParsePath(p.config.Expression) val = val.LookupPath(expr) } + p.value = val + return nil +} + +func (p *Provisioner) Provision(_ context.Context, ui packer.Ui, comm packer.Communicator, _generatedData map[string]interface{}) error { + ui.Say(fmt.Sprintf("cue-export provisioning file %s", p.config.DestFile)) + + ui.Message(fmt.Sprintf("cue module: %s; package: %s; expression: %s", + p.config.ModuleRoot, p.config.Package, p.config.Expression)) + + val := p.value log.Printf("cue kind: %v\n", val.Kind()) switch val.Kind() { @@ -179,8 +187,8 @@ func (p *Provisioner) Provision(_ context.Context, ui packer.Ui, comm packer.Com return fmt.Errorf("unsuppored CUE kind: %v", val.Kind()) } - // Our buf has been filled; Upload reads it into a remote file. - // TODO(cm) set mode? + // Our buf has been filled; Upload reads it into a remote file. + // TODO(cm) set mode? if err := comm.Upload(p.config.DestFile, p.buf, nil); err != nil { return err }