2013-06-18 16:49:07 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
2019-03-22 09:56:02 -04:00
|
|
|
"context"
|
2013-06-18 16:49:07 -04:00
|
|
|
"log"
|
2018-01-22 20:21:10 -05:00
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
2020-12-17 16:29:25 -05:00
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2013-06-18 16:49:07 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type cmdPostProcessor struct {
|
2020-12-01 17:48:55 -05:00
|
|
|
p packersdk.PostProcessor
|
2013-06-18 16:49:07 -04:00
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
func (b *cmdPostProcessor) ConfigSpec() hcldec.ObjectSpec {
|
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
b.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
|
|
|
return b.p.ConfigSpec()
|
|
|
|
}
|
|
|
|
|
2013-07-01 17:59:23 -04:00
|
|
|
func (c *cmdPostProcessor) Configure(config ...interface{}) error {
|
2013-06-18 16:49:07 -04:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
c.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
2013-07-01 17:59:23 -04:00
|
|
|
return c.p.Configure(config...)
|
2013-06-18 16:49:07 -04:00
|
|
|
}
|
|
|
|
|
2020-11-19 15:17:11 -05:00
|
|
|
func (c *cmdPostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, a packersdk.Artifact) (packersdk.Artifact, bool, bool, error) {
|
2013-06-18 16:49:07 -04:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
c.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
2019-03-22 09:56:02 -04:00
|
|
|
return c.p.PostProcess(ctx, ui, a)
|
2013-06-18 16:49:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) {
|
2015-05-29 14:30:56 -04:00
|
|
|
if c.client.Exited() && cb != nil {
|
2013-06-18 16:49:07 -04:00
|
|
|
cb()
|
2013-08-20 02:38:22 -04:00
|
|
|
} else if p != nil && !Killed {
|
2013-06-18 16:49:07 -04:00
|
|
|
log.Panic(p)
|
|
|
|
}
|
|
|
|
}
|