WIP
This commit is contained in:
parent
2db0a03142
commit
098764d8ac
|
@ -34,7 +34,7 @@ func (b *Builder) Prepare(rawConfig ...interface{}) ([]string, error) {
|
|||
|
||||
var errs *packer.MultiError
|
||||
|
||||
errs = packer.MultiErrorAppend(errs, b.config.PVConfig.Prepare(&b.config.ctx).Errors...)
|
||||
errs = packer.MultiErrorAppend(errs, b.config.PVConfig.Prepare(&b.config.ctx))
|
||||
|
||||
if errs != nil && len(errs.Errors) > 0 {
|
||||
return nil, errs
|
||||
|
@ -70,7 +70,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
runID := uuid.TimeOrderedUUID()
|
||||
|
||||
var steps []multistep.Step
|
||||
if b.config.PersistentVolumeSize > 0 {
|
||||
if b.config.IsPV() {
|
||||
steps = []multistep.Step{
|
||||
&stepCreatePersistentVolume{
|
||||
volumeSize: fmt.Sprintf("%d", b.config.PersistentVolumeSize),
|
||||
|
@ -115,7 +115,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
Host: ocommon.CommHost,
|
||||
SSHConfig: b.config.Comm.SSHConfigFunc(),
|
||||
},
|
||||
&stepCreateImage{},
|
||||
&stepCreateImage{
|
||||
uploadImageCommand: b.config.BuilderUploadImageCommand,
|
||||
},
|
||||
}
|
||||
} else {
|
||||
// Build the steps
|
||||
|
|
|
@ -7,10 +7,9 @@ import (
|
|||
|
||||
type PVConfig struct {
|
||||
// PersistentVolumeSize lets us control the volume size by using persistent boot storage
|
||||
PersistentVolumeSize int `mapstructure:"persistent_volume_size"`
|
||||
BuilderImageList string `mapstructure:"builder_image_list"`
|
||||
BuilderInstallUploadToolCommand string `mapstructure:"builder_install_upload_tool_command"`
|
||||
BuilderUploadImageCommand string `mapstructure:"builder_upload_image_command"`
|
||||
PersistentVolumeSize int `mapstructure:"persistent_volume_size"`
|
||||
BuilderImageList string `mapstructure:"builder_image_list"`
|
||||
BuilderUploadImageCommand string `mapstructure:"builder_upload_image_command"`
|
||||
/* TODO:
|
||||
default to OL image
|
||||
make sure if set then PVS is above
|
||||
|
@ -19,8 +18,12 @@ type PVConfig struct {
|
|||
*/
|
||||
}
|
||||
|
||||
func (c *PVConfig) IsPV() bool {
|
||||
return c.PersistentVolumeSize > 0
|
||||
}
|
||||
|
||||
func (c *PVConfig) Prepare(ctx *interpolate.Context) (errs *packer.MultiError) {
|
||||
if c.PersistentVolumeSize == 0 {
|
||||
if !c.IsPV() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -31,6 +34,7 @@ func (c *PVConfig) Prepare(ctx *interpolate.Context) (errs *packer.MultiError) {
|
|||
--retry-delay 0 \
|
||||
-o {{ .DiskImagePath }} \
|
||||
'...'`
|
||||
c.BuilderUploadImageCommand = "false"
|
||||
}
|
||||
/*
|
||||
errs = packer.MultiErrorAppend(errs,
|
||||
|
|
|
@ -11,8 +11,7 @@ import (
|
|||
)
|
||||
|
||||
type stepCreateImage struct {
|
||||
installUploadToolCommand string
|
||||
uploadImageCommand string
|
||||
uploadImageCommand string
|
||||
}
|
||||
|
||||
type uploadCmdData struct {
|
||||
|
@ -38,7 +37,6 @@ func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multi
|
|||
|
||||
command := fmt.Sprintf(`#!/bin/sh
|
||||
set -e
|
||||
%s
|
||||
mkdir /builder
|
||||
mkfs -t ext3 /dev/xvdb
|
||||
mount /dev/xvdb /builder
|
||||
|
@ -46,7 +44,7 @@ func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multi
|
|||
cd /builder
|
||||
dd if=/dev/xvdc bs=8M status=progress | cp --sparse=always /dev/stdin diskimage.raw
|
||||
tar czSf ./diskimage.tar.gz ./diskimage.raw
|
||||
%s`, s.installUploadToolCommand, uploadImageCmd)
|
||||
%s`, uploadImageCmd)
|
||||
|
||||
dest := "/tmp/create-packer-diskimage.sh"
|
||||
comm.Upload(dest, strings.NewReader(command), nil)
|
||||
|
|
|
@ -37,7 +37,16 @@ func MultiErrorAppend(err error, errs ...error) *MultiError {
|
|||
err = new(MultiError)
|
||||
}
|
||||
|
||||
err.Errors = append(err.Errors, errs...)
|
||||
for _, verr := range errs {
|
||||
switch rhsErr := verr.(type) {
|
||||
case *MultiError:
|
||||
if rhsErr != nil {
|
||||
err.Errors = append(err.Errors, rhsErr.Errors...)
|
||||
}
|
||||
default:
|
||||
err.Errors = append(err.Errors, verr)
|
||||
}
|
||||
}
|
||||
return err
|
||||
default:
|
||||
newErrs := make([]error, len(errs)+1)
|
||||
|
|
Loading…
Reference in New Issue