| 62 | func (p *PostProcessor) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() } |
| 63 | |
| 64 | func (p *PostProcessor) Configure(raws ...interface{}) error { |
| 65 | err := config.Decode(&p.config, &config.DecodeOpts{ |
| 66 | PluginType: "compress", |
| 67 | Interpolate: true, |
| 68 | InterpolateContext: &p.config.ctx, |
| 69 | InterpolateFilter: &interpolate.RenderFilter{ |
| 70 | Exclude: []string{"output"}, |
| 71 | }, |
| 72 | }, raws...) |
| 73 | if err != nil { |
| 74 | return err |
| 75 | } |
| 76 | |
| 77 | errs := new(packersdk.MultiError) |
| 78 | |
| 79 | // If there is no explicit number of Go threads to use, then set it |
| 80 | if os.Getenv("GOMAXPROCS") == "" { |
| 81 | runtime.GOMAXPROCS(runtime.NumCPU()) |
| 82 | } |
| 83 | |
| 84 | if p.config.OutputPath == "" { |
| 85 | p.config.OutputPath = "packer_{{.BuildName}}_{{.BuilderType}}" |
| 86 | } |
| 87 | |
| 88 | if p.config.CompressionLevel > pgzip.BestCompression { |
| 89 | p.config.CompressionLevel = pgzip.BestCompression |
| 90 | } |
| 91 | // Technically 0 means "don't compress" but I don't know how to |
| 92 | // differentiate between "user entered zero" and "user entered nothing". |
| 93 | // Also, why bother creating a compressed file with zero compression? |
| 94 | if p.config.CompressionLevel == -1 || p.config.CompressionLevel == 0 { |
| 95 | p.config.CompressionLevel = pgzip.DefaultCompression |
| 96 | } |
| 97 | |
| 98 | if err = interpolate.Validate(p.config.OutputPath, &p.config.ctx); err != nil { |
| 99 | errs = packersdk.MultiErrorAppend( |
| 100 | errs, fmt.Errorf("Error parsing target template: %s", err)) |
| 101 | } |
| 102 | |
| 103 | p.config.detectFromFilename() |
| 104 | |
| 105 | if len(errs.Errors) > 0 { |
| 106 | return errs |
| 107 | } |
| 108 | |
| 109 | return nil |
| 110 | } |
| 111 | |
| 112 | func (p *PostProcessor) PostProcess( |
| 113 | ctx context.Context, |