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
f78cbb45
Commit
f78cbb45
authored
Jul 01, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: PostProcessor API change so they can keep artifacts [GH-55]
parent
8eb30482
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
93 additions
and
60 deletions
+93
-60
CHANGELOG.md
CHANGELOG.md
+1
-0
packer/build.go
packer/build.go
+4
-3
packer/build_test.go
packer/build_test.go
+27
-0
packer/plugin/post_processor.go
packer/plugin/post_processor.go
+1
-1
packer/plugin/post_processor_test.go
packer/plugin/post_processor_test.go
+2
-2
packer/post_processor.go
packer/post_processor.go
+3
-2
packer/post_processor_test.go
packer/post_processor_test.go
+3
-2
packer/rpc/post_processor.go
packer/rpc/post_processor.go
+9
-7
packer/rpc/post_processor_test.go
packer/rpc/post_processor_test.go
+3
-3
post-processor/vagrant/aws.go
post-processor/vagrant/aws.go
+10
-10
post-processor/vagrant/post-processor.go
post-processor/vagrant/post-processor.go
+4
-4
post-processor/vagrant/virtualbox.go
post-processor/vagrant/virtualbox.go
+14
-14
post-processor/vagrant/vmware.go
post-processor/vagrant/vmware.go
+12
-12
No files found.
CHANGELOG.md
View file @
f78cbb45
...
@@ -13,6 +13,7 @@ IMPROVEMENTS:
...
@@ -13,6 +13,7 @@ IMPROVEMENTS:
BUG FIXES:
BUG FIXES:
*
core: More plugin server fixes that avoid hangs on OS X 10.7 [GH-87]
*
core: More plugin server fixes that avoid hangs on OS X 10.7 [GH-87]
*
vagrant: AWS boxes will keep the AMI artifact around [GH-55]
*
virtualbox: More robust version parsing for uploading guest additions. [GH-69]
*
virtualbox: More robust version parsing for uploading guest additions. [GH-69]
*
virtualbox: Output dir and VM name defaults depend on build name,
*
virtualbox: Output dir and VM name defaults depend on build name,
avoiding collisions. [GH-91]
avoiding collisions. [GH-91]
...
...
packer/build.go
View file @
f78cbb45
...
@@ -194,7 +194,7 @@ PostProcessorRunSeqLoop:
...
@@ -194,7 +194,7 @@ PostProcessorRunSeqLoop:
}
}
builderUi
.
Say
(
fmt
.
Sprintf
(
"Running post-processor: %s"
,
corePP
.
processorType
))
builderUi
.
Say
(
fmt
.
Sprintf
(
"Running post-processor: %s"
,
corePP
.
processorType
))
artifact
,
err
:=
corePP
.
processor
.
PostProcess
(
ppUi
,
priorArtifact
)
artifact
,
keep
,
err
:=
corePP
.
processor
.
PostProcess
(
ppUi
,
priorArtifact
)
if
err
!=
nil
{
if
err
!=
nil
{
errors
=
append
(
errors
,
fmt
.
Errorf
(
"Post-processor failed: %s"
,
err
))
errors
=
append
(
errors
,
fmt
.
Errorf
(
"Post-processor failed: %s"
,
err
))
continue
PostProcessorRunSeqLoop
continue
PostProcessorRunSeqLoop
...
@@ -205,11 +205,12 @@ PostProcessorRunSeqLoop:
...
@@ -205,11 +205,12 @@ PostProcessorRunSeqLoop:
continue
PostProcessorRunSeqLoop
continue
PostProcessorRunSeqLoop
}
}
keep
=
keep
||
corePP
.
keepInputArtifact
if
i
==
0
{
if
i
==
0
{
// This is the first post-processor. We handle deleting
// This is the first post-processor. We handle deleting
// previous artifacts a bit different because multiple
// previous artifacts a bit different because multiple
// post-processors may be using the original and need it.
// post-processors may be using the original and need it.
if
!
keepOriginalArtifact
&&
corePP
.
keepInputArtifact
{
if
!
keepOriginalArtifact
&&
keep
{
log
.
Printf
(
log
.
Printf
(
"Flagging to keep original artifact from post-processor '%s'"
,
"Flagging to keep original artifact from post-processor '%s'"
,
corePP
.
processorType
)
corePP
.
processorType
)
...
@@ -218,7 +219,7 @@ PostProcessorRunSeqLoop:
...
@@ -218,7 +219,7 @@ PostProcessorRunSeqLoop:
}
else
{
}
else
{
// We have a prior artifact. If we want to keep it, we append
// We have a prior artifact. If we want to keep it, we append
// it to the results list. Otherwise, we destroy it.
// it to the results list. Otherwise, we destroy it.
if
corePP
.
keepInputArtifact
{
if
keep
{
artifacts
=
append
(
artifacts
,
priorArtifact
)
artifacts
=
append
(
artifacts
,
priorArtifact
)
}
else
{
}
else
{
log
.
Printf
(
"Deleting prior artifact from post-processor '%s'"
,
corePP
.
processorType
)
log
.
Printf
(
"Deleting prior artifact from post-processor '%s'"
,
corePP
.
processorType
)
...
...
packer/build_test.go
View file @
f78cbb45
...
@@ -245,6 +245,33 @@ func TestBuild_Run_Artifacts(t *testing.T) {
...
@@ -245,6 +245,33 @@ func TestBuild_Run_Artifacts(t *testing.T) {
if
!
reflect
.
DeepEqual
(
artifactIds
,
expectedIds
)
{
if
!
reflect
.
DeepEqual
(
artifactIds
,
expectedIds
)
{
t
.
Fatalf
(
"unexpected ids: %#v"
,
artifactIds
)
t
.
Fatalf
(
"unexpected ids: %#v"
,
artifactIds
)
}
}
// Test case: Test that with a single post-processor that forcibly
// keeps inputs, that the artifacts are kept.
build
=
testBuild
()
build
.
postProcessors
=
[][]
coreBuildPostProcessor
{
[]
coreBuildPostProcessor
{
coreBuildPostProcessor
{
&
TestPostProcessor
{
artifactId
:
"pp"
,
keep
:
true
},
"pp"
,
42
,
false
,
},
},
}
build
.
Prepare
()
artifacts
,
err
=
build
.
Run
(
ui
,
cache
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
expectedIds
=
[]
string
{
"b"
,
"pp"
}
artifactIds
=
make
([]
string
,
len
(
artifacts
))
for
i
,
artifact
:=
range
artifacts
{
artifactIds
[
i
]
=
artifact
.
Id
()
}
if
!
reflect
.
DeepEqual
(
artifactIds
,
expectedIds
)
{
t
.
Fatalf
(
"unexpected ids: %#v"
,
artifactIds
)
}
}
}
func
TestBuild_RunBeforePrepare
(
t
*
testing
.
T
)
{
func
TestBuild_RunBeforePrepare
(
t
*
testing
.
T
)
{
...
...
packer/plugin/post_processor.go
View file @
f78cbb45
...
@@ -19,7 +19,7 @@ func (c *cmdPostProcessor) Configure(config interface{}) error {
...
@@ -19,7 +19,7 @@ func (c *cmdPostProcessor) Configure(config interface{}) error {
return
c
.
p
.
Configure
(
config
)
return
c
.
p
.
Configure
(
config
)
}
}
func
(
c
*
cmdPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
a
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
func
(
c
*
cmdPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
a
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
defer
func
()
{
defer
func
()
{
r
:=
recover
()
r
:=
recover
()
c
.
checkExit
(
r
,
nil
)
c
.
checkExit
(
r
,
nil
)
...
...
packer/plugin/post_processor_test.go
View file @
f78cbb45
...
@@ -12,8 +12,8 @@ func (helperPostProcessor) Configure(interface{}) error {
...
@@ -12,8 +12,8 @@ func (helperPostProcessor) Configure(interface{}) error {
return
nil
return
nil
}
}
func
(
helperPostProcessor
)
PostProcess
(
packer
.
Ui
,
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
func
(
helperPostProcessor
)
PostProcess
(
packer
.
Ui
,
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
return
nil
,
nil
return
nil
,
false
,
nil
}
}
func
TestPostProcessor_NoExist
(
t
*
testing
.
T
)
{
func
TestPostProcessor_NoExist
(
t
*
testing
.
T
)
{
...
...
packer/post_processor.go
View file @
f78cbb45
...
@@ -12,6 +12,7 @@ type PostProcessor interface {
...
@@ -12,6 +12,7 @@ type PostProcessor interface {
Configure
(
interface
{})
error
Configure
(
interface
{})
error
// PostProcess takes a previously created Artifact and produces another
// PostProcess takes a previously created Artifact and produces another
// Artifact. If an error occurs, it should return that error.
// Artifact. If an error occurs, it should return that error. If `keep`
PostProcess
(
Ui
,
Artifact
)
(
Artifact
,
error
)
// is to true, then the previous artifact is forcibly kept.
PostProcess
(
Ui
,
Artifact
)
(
a
Artifact
,
keep
bool
,
err
error
)
}
}
packer/post_processor_test.go
View file @
f78cbb45
...
@@ -2,6 +2,7 @@ package packer
...
@@ -2,6 +2,7 @@ package packer
type
TestPostProcessor
struct
{
type
TestPostProcessor
struct
{
artifactId
string
artifactId
string
keep
bool
configCalled
bool
configCalled
bool
configVal
interface
{}
configVal
interface
{}
ppCalled
bool
ppCalled
bool
...
@@ -15,9 +16,9 @@ func (pp *TestPostProcessor) Configure(v interface{}) error {
...
@@ -15,9 +16,9 @@ func (pp *TestPostProcessor) Configure(v interface{}) error {
return
nil
return
nil
}
}
func
(
pp
*
TestPostProcessor
)
PostProcess
(
ui
Ui
,
a
Artifact
)
(
Artifact
,
error
)
{
func
(
pp
*
TestPostProcessor
)
PostProcess
(
ui
Ui
,
a
Artifact
)
(
Artifact
,
bool
,
error
)
{
pp
.
ppCalled
=
true
pp
.
ppCalled
=
true
pp
.
ppArtifact
=
a
pp
.
ppArtifact
=
a
pp
.
ppUi
=
ui
pp
.
ppUi
=
ui
return
&
TestArtifact
{
id
:
pp
.
artifactId
},
nil
return
&
TestArtifact
{
id
:
pp
.
artifactId
},
pp
.
keep
,
nil
}
}
packer/rpc/post_processor.go
View file @
f78cbb45
...
@@ -19,6 +19,7 @@ type PostProcessorServer struct {
...
@@ -19,6 +19,7 @@ type PostProcessorServer struct {
type
PostProcessorProcessResponse
struct
{
type
PostProcessorProcessResponse
struct
{
Err
error
Err
error
Keep
bool
RPCAddress
string
RPCAddress
string
}
}
...
@@ -33,30 +34,30 @@ func (p *postProcessor) Configure(raw interface{}) (err error) {
...
@@ -33,30 +34,30 @@ func (p *postProcessor) Configure(raw interface{}) (err error) {
return
return
}
}
func
(
p
*
postProcessor
)
PostProcess
(
ui
packer
.
Ui
,
a
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
func
(
p
*
postProcessor
)
PostProcess
(
ui
packer
.
Ui
,
a
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
server
:=
rpc
.
NewServer
()
server
:=
rpc
.
NewServer
()
RegisterArtifact
(
server
,
a
)
RegisterArtifact
(
server
,
a
)
RegisterUi
(
server
,
ui
)
RegisterUi
(
server
,
ui
)
var
response
PostProcessorProcessResponse
var
response
PostProcessorProcessResponse
if
err
:=
p
.
client
.
Call
(
"PostProcessor.PostProcess"
,
serveSingleConn
(
server
),
&
response
);
err
!=
nil
{
if
err
:=
p
.
client
.
Call
(
"PostProcessor.PostProcess"
,
serveSingleConn
(
server
),
&
response
);
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
if
response
.
Err
!=
nil
{
if
response
.
Err
!=
nil
{
return
nil
,
response
.
Err
return
nil
,
false
,
response
.
Err
}
}
if
response
.
RPCAddress
==
""
{
if
response
.
RPCAddress
==
""
{
return
nil
,
nil
return
nil
,
false
,
nil
}
}
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
response
.
RPCAddress
)
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
response
.
RPCAddress
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
return
Artifact
(
client
),
nil
return
Artifact
(
client
),
response
.
Keep
,
nil
}
}
func
(
p
*
PostProcessorServer
)
Configure
(
raw
*
interface
{},
reply
*
error
)
error
{
func
(
p
*
PostProcessorServer
)
Configure
(
raw
*
interface
{},
reply
*
error
)
error
{
...
@@ -76,7 +77,7 @@ func (p *PostProcessorServer) PostProcess(address string, reply *PostProcessorPr
...
@@ -76,7 +77,7 @@ func (p *PostProcessorServer) PostProcess(address string, reply *PostProcessorPr
responseAddress
:=
""
responseAddress
:=
""
artifact
,
err
:=
p
.
p
.
PostProcess
(
&
Ui
{
client
},
Artifact
(
client
))
artifact
,
keep
,
err
:=
p
.
p
.
PostProcess
(
&
Ui
{
client
},
Artifact
(
client
))
if
err
==
nil
&&
artifact
!=
nil
{
if
err
==
nil
&&
artifact
!=
nil
{
server
:=
rpc
.
NewServer
()
server
:=
rpc
.
NewServer
()
RegisterArtifact
(
server
,
artifact
)
RegisterArtifact
(
server
,
artifact
)
...
@@ -89,6 +90,7 @@ func (p *PostProcessorServer) PostProcess(address string, reply *PostProcessorPr
...
@@ -89,6 +90,7 @@ func (p *PostProcessorServer) PostProcess(address string, reply *PostProcessorPr
*
reply
=
PostProcessorProcessResponse
{
*
reply
=
PostProcessorProcessResponse
{
Err
:
err
,
Err
:
err
,
Keep
:
keep
,
RPCAddress
:
responseAddress
,
RPCAddress
:
responseAddress
,
}
}
...
...
packer/rpc/post_processor_test.go
View file @
f78cbb45
...
@@ -22,11 +22,11 @@ func (pp *TestPostProcessor) Configure(v interface{}) error {
...
@@ -22,11 +22,11 @@ func (pp *TestPostProcessor) Configure(v interface{}) error {
return
nil
return
nil
}
}
func
(
pp
*
TestPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
a
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
func
(
pp
*
TestPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
a
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
pp
.
ppCalled
=
true
pp
.
ppCalled
=
true
pp
.
ppArtifact
=
a
pp
.
ppArtifact
=
a
pp
.
ppUi
=
ui
pp
.
ppUi
=
ui
return
testPostProcessorArtifact
,
nil
return
testPostProcessorArtifact
,
false
,
nil
}
}
func
TestPostProcessorRPC
(
t
*
testing
.
T
)
{
func
TestPostProcessorRPC
(
t
*
testing
.
T
)
{
...
@@ -63,7 +63,7 @@ func TestPostProcessorRPC(t *testing.T) {
...
@@ -63,7 +63,7 @@ func TestPostProcessorRPC(t *testing.T) {
// Test PostProcess
// Test PostProcess
a
:=
new
(
testArtifact
)
a
:=
new
(
testArtifact
)
ui
:=
new
(
testUi
)
ui
:=
new
(
testUi
)
artifact
,
err
:=
pClient
.
PostProcess
(
ui
,
a
)
artifact
,
_
,
err
:=
pClient
.
PostProcess
(
ui
,
a
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
t
.
Fatalf
(
"err: %s"
,
err
)
}
}
...
...
post-processor/vagrant/aws.go
View file @
f78cbb45
...
@@ -33,7 +33,7 @@ func (p *AWSBoxPostProcessor) Configure(raw interface{}) error {
...
@@ -33,7 +33,7 @@ func (p *AWSBoxPostProcessor) Configure(raw interface{}) error {
return
nil
return
nil
}
}
func
(
p
*
AWSBoxPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
func
(
p
*
AWSBoxPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
// Determine the regions...
// Determine the regions...
tplData
:=
&
AWSVagrantfileTemplate
{
tplData
:=
&
AWSVagrantfileTemplate
{
Images
:
make
(
map
[
string
]
string
),
Images
:
make
(
map
[
string
]
string
),
...
@@ -42,7 +42,7 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
...
@@ -42,7 +42,7 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
for
_
,
regions
:=
range
strings
.
Split
(
artifact
.
Id
(),
","
)
{
for
_
,
regions
:=
range
strings
.
Split
(
artifact
.
Id
(),
","
)
{
parts
:=
strings
.
Split
(
regions
,
":"
)
parts
:=
strings
.
Split
(
regions
,
":"
)
if
len
(
parts
)
!=
2
{
if
len
(
parts
)
!=
2
{
return
nil
,
fmt
.
Errorf
(
"Poorly formatted artifact ID: %s"
,
artifact
.
Id
())
return
nil
,
f
alse
,
f
mt
.
Errorf
(
"Poorly formatted artifact ID: %s"
,
artifact
.
Id
())
}
}
tplData
.
Images
[
parts
[
0
]]
=
parts
[
1
]
tplData
.
Images
[
parts
[
0
]]
=
parts
[
1
]
...
@@ -51,20 +51,20 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
...
@@ -51,20 +51,20 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
// Compile the output path
// Compile the output path
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
"aws"
,
artifact
)
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
"aws"
,
artifact
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
// Create a temporary directory for us to build the contents of the box in
// Create a temporary directory for us to build the contents of the box in
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
defer
os
.
RemoveAll
(
dir
)
defer
os
.
RemoveAll
(
dir
)
// Create the Vagrantfile from the template
// Create the Vagrantfile from the template
vf
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
"Vagrantfile"
))
vf
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
"Vagrantfile"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
defer
vf
.
Close
()
defer
vf
.
Close
()
...
@@ -72,13 +72,13 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
...
@@ -72,13 +72,13 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
if
p
.
config
.
VagrantfileTemplate
!=
""
{
if
p
.
config
.
VagrantfileTemplate
!=
""
{
f
,
err
:=
os
.
Open
(
p
.
config
.
VagrantfileTemplate
)
f
,
err
:=
os
.
Open
(
p
.
config
.
VagrantfileTemplate
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
defer
f
.
Close
()
defer
f
.
Close
()
contents
,
err
:=
ioutil
.
ReadAll
(
f
)
contents
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
vagrantfileContents
=
string
(
contents
)
vagrantfileContents
=
string
(
contents
)
...
@@ -91,15 +91,15 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
...
@@ -91,15 +91,15 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
// Create the metadata
// Create the metadata
metadata
:=
map
[
string
]
string
{
"provider"
:
"aws"
}
metadata
:=
map
[
string
]
string
{
"provider"
:
"aws"
}
if
err
:=
WriteMetadata
(
dir
,
metadata
);
err
!=
nil
{
if
err
:=
WriteMetadata
(
dir
,
metadata
);
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
// Compress the directory to the given output path
// Compress the directory to the given output path
if
err
:=
DirToBox
(
outputPath
,
dir
);
err
!=
nil
{
if
err
:=
DirToBox
(
outputPath
,
dir
);
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
return
NewArtifact
(
"aws"
,
outputPath
),
nil
return
NewArtifact
(
"aws"
,
outputPath
),
true
,
nil
}
}
var
defaultAWSVagrantfile
=
`
var
defaultAWSVagrantfile
=
`
...
...
post-processor/vagrant/post-processor.go
View file @
f78cbb45
...
@@ -68,10 +68,10 @@ func (p *PostProcessor) Configure(raw interface{}) error {
...
@@ -68,10 +68,10 @@ func (p *PostProcessor) Configure(raw interface{}) error {
return
nil
return
nil
}
}
func
(
p
*
PostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
func
(
p
*
PostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
ppName
,
ok
:=
builtins
[
artifact
.
BuilderId
()]
ppName
,
ok
:=
builtins
[
artifact
.
BuilderId
()]
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"Unknown artifact type, can't build box: %s"
,
artifact
.
BuilderId
())
return
nil
,
f
alse
,
f
mt
.
Errorf
(
"Unknown artifact type, can't build box: %s"
,
artifact
.
BuilderId
())
}
}
// Use the premade PostProcessor if we have one. Otherwise, we
// Use the premade PostProcessor if we have one. Otherwise, we
...
@@ -81,12 +81,12 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
...
@@ -81,12 +81,12 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
log
.
Printf
(
"Premade post-processor for '%s' not found. Creating."
,
ppName
)
log
.
Printf
(
"Premade post-processor for '%s' not found. Creating."
,
ppName
)
pp
=
keyToPostProcessor
(
ppName
)
pp
=
keyToPostProcessor
(
ppName
)
if
pp
==
nil
{
if
pp
==
nil
{
return
nil
,
fmt
.
Errorf
(
"Vagrant box post-processor not found: %s"
,
ppName
)
return
nil
,
f
alse
,
f
mt
.
Errorf
(
"Vagrant box post-processor not found: %s"
,
ppName
)
}
}
config
:=
map
[
string
]
string
{
"output"
:
p
.
config
.
OutputPath
}
config
:=
map
[
string
]
string
{
"output"
:
p
.
config
.
OutputPath
}
if
err
:=
pp
.
Configure
(
config
);
err
!=
nil
{
if
err
:=
pp
.
Configure
(
config
);
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
}
}
...
...
post-processor/vagrant/virtualbox.go
View file @
f78cbb45
...
@@ -37,24 +37,24 @@ func (p *VBoxBoxPostProcessor) Configure(raw interface{}) error {
...
@@ -37,24 +37,24 @@ func (p *VBoxBoxPostProcessor) Configure(raw interface{}) error {
return
nil
return
nil
}
}
func
(
p
*
VBoxBoxPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
func
(
p
*
VBoxBoxPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
var
err
error
var
err
error
tplData
:=
&
VBoxVagrantfileTemplate
{}
tplData
:=
&
VBoxVagrantfileTemplate
{}
tplData
.
BaseMacAddress
,
err
=
p
.
findBaseMacAddress
(
artifact
)
tplData
.
BaseMacAddress
,
err
=
p
.
findBaseMacAddress
(
artifact
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
// Compile the output path
// Compile the output path
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
"virtualbox"
,
artifact
)
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
"virtualbox"
,
artifact
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
// Create a temporary directory for us to build the contents of the box in
// Create a temporary directory for us to build the contents of the box in
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
defer
os
.
RemoveAll
(
dir
)
defer
os
.
RemoveAll
(
dir
)
...
@@ -63,25 +63,25 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
...
@@ -63,25 +63,25 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
ui
.
Message
(
fmt
.
Sprintf
(
"Copying: %s"
,
path
))
ui
.
Message
(
fmt
.
Sprintf
(
"Copying: %s"
,
path
))
src
,
err
:=
os
.
Open
(
path
)
src
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
defer
src
.
Close
()
defer
src
.
Close
()
dst
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
filepath
.
Base
(
path
)))
dst
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
filepath
.
Base
(
path
)))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
defer
dst
.
Close
()
defer
dst
.
Close
()
if
_
,
err
:=
io
.
Copy
(
dst
,
src
);
err
!=
nil
{
if
_
,
err
:=
io
.
Copy
(
dst
,
src
);
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
}
}
// Create the Vagrantfile from the template
// Create the Vagrantfile from the template
vf
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
"Vagrantfile"
))
vf
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
"Vagrantfile"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
defer
vf
.
Close
()
defer
vf
.
Close
()
...
@@ -89,13 +89,13 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
...
@@ -89,13 +89,13 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
if
p
.
config
.
VagrantfileTemplate
!=
""
{
if
p
.
config
.
VagrantfileTemplate
!=
""
{
f
,
err
:=
os
.
Open
(
p
.
config
.
VagrantfileTemplate
)
f
,
err
:=
os
.
Open
(
p
.
config
.
VagrantfileTemplate
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
defer
f
.
Close
()
defer
f
.
Close
()
contents
,
err
:=
ioutil
.
ReadAll
(
f
)
contents
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
vagrantfileContents
=
string
(
contents
)
vagrantfileContents
=
string
(
contents
)
...
@@ -108,22 +108,22 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
...
@@ -108,22 +108,22 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
// Create the metadata
// Create the metadata
metadata
:=
map
[
string
]
string
{
"provider"
:
"virtualbox"
}
metadata
:=
map
[
string
]
string
{
"provider"
:
"virtualbox"
}
if
err
:=
WriteMetadata
(
dir
,
metadata
);
err
!=
nil
{
if
err
:=
WriteMetadata
(
dir
,
metadata
);
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
// Rename the OVF file to box.ovf, as required by Vagrant
// Rename the OVF file to box.ovf, as required by Vagrant
ui
.
Message
(
"Renaming the OVF to box.ovf..."
)
ui
.
Message
(
"Renaming the OVF to box.ovf..."
)
if
err
:=
p
.
renameOVF
(
dir
);
err
!=
nil
{
if
err
:=
p
.
renameOVF
(
dir
);
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
// Compress the directory to the given output path
// Compress the directory to the given output path
ui
.
Message
(
fmt
.
Sprintf
(
"Compressing box..."
))
ui
.
Message
(
fmt
.
Sprintf
(
"Compressing box..."
))
if
err
:=
DirToBox
(
outputPath
,
dir
);
err
!=
nil
{
if
err
:=
DirToBox
(
outputPath
,
dir
);
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
return
NewArtifact
(
"virtualbox"
,
outputPath
),
nil
return
NewArtifact
(
"virtualbox"
,
outputPath
),
false
,
nil
}
}
func
(
p
*
VBoxBoxPostProcessor
)
findBaseMacAddress
(
a
packer
.
Artifact
)
(
string
,
error
)
{
func
(
p
*
VBoxBoxPostProcessor
)
findBaseMacAddress
(
a
packer
.
Artifact
)
(
string
,
error
)
{
...
...
post-processor/vagrant/vmware.go
View file @
f78cbb45
...
@@ -29,17 +29,17 @@ func (p *VMwareBoxPostProcessor) Configure(raw interface{}) error {
...
@@ -29,17 +29,17 @@ func (p *VMwareBoxPostProcessor) Configure(raw interface{}) error {
return
nil
return
nil
}
}
func
(
p
*
VMwareBoxPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
func
(
p
*
VMwareBoxPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
// Compile the output path
// Compile the output path
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
"vmware"
,
artifact
)
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
"vmware"
,
artifact
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
// Create a temporary directory for us to build the contents of the box in
// Create a temporary directory for us to build the contents of the box in
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
defer
os
.
RemoveAll
(
dir
)
defer
os
.
RemoveAll
(
dir
)
...
@@ -48,37 +48,37 @@ func (p *VMwareBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artif
...
@@ -48,37 +48,37 @@ func (p *VMwareBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artif
ui
.
Message
(
fmt
.
Sprintf
(
"Copying: %s"
,
path
))
ui
.
Message
(
fmt
.
Sprintf
(
"Copying: %s"
,
path
))
src
,
err
:=
os
.
Open
(
path
)
src
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
defer
src
.
Close
()
defer
src
.
Close
()
dst
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
filepath
.
Base
(
path
)))
dst
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
filepath
.
Base
(
path
)))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
defer
dst
.
Close
()
defer
dst
.
Close
()
if
_
,
err
:=
io
.
Copy
(
dst
,
src
);
err
!=
nil
{
if
_
,
err
:=
io
.
Copy
(
dst
,
src
);
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
}
}
if
p
.
config
.
VagrantfileTemplate
!=
""
{
if
p
.
config
.
VagrantfileTemplate
!=
""
{
f
,
err
:=
os
.
Open
(
p
.
config
.
VagrantfileTemplate
)
f
,
err
:=
os
.
Open
(
p
.
config
.
VagrantfileTemplate
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
defer
f
.
Close
()
defer
f
.
Close
()
contents
,
err
:=
ioutil
.
ReadAll
(
f
)
contents
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
// Create the Vagrantfile from the template
// Create the Vagrantfile from the template
vf
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
"Vagrantfile"
))
vf
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
"Vagrantfile"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
defer
vf
.
Close
()
defer
vf
.
Close
()
...
@@ -90,14 +90,14 @@ func (p *VMwareBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artif
...
@@ -90,14 +90,14 @@ func (p *VMwareBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artif
// Create the metadata
// Create the metadata
metadata
:=
map
[
string
]
string
{
"provider"
:
"vmware_desktop"
}
metadata
:=
map
[
string
]
string
{
"provider"
:
"vmware_desktop"
}
if
err
:=
WriteMetadata
(
dir
,
metadata
);
err
!=
nil
{
if
err
:=
WriteMetadata
(
dir
,
metadata
);
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
// Compress the directory to the given output path
// Compress the directory to the given output path
ui
.
Message
(
fmt
.
Sprintf
(
"Compressing box..."
))
ui
.
Message
(
fmt
.
Sprintf
(
"Compressing box..."
))
if
err
:=
DirToBox
(
outputPath
,
dir
);
err
!=
nil
{
if
err
:=
DirToBox
(
outputPath
,
dir
);
err
!=
nil
{
return
nil
,
err
return
nil
,
false
,
err
}
}
return
NewArtifact
(
"vmware"
,
outputPath
),
nil
return
NewArtifact
(
"vmware"
,
outputPath
),
false
,
nil
}
}
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