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
14eede26
Commit
14eede26
authored
Dec 21, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox: add common package, common Artifact
parent
09c3d67c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
53 deletions
+106
-53
builder/virtualbox/common/artifact.go
builder/virtualbox/common/artifact.go
+61
-0
builder/virtualbox/common/artifact_test.go
builder/virtualbox/common/artifact_test.go
+43
-0
builder/virtualbox/iso/artifact.go
builder/virtualbox/iso/artifact.go
+0
-33
builder/virtualbox/iso/builder.go
builder/virtualbox/iso/builder.go
+2
-20
No files found.
builder/virtualbox/common/artifact.go
0 → 100644
View file @
14eede26
package
common
import
(
"fmt"
"os"
"path/filepath"
"github.com/mitchellh/packer/packer"
)
// This is the common builder ID to all of these artifacts.
const
BuilderId
=
"mitchellh.virtualbox"
// Artifact is the result of running the VirtualBox builder, namely a set
// of files associated with the resulting machine.
type
artifact
struct
{
dir
string
f
[]
string
}
// NewArtifact returns a VirtualBox artifact containing the files
// in the given directory.
func
NewArtifact
(
dir
string
)
(
packer
.
Artifact
,
error
)
{
files
:=
make
([]
string
,
0
,
5
)
visit
:=
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
if
!
info
.
IsDir
()
{
files
=
append
(
files
,
path
)
}
return
err
}
if
err
:=
filepath
.
Walk
(
dir
,
visit
);
err
!=
nil
{
return
nil
,
err
}
return
&
artifact
{
dir
:
dir
,
f
:
files
,
},
nil
}
func
(
*
artifact
)
BuilderId
()
string
{
return
BuilderId
}
func
(
a
*
artifact
)
Files
()
[]
string
{
return
a
.
f
}
func
(
*
artifact
)
Id
()
string
{
return
"VM"
}
func
(
a
*
artifact
)
String
()
string
{
return
fmt
.
Sprintf
(
"VM files in directory: %s"
,
a
.
dir
)
}
func
(
a
*
artifact
)
Destroy
()
error
{
return
os
.
RemoveAll
(
a
.
dir
)
}
builder/virtualbox/common/artifact_test.go
0 → 100644
View file @
14eede26
package
common
import
(
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/mitchellh/packer/packer"
)
func
TestArtifact_impl
(
t
*
testing
.
T
)
{
var
_
packer
.
Artifact
=
new
(
artifact
)
}
func
TestNewArtifact
(
t
*
testing
.
T
)
{
td
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
defer
os
.
RemoveAll
(
td
)
err
=
ioutil
.
WriteFile
(
filepath
.
Join
(
td
,
"a"
),
[]
byte
(
"foo"
),
0644
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
err
:=
os
.
Mkdir
(
filepath
.
Join
(
td
,
"b"
),
0755
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
a
,
err
:=
NewArtifact
(
td
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
a
.
BuilderId
()
!=
BuilderId
{
t
.
Fatalf
(
"bad: %#v"
,
a
.
BuilderId
())
}
if
len
(
a
.
Files
())
!=
1
{
t
.
Fatalf
(
"should length 1: %d"
,
len
(
a
.
Files
()))
}
}
builder/virtualbox/iso/artifact.go
deleted
100644 → 0
View file @
09c3d67c
package
iso
import
(
"fmt"
"os"
)
// Artifact is the result of running the VirtualBox builder, namely a set
// of files associated with the resulting machine.
type
Artifact
struct
{
dir
string
f
[]
string
}
func
(
*
Artifact
)
BuilderId
()
string
{
return
BuilderId
}
func
(
a
*
Artifact
)
Files
()
[]
string
{
return
a
.
f
}
func
(
*
Artifact
)
Id
()
string
{
return
"VM"
}
func
(
a
*
Artifact
)
String
()
string
{
return
fmt
.
Sprintf
(
"VM files in directory: %s"
,
a
.
dir
)
}
func
(
a
*
Artifact
)
Destroy
()
error
{
return
os
.
RemoveAll
(
a
.
dir
)
}
builder/virtualbox/iso/builder.go
View file @
14eede26
...
...
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/mitchellh/multistep"
vboxcommon
"github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"log"
...
...
@@ -457,26 +458,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
return
nil
,
errors
.
New
(
"Build was halted."
)
}
// Compile the artifact list
files
:=
make
([]
string
,
0
,
5
)
visit
:=
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
if
!
info
.
IsDir
()
{
files
=
append
(
files
,
path
)
}
return
err
}
if
err
:=
filepath
.
Walk
(
b
.
config
.
OutputDir
,
visit
);
err
!=
nil
{
return
nil
,
err
}
artifact
:=
&
Artifact
{
dir
:
b
.
config
.
OutputDir
,
f
:
files
,
}
return
artifact
,
nil
return
vboxcommon
.
NewArtifact
(
b
.
config
.
OutputDir
)
}
func
(
b
*
Builder
)
Cancel
()
{
...
...
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