Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
598822d4
Commit
598822d4
authored
Dec 21, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox/common: move outputdir config to common
parent
886c0d3a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
207 additions
and
49 deletions
+207
-49
builder/virtualbox/common/config_test.go
builder/virtualbox/common/config_test.go
+15
-0
builder/virtualbox/common/output_config.go
builder/virtualbox/common/output_config.go
+40
-0
builder/virtualbox/common/output_config_test.go
builder/virtualbox/common/output_config_test.go
+65
-0
builder/virtualbox/iso/builder.go
builder/virtualbox/iso/builder.go
+4
-15
builder/virtualbox/ovf/builder.go
builder/virtualbox/ovf/builder.go
+34
-34
builder/virtualbox/ovf/config.go
builder/virtualbox/ovf/config.go
+40
-0
builder/virtualbox/ovf/config_test.go
builder/virtualbox/ovf/config_test.go
+9
-0
No files found.
builder/virtualbox/common/config_test.go
0 → 100644
View file @
598822d4
package
common
import
(
"github.com/mitchellh/packer/packer"
"testing"
)
func
testConfigTemplate
(
t
*
testing
.
T
)
*
packer
.
ConfigTemplate
{
result
,
err
:=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
return
result
}
builder/virtualbox/common/output_config.go
0 → 100644
View file @
598822d4
package
common
import
(
"fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"os"
)
type
OutputConfig
struct
{
OutputDir
string
`mapstructure:"output_directory"`
}
func
(
c
*
OutputConfig
)
Prepare
(
t
*
packer
.
ConfigTemplate
,
pc
*
common
.
PackerConfig
)
[]
error
{
if
c
.
OutputDir
==
""
{
c
.
OutputDir
=
fmt
.
Sprintf
(
"output-%s"
,
pc
.
PackerBuildName
)
}
templates
:=
map
[
string
]
*
string
{
"output_directory"
:
&
c
.
OutputDir
,
}
errs
:=
make
([]
error
,
0
)
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
t
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
if
!
pc
.
PackerForce
{
if
_
,
err
:=
os
.
Stat
(
c
.
OutputDir
);
err
==
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Output directory '%s' already exists. It must not exist."
,
c
.
OutputDir
))
}
}
return
errs
}
builder/virtualbox/common/output_config_test.go
0 → 100644
View file @
598822d4
package
common
import
(
"github.com/mitchellh/packer/common"
"io/ioutil"
"os"
"testing"
)
func
TestOutputConfigPrepare
(
t
*
testing
.
T
)
{
c
:=
new
(
OutputConfig
)
if
c
.
OutputDir
!=
""
{
t
.
Fatalf
(
"what: %s"
,
c
.
OutputDir
)
}
pc
:=
&
common
.
PackerConfig
{
PackerBuildName
:
"foo"
}
errs
:=
c
.
Prepare
(
testConfigTemplate
(
t
),
pc
)
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"err: %#v"
,
errs
)
}
if
c
.
OutputDir
==
""
{
t
.
Fatal
(
"should have output dir"
)
}
}
func
TestOutputConfigPrepare_exists
(
t
*
testing
.
T
)
{
td
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
defer
os
.
RemoveAll
(
td
)
c
:=
new
(
OutputConfig
)
c
.
OutputDir
=
td
pc
:=
&
common
.
PackerConfig
{
PackerBuildName
:
"foo"
,
PackerForce
:
false
,
}
errs
:=
c
.
Prepare
(
testConfigTemplate
(
t
),
pc
)
if
len
(
errs
)
==
0
{
t
.
Fatal
(
"should have errors"
)
}
}
func
TestOutputConfigPrepare_forceExists
(
t
*
testing
.
T
)
{
td
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
defer
os
.
RemoveAll
(
td
)
c
:=
new
(
OutputConfig
)
c
.
OutputDir
=
td
pc
:=
&
common
.
PackerConfig
{
PackerBuildName
:
"foo"
,
PackerForce
:
true
,
}
errs
:=
c
.
Prepare
(
testConfigTemplate
(
t
),
pc
)
if
len
(
errs
)
>
0
{
t
.
Fatal
(
"should not have errors"
)
}
}
builder/virtualbox/iso/builder.go
View file @
598822d4
...
...
@@ -29,7 +29,8 @@ type Builder struct {
}
type
config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
common
.
PackerConfig
`mapstructure:",squash"`
vboxcommon
.
OutputConfig
`mapstructure:",squash"`
BootCommand
[]
string
`mapstructure:"boot_command"`
DiskSize
uint
`mapstructure:"disk_size"`
...
...
@@ -48,7 +49,6 @@ type config struct {
ISOChecksum
string
`mapstructure:"iso_checksum"`
ISOChecksumType
string
`mapstructure:"iso_checksum_type"`
ISOUrls
[]
string
`mapstructure:"iso_urls"`
OutputDir
string
`mapstructure:"output_directory"`
ShutdownCommand
string
`mapstructure:"shutdown_command"`
SSHHostPortMin
uint
`mapstructure:"ssh_host_port_min"`
SSHHostPortMax
uint
`mapstructure:"ssh_host_port_max"`
...
...
@@ -85,6 +85,8 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
// Accumulate any errors and warnings
errs
:=
common
.
CheckUnusedConfig
(
md
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
OutputConfig
.
Prepare
(
b
.
config
.
tpl
,
&
b
.
config
.
PackerConfig
)
...
)
warnings
:=
make
([]
string
,
0
)
if
b
.
config
.
DiskSize
==
0
{
...
...
@@ -119,10 +121,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b
.
config
.
HTTPPortMax
=
9000
}
if
b
.
config
.
OutputDir
==
""
{
b
.
config
.
OutputDir
=
fmt
.
Sprintf
(
"output-%s"
,
b
.
config
.
PackerBuildName
)
}
if
b
.
config
.
RawBootWait
==
""
{
b
.
config
.
RawBootWait
=
"10s"
}
...
...
@@ -165,7 +163,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
"iso_checksum"
:
&
b
.
config
.
ISOChecksum
,
"iso_checksum_type"
:
&
b
.
config
.
ISOChecksumType
,
"iso_url"
:
&
b
.
config
.
RawSingleISOUrl
,
"output_directory"
:
&
b
.
config
.
OutputDir
,
"shutdown_command"
:
&
b
.
config
.
ShutdownCommand
,
"ssh_key_path"
:
&
b
.
config
.
SSHKeyPath
,
"ssh_password"
:
&
b
.
config
.
SSHPassword
,
...
...
@@ -300,14 +297,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b
.
config
.
GuestAdditionsSHA256
=
strings
.
ToLower
(
b
.
config
.
GuestAdditionsSHA256
)
}
if
!
b
.
config
.
PackerForce
{
if
_
,
err
:=
os
.
Stat
(
b
.
config
.
OutputDir
);
err
==
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Output directory '%s' already exists. It must not exist."
,
b
.
config
.
OutputDir
))
}
}
b
.
config
.
bootWait
,
err
=
time
.
ParseDuration
(
b
.
config
.
RawBootWait
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
...
...
builder/virtualbox/ovf/builder.go
View file @
598822d4
package
ovf
import
(
"github.com/mitchellh/packer/builder/virtualbox/common"
"errors"
"log"
"github.com/mitchellh/multistep"
vboxcommon
"github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
)
// Builder implements packer.Builder and builds the actual VirtualBox
...
...
@@ -33,38 +39,36 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Build the steps.
steps
:=
[]
multistep
.
Step
{
/*
new(stepDownloadGuestAdditions),
*/
/*
/*
new(stepDownloadGuestAdditions),
*/
&
vboxcommon
.
StepOutputDir
{
Force
:
b
.
config
.
PackerForce
,
Path
:
b
.
config
.
OutputDir
,
},
*/
/*
&common.StepCreateFloppy{
Files: b.config.FloppyFiles,
},
new(stepSuppressMessages),
new(stepAttachGuestAdditions),
new(stepAttachFloppy),
new(stepForwardSSH),
new(stepVBoxManage),
new(stepRun),
new(stepTypeBootCommand),
&common.StepConnectSSH{
SSHAddress: sshAddress,
SSHConfig: sshConfig,
SSHWaitTimeout: b.config.sshWaitTimeout,
},
new(stepUploadVersion),
new(stepUploadGuestAdditions),
new(common.StepProvision),
new(stepShutdown),
new(stepRemoveDevices),
new(stepExport),
*/
new
(
vboxcommon
.
StepSuppressMessages
),
/*
&common.StepCreateFloppy{
Files: b.config.FloppyFiles,
},
new(stepAttachGuestAdditions),
new(stepAttachFloppy),
new(stepForwardSSH),
new(stepVBoxManage),
new(stepRun),
new(stepTypeBootCommand),
&common.StepConnectSSH{
SSHAddress: sshAddress,
SSHConfig: sshConfig,
SSHWaitTimeout: b.config.sshWaitTimeout,
},
new(stepUploadVersion),
new(stepUploadGuestAdditions),
new(common.StepProvision),
new(stepShutdown),
new(stepRemoveDevices),
new(stepExport),
*/
}
// Run the steps.
...
...
@@ -92,11 +96,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
return
nil
,
errors
.
New
(
"Build was halted."
)
}
artifact
:=
&
Artifact
{
imageName
:
state
.
Get
(
"image_name"
)
.
(
string
),
driver
:
driver
,
}
return
artifact
,
nil
return
vboxcommon
.
NewArtifact
(
b
.
config
.
OutputDir
)
}
// Cancel.
...
...
builder/virtualbox/ovf/config.go
0 → 100644
View file @
598822d4
package
ovf
import
(
vboxcommon
"github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
)
// Config is the configuration structure for the builder.
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
vboxcommon
.
OutputConfig
`mapstructure:",squash"`
tpl
*
packer
.
ConfigTemplate
}
func
NewConfig
(
raws
...
interface
{})
(
*
Config
,
[]
string
,
error
)
{
c
:=
new
(
Config
)
md
,
err
:=
common
.
DecodeConfig
(
c
,
raws
...
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
c
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
nil
,
nil
,
err
}
c
.
tpl
.
UserVars
=
c
.
PackerUserVars
// Prepare the errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
OutputConfig
.
Prepare
(
c
.
tpl
,
&
c
.
PackerConfig
)
...
)
// Check for any errors.
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
return
nil
,
nil
,
errs
}
return
c
,
nil
,
nil
}
builder/virtualbox/ovf/config_test.go
0 → 100644
View file @
598822d4
package
ovf
import
(
"testing"
)
func
testConfig
(
t
*
testing
.
T
)
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment