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
6f3d0f6b
Commit
6f3d0f6b
authored
Jun 27, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-processor/vagrant: compile the output path
parent
faa75051
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
5 deletions
+46
-5
post-processor/vagrant/aws.go
post-processor/vagrant/aws.go
+9
-3
post-processor/vagrant/util.go
post-processor/vagrant/util.go
+29
-0
post-processor/vagrant/virtualbox.go
post-processor/vagrant/virtualbox.go
+8
-2
No files found.
post-processor/vagrant/aws.go
View file @
6f3d0f6b
...
@@ -12,7 +12,7 @@ import (
...
@@ -12,7 +12,7 @@ import (
)
)
type
AWSBoxConfig
struct
{
type
AWSBoxConfig
struct
{
OutputPath
string
`mapstructure:"output"`
OutputPath
string
`mapstructure:"output"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
}
}
...
@@ -48,6 +48,12 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
...
@@ -48,6 +48,12 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
tplData
.
Images
[
parts
[
0
]]
=
parts
[
1
]
tplData
.
Images
[
parts
[
0
]]
=
parts
[
1
]
}
}
// Compile the output path
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
"aws"
,
artifact
)
if
err
!=
nil
{
return
nil
,
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
{
...
@@ -89,11 +95,11 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
...
@@ -89,11 +95,11 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
}
}
// Compress the directory to the given output path
// Compress the directory to the given output path
if
err
:=
DirToBox
(
p
.
config
.
O
utputPath
,
dir
);
err
!=
nil
{
if
err
:=
DirToBox
(
o
utputPath
,
dir
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
NewArtifact
(
"aws"
,
p
.
config
.
O
utputPath
),
nil
return
NewArtifact
(
"aws"
,
o
utputPath
),
nil
}
}
var
defaultAWSVagrantfile
=
`
var
defaultAWSVagrantfile
=
`
...
...
post-processor/vagrant/util.go
View file @
6f3d0f6b
...
@@ -2,13 +2,23 @@ package vagrant
...
@@ -2,13 +2,23 @@ package vagrant
import
(
import
(
"archive/tar"
"archive/tar"
"bytes"
"compress/gzip"
"compress/gzip"
"encoding/json"
"encoding/json"
"github.com/mitchellh/packer/packer"
"io"
"io"
"os"
"os"
"path/filepath"
"path/filepath"
"text/template"
)
)
// OutputPathTemplate is the structure that is availalable within the
// OutputPath variables.
type
OutputPathTemplate
struct
{
ArtifactId
string
Provider
string
}
// DirToBox takes the directory and compresses it into a Vagrant-compatible
// DirToBox takes the directory and compresses it into a Vagrant-compatible
// box. This function does not perform checks to verify that dir is
// box. This function does not perform checks to verify that dir is
// actually a proper box. This is an expected precondition.
// actually a proper box. This is an expected precondition.
...
@@ -62,6 +72,25 @@ func DirToBox(dst, dir string) error {
...
@@ -62,6 +72,25 @@ func DirToBox(dst, dir string) error {
return
filepath
.
Walk
(
dir
,
tarWalk
)
return
filepath
.
Walk
(
dir
,
tarWalk
)
}
}
// ProcessOutputPath takes an output path template and executes it,
// replacing variables with their respective values.
func
ProcessOutputPath
(
path
string
,
provider
string
,
artifact
packer
.
Artifact
)
(
string
,
error
)
{
var
buf
bytes
.
Buffer
tplData
:=
&
OutputPathTemplate
{
ArtifactId
:
artifact
.
Id
(),
Provider
:
provider
,
}
t
,
err
:=
template
.
New
(
"output"
)
.
Parse
(
path
)
if
err
!=
nil
{
return
""
,
err
}
err
=
t
.
Execute
(
&
buf
,
tplData
)
return
buf
.
String
(),
err
}
// WriteMetadata writes the "metadata.json" file for a Vagrant box.
// WriteMetadata writes the "metadata.json" file for a Vagrant box.
func
WriteMetadata
(
dir
string
,
contents
interface
{})
error
{
func
WriteMetadata
(
dir
string
,
contents
interface
{})
error
{
f
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
"metadata.json"
))
f
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
"metadata.json"
))
...
...
post-processor/vagrant/virtualbox.go
View file @
6f3d0f6b
...
@@ -37,6 +37,12 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
...
@@ -37,6 +37,12 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
// TODO(mitchellh): Actually parse the base mac address
// TODO(mitchellh): Actually parse the base mac address
tplData
:=
&
VBoxVagrantfileTemplate
{}
tplData
:=
&
VBoxVagrantfileTemplate
{}
// Compile the output path
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
"aws"
,
artifact
)
if
err
!=
nil
{
return
nil
,
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
{
...
@@ -99,11 +105,11 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
...
@@ -99,11 +105,11 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
// 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
(
p
.
config
.
O
utputPath
,
dir
);
err
!=
nil
{
if
err
:=
DirToBox
(
o
utputPath
,
dir
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
NewArtifact
(
"virtualbox"
,
p
.
config
.
O
utputPath
),
nil
return
NewArtifact
(
"virtualbox"
,
o
utputPath
),
nil
}
}
var
defaultVBoxVagrantfile
=
`
var
defaultVBoxVagrantfile
=
`
...
...
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