packer/packer/cmd_builder.go
hashicorp-copywrite[bot] 19055df3ec
[COMPLIANCE] License changes (#12568)
* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl.

* Update copyright file headers to BUSL-1.1

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-10 15:53:29 -07:00

52 lines
996 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package packer
import (
"context"
"log"
"github.com/hashicorp/hcl/v2/hcldec"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
)
type cmdBuilder struct {
builder packersdk.Builder
client *PluginClient
}
func (b *cmdBuilder) ConfigSpec() hcldec.ObjectSpec {
defer func() {
r := recover()
b.checkExit(r, nil)
}()
return b.builder.ConfigSpec()
}
func (b *cmdBuilder) Prepare(config ...interface{}) ([]string, []string, error) {
defer func() {
r := recover()
b.checkExit(r, nil)
}()
return b.builder.Prepare(config...)
}
func (b *cmdBuilder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) (packersdk.Artifact, error) {
defer func() {
r := recover()
b.checkExit(r, nil)
}()
return b.builder.Run(ctx, ui, hook)
}
func (c *cmdBuilder) checkExit(p interface{}, cb func()) {
if c.client.Exited() && cb != nil {
cb()
} else if p != nil && !Killed {
log.Panic(p)
}
}