fix vagrant box structure
This commit is contained in:
parent
8e18baf493
commit
d57517d4a4
|
@ -3,7 +3,9 @@ package vagrant
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HypervProvider struct{}
|
type HypervProvider struct{}
|
||||||
|
@ -16,14 +18,48 @@ func (p *HypervProvider) Process(ui packer.Ui, artifact packer.Artifact, dir str
|
||||||
// Create the metadata
|
// Create the metadata
|
||||||
metadata = map[string]interface{}{"provider": "hyperv"}
|
metadata = map[string]interface{}{"provider": "hyperv"}
|
||||||
|
|
||||||
|
// ui.Message(fmt.Sprintf("artifacts all: %+v", artifact))
|
||||||
|
var outputDir string
|
||||||
|
|
||||||
|
// Vargant requires specific dir structure for hyperv
|
||||||
|
// hyperv builder creates the structure in the output dir
|
||||||
|
// we have to keep the structure in a temp dir
|
||||||
|
// hack little bit but string in artifact usually have output dir
|
||||||
|
artifactString := artifact.String()
|
||||||
|
d := strings.Split(artifactString, ": ")
|
||||||
|
outputDir = d[1]
|
||||||
|
// ui.Message(fmt.Sprintf("artifact dir from string: %s", outputDir))
|
||||||
|
|
||||||
// Copy all of the original contents into the temporary directory
|
// Copy all of the original contents into the temporary directory
|
||||||
for _, path := range artifact.Files() {
|
for _, path := range artifact.Files() {
|
||||||
ui.Message(fmt.Sprintf("Copying: %s", path))
|
ui.Message(fmt.Sprintf("Copying: %s", path))
|
||||||
|
|
||||||
dstPath := filepath.Join(dir, filepath.Base(path))
|
var rel string
|
||||||
if err = CopyContents(dstPath, path); err != nil {
|
|
||||||
|
rel, err = filepath.Rel(outputDir, filepath.Dir(path))
|
||||||
|
// ui.Message(fmt.Sprintf("rel is: %s", rel))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
ui.Message(fmt.Sprintf("err in: %s", rel))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dstDir := filepath.Join(dir, rel)
|
||||||
|
// ui.Message(fmt.Sprintf("dstdir is: %s", dstDir))
|
||||||
|
if _, err = os.Stat(dstDir); err != nil {
|
||||||
|
if err = os.MkdirAll(dstDir, 0755); err != nil {
|
||||||
|
ui.Message(fmt.Sprintf("err in creating: %s", dstDir))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dstPath := filepath.Join(dstDir, filepath.Base(path))
|
||||||
|
|
||||||
|
if err = CopyContents(dstPath, path); err != nil {
|
||||||
|
ui.Message(fmt.Sprintf("err in copying: %s to %s", path, dstPath))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ui.Message(fmt.Sprintf("Copyed %s to %s", path, dstPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue