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