Merge pull request #3790 from yoctocloud/manifest
post-processor/manifest: add artifact file size to manifest
This commit is contained in:
commit
c5e9944969
|
@ -4,13 +4,18 @@ import "fmt"
|
|||
|
||||
const BuilderId = "packer.post-processor.manifest"
|
||||
|
||||
type ArtifactFile struct {
|
||||
Name string `json:"name"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
type Artifact struct {
|
||||
BuildName string `json:"name"`
|
||||
BuilderType string `json:"builder_type"`
|
||||
BuildTime int64 `json:"build_time"`
|
||||
ArtifactFiles []string `json:"files"`
|
||||
ArtifactId string `json:"artifact_id"`
|
||||
PackerRunUUID string `json:"packer_run_uuid"`
|
||||
BuildName string `json:"name"`
|
||||
BuilderType string `json:"builder_type"`
|
||||
BuildTime int64 `json:"build_time"`
|
||||
ArtifactFiles []ArtifactFile `json:"files"`
|
||||
ArtifactId string `json:"artifact_id"`
|
||||
PackerRunUUID string `json:"packer_run_uuid"`
|
||||
}
|
||||
|
||||
func (a *Artifact) BuilderId() string {
|
||||
|
@ -18,7 +23,11 @@ func (a *Artifact) BuilderId() string {
|
|||
}
|
||||
|
||||
func (a *Artifact) Files() []string {
|
||||
return a.ArtifactFiles
|
||||
var files []string
|
||||
for _, af := range a.ArtifactFiles {
|
||||
files = append(files, af.Name)
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
func (a *Artifact) Id() string {
|
||||
|
|
|
@ -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 {
|
||||
|
@ -54,9 +55,21 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, source packer.Artifact) (packe
|
|||
artifact := &Artifact{}
|
||||
|
||||
var err error
|
||||
var fi os.FileInfo
|
||||
|
||||
// Create the current artifact.
|
||||
artifact.ArtifactFiles = source.Files()
|
||||
for _, name := range source.Files() {
|
||||
af := ArtifactFile{}
|
||||
if fi, err = os.Stat(name); err == nil {
|
||||
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
|
||||
artifact.BuildName = p.config.PackerBuildName
|
||||
|
|
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue