post-processor/manifest: allow to strip path components from artifact path

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
Vasiliy Tolstov 2016-08-09 17:41:21 +03:00
parent 4868f5872e
commit fe76081e0a
2 changed files with 15 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"
"time"
"github.com/mitchellh/packer/common"
@ -17,9 +18,9 @@ import (
type Config struct {
common.PackerConfig `mapstructure:",squash"`
Filename string `mapstructure:"filename"`
ctx interpolate.Context
Filename string `mapstructure:"filename"`
StripPath bool `mapstructure:"strip_path"`
ctx interpolate.Context
}
type PostProcessor struct {
@ -58,11 +59,16 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, source packer.Artifact) (packe
// Create the current artifact.
for _, name := range source.Files() {
af := ArtifactFile{}
if fi, err = os.Stat(name); err == nil {
artifact.ArtifactFiles = append(artifact.ArtifactFiles, ArtifactFile{Name: name, Size: fi.Size()})
} else {
artifact.ArtifactFiles = append(artifact.ArtifactFiles, ArtifactFile{Name: name})
af.Size = fi.Size()
}
if p.config.StripPath {
af.Name = filepath.Base(name)
} else {
af.Name = name
}
artifact.ArtifactFiles = append(artifact.ArtifactFiles, af)
}
artifact.ArtifactId = source.Id()
artifact.BuilderType = p.config.PackerBuilderType

View File

@ -22,6 +22,7 @@ You can specify manifest more than once and write each build to its own file, or
### Optional:
- `filename` (string) The manifest will be written to this file. This defaults to `packer-manifest.json`.
- `strip_path` (bool) Write only filename without the path to the manifest file. This defaults to false.
### Example Configuration
@ -32,7 +33,8 @@ You can simply add `{"type":"manifest"}` to your post-processor section. Below i
"post-processors": [
{
"type": "manifest",
"filename": "manifest.json"
"filename": "manifest.json",
"strip_path": true
}
]
}