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
e0ab81ae
Commit
e0ab81ae
authored
Jun 27, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-processor/vagrant: VirtualBox post-processor
parent
c190a5ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
0 deletions
+112
-0
post-processor/vagrant/virtualbox.go
post-processor/vagrant/virtualbox.go
+98
-0
post-processor/vagrant/virtualbox_test.go
post-processor/vagrant/virtualbox_test.go
+14
-0
No files found.
post-processor/vagrant/virtualbox.go
0 → 100644
View file @
e0ab81ae
package
vagrant
import
(
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/packer"
"io"
"io/ioutil"
"os"
"path/filepath"
"text/template"
)
type
VBoxBoxConfig
struct
{
OutputPath
string
`mapstructure:"output"`
}
type
VBoxVagrantfileTemplate
struct
{
BaseMacAddress
string
}
type
VBoxBoxPostProcessor
struct
{
config
VBoxBoxConfig
}
func
(
p
*
VBoxBoxPostProcessor
)
Configure
(
raw
interface
{})
error
{
err
:=
mapstructure
.
Decode
(
raw
,
&
p
.
config
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
(
p
*
VBoxBoxPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
// TODO(mitchellh): Actually parse the base mac address
tplData
:=
&
VBoxVagrantfileTemplate
{}
// Create a temporary directory for us to build the contents of the box in
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
return
nil
,
err
}
defer
os
.
RemoveAll
(
dir
)
// Copy all of the original contents into the temporary directory
for
_
,
path
:=
range
artifact
.
Files
()
{
ui
.
Message
(
fmt
.
Sprintf
(
"Copying: %s"
,
path
))
src
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
defer
src
.
Close
()
dst
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
filepath
.
Base
(
path
)))
if
err
!=
nil
{
return
nil
,
err
}
defer
dst
.
Close
()
if
_
,
err
:=
io
.
Copy
(
dst
,
src
);
err
!=
nil
{
return
nil
,
err
}
}
// Create the Vagrantfile from the template
vf
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
"Vagrantfile"
))
if
err
!=
nil
{
return
nil
,
err
}
defer
vf
.
Close
()
t
:=
template
.
Must
(
template
.
New
(
"vagrantfile"
)
.
Parse
(
defaultVBoxVagrantfile
))
t
.
Execute
(
vf
,
tplData
)
vf
.
Close
()
// Create the metadata
metadata
:=
map
[
string
]
string
{
"provider"
:
"virtualbox"
}
if
err
:=
WriteMetadata
(
dir
,
metadata
);
err
!=
nil
{
return
nil
,
err
}
// Compress the directory to the given output path
ui
.
Message
(
fmt
.
Sprintf
(
"Compressing box..."
))
if
err
:=
DirToBox
(
p
.
config
.
OutputPath
,
dir
);
err
!=
nil
{
return
nil
,
err
}
return
NewArtifact
(
"virtualbox"
,
p
.
config
.
OutputPath
),
nil
}
var
defaultVBoxVagrantfile
=
`
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |vb|
# TODO
end
end
`
post-processor/vagrant/virtualbox_test.go
0 → 100644
View file @
e0ab81ae
package
vagrant
import
(
"github.com/mitchellh/packer/packer"
"testing"
)
func
TestVBoxBoxPostProcessor_ImplementsPostProcessor
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
&
VBoxBoxPostProcessor
{}
if
_
,
ok
:=
raw
.
(
packer
.
PostProcessor
);
!
ok
{
t
.
Fatalf
(
"VBox PostProcessor should be a PostProcessor"
)
}
}
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