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
7537eeae
Commit
7537eeae
authored
Oct 20, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #506 from maspwr/compression_level
post-processors/vagrant: add compression_level option
parents
d1c49767
21787cfe
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
5 deletions
+59
-5
post-processor/vagrant/aws.go
post-processor/vagrant/aws.go
+13
-1
post-processor/vagrant/util.go
post-processor/vagrant/util.go
+5
-2
post-processor/vagrant/virtualbox.go
post-processor/vagrant/virtualbox.go
+13
-1
post-processor/vagrant/vmware.go
post-processor/vagrant/vmware.go
+13
-1
website/source/docs/post-processors/vagrant.html.markdown
website/source/docs/post-processors/vagrant.html.markdown
+15
-0
No files found.
post-processor/vagrant/aws.go
View file @
7537eeae
package
vagrant
import
(
"compress/flate"
"fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
...
...
@@ -8,6 +9,7 @@ import (
"log"
"os"
"path/filepath"
"strconv"
"strings"
)
...
...
@@ -16,6 +18,7 @@ type AWSBoxConfig struct {
OutputPath
string
`mapstructure:"output"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
CompressionLevel
string
`mapstructure:"compression_level"`
tpl
*
packer
.
ConfigTemplate
}
...
...
@@ -46,6 +49,7 @@ func (p *AWSBoxPostProcessor) Configure(raws ...interface{}) error {
validates
:=
map
[
string
]
*
string
{
"output"
:
&
p
.
config
.
OutputPath
,
"vagrantfile_template"
:
&
p
.
config
.
VagrantfileTemplate
,
"compression_level"
:
&
p
.
config
.
CompressionLevel
,
}
for
n
,
ptr
:=
range
validates
{
...
...
@@ -127,6 +131,14 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
vf
.
Write
([]
byte
(
vagrantfileContents
))
vf
.
Close
()
var
level
int
=
flate
.
DefaultCompression
if
p
.
config
.
CompressionLevel
!=
""
{
level
,
err
=
strconv
.
Atoi
(
p
.
config
.
CompressionLevel
)
if
err
!=
nil
{
return
nil
,
false
,
err
}
}
// Create the metadata
metadata
:=
map
[
string
]
string
{
"provider"
:
"aws"
}
if
err
:=
WriteMetadata
(
dir
,
metadata
);
err
!=
nil
{
...
...
@@ -134,7 +146,7 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
}
// Compress the directory to the given output path
if
err
:=
DirToBox
(
outputPath
,
dir
,
ui
);
err
!=
nil
{
if
err
:=
DirToBox
(
outputPath
,
dir
,
ui
,
level
);
err
!=
nil
{
err
=
fmt
.
Errorf
(
"error creating box: %s"
,
err
)
return
nil
,
false
,
err
}
...
...
post-processor/vagrant/util.go
View file @
7537eeae
...
...
@@ -44,7 +44,7 @@ func CopyContents(dst, src string) error {
// DirToBox takes the directory and compresses it into a Vagrant-compatible
// box. This function does not perform checks to verify that dir is
// actually a proper box. This is an expected precondition.
func
DirToBox
(
dst
,
dir
string
,
ui
packer
.
Ui
)
error
{
func
DirToBox
(
dst
,
dir
string
,
ui
packer
.
Ui
,
level
int
)
error
{
log
.
Printf
(
"Turning dir into box: %s => %s"
,
dir
,
dst
)
dstF
,
err
:=
os
.
Create
(
dst
)
if
err
!=
nil
{
...
...
@@ -52,7 +52,10 @@ func DirToBox(dst, dir string, ui packer.Ui) error {
}
defer
dstF
.
Close
()
gzipWriter
:=
gzip
.
NewWriter
(
dstF
)
gzipWriter
,
err
:=
gzip
.
NewWriterLevel
(
dstF
,
level
)
if
err
!=
nil
{
return
err
}
defer
gzipWriter
.
Close
()
tarWriter
:=
tar
.
NewWriter
(
gzipWriter
)
...
...
post-processor/vagrant/virtualbox.go
View file @
7537eeae
...
...
@@ -2,6 +2,7 @@ package vagrant
import
(
"archive/tar"
"compress/flate"
"errors"
"fmt"
"github.com/mitchellh/packer/common"
...
...
@@ -12,6 +13,7 @@ import (
"os"
"path/filepath"
"regexp"
"strconv"
)
type
VBoxBoxConfig
struct
{
...
...
@@ -19,6 +21,7 @@ type VBoxBoxConfig struct {
OutputPath
string
`mapstructure:"output"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
CompressionLevel
string
`mapstructure:"compression_level"`
tpl
*
packer
.
ConfigTemplate
}
...
...
@@ -49,6 +52,7 @@ func (p *VBoxBoxPostProcessor) Configure(raws ...interface{}) error {
validates
:=
map
[
string
]
*
string
{
"output"
:
&
p
.
config
.
OutputPath
,
"vagrantfile_template"
:
&
p
.
config
.
VagrantfileTemplate
,
"compression_level"
:
&
p
.
config
.
CompressionLevel
,
}
for
n
,
ptr
:=
range
validates
{
...
...
@@ -141,6 +145,14 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
vf
.
Write
([]
byte
(
vagrantfileContents
))
vf
.
Close
()
var
level
int
=
flate
.
DefaultCompression
if
p
.
config
.
CompressionLevel
!=
""
{
level
,
err
=
strconv
.
Atoi
(
p
.
config
.
CompressionLevel
)
if
err
!=
nil
{
return
nil
,
false
,
err
}
}
// Create the metadata
metadata
:=
map
[
string
]
string
{
"provider"
:
"virtualbox"
}
if
err
:=
WriteMetadata
(
dir
,
metadata
);
err
!=
nil
{
...
...
@@ -155,7 +167,7 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
// Compress the directory to the given output path
ui
.
Message
(
fmt
.
Sprintf
(
"Compressing box..."
))
if
err
:=
DirToBox
(
outputPath
,
dir
,
ui
);
err
!=
nil
{
if
err
:=
DirToBox
(
outputPath
,
dir
,
ui
,
level
);
err
!=
nil
{
return
nil
,
false
,
err
}
...
...
post-processor/vagrant/vmware.go
View file @
7537eeae
package
vagrant
import
(
"compress/flate"
"fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"io/ioutil"
"os"
"path/filepath"
"strconv"
)
type
VMwareBoxConfig
struct
{
...
...
@@ -14,6 +16,7 @@ type VMwareBoxConfig struct {
OutputPath
string
`mapstructure:"output"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
CompressionLevel
string
`mapstructure:"compression_level"`
tpl
*
packer
.
ConfigTemplate
}
...
...
@@ -40,6 +43,7 @@ func (p *VMwareBoxPostProcessor) Configure(raws ...interface{}) error {
validates
:=
map
[
string
]
*
string
{
"output"
:
&
p
.
config
.
OutputPath
,
"vagrantfile_template"
:
&
p
.
config
.
VagrantfileTemplate
,
"compression_level"
:
&
p
.
config
.
CompressionLevel
,
}
for
n
,
ptr
:=
range
validates
{
...
...
@@ -111,6 +115,14 @@ func (p *VMwareBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artif
vf
.
Close
()
}
var
level
int
=
flate
.
DefaultCompression
if
p
.
config
.
CompressionLevel
!=
""
{
level
,
err
=
strconv
.
Atoi
(
p
.
config
.
CompressionLevel
)
if
err
!=
nil
{
return
nil
,
false
,
err
}
}
// Create the metadata
metadata
:=
map
[
string
]
string
{
"provider"
:
"vmware_desktop"
}
if
err
:=
WriteMetadata
(
dir
,
metadata
);
err
!=
nil
{
...
...
@@ -119,7 +131,7 @@ func (p *VMwareBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artif
// Compress the directory to the given output path
ui
.
Message
(
fmt
.
Sprintf
(
"Compressing box..."
))
if
err
:=
DirToBox
(
outputPath
,
dir
,
ui
);
err
!=
nil
{
if
err
:=
DirToBox
(
outputPath
,
dir
,
ui
,
level
);
err
!=
nil
{
return
nil
,
false
,
err
}
...
...
website/source/docs/post-processors/vagrant.html.markdown
View file @
7537eeae
...
...
@@ -68,6 +68,11 @@ The AWS provider itself can be configured with specific options:
this is a template that simply sets the AMIs for the various regions
of the AWS build.
*
`compression_level`
(integer) - An integer repesenting the
compression level to use when creating the Vagrant box. Valid
values range from 0 to 9, with 0 being no compression and 9 being
the best compression.
The
`vagrantfile_template`
has the
`Images`
variable which is a map
of region (string) to AMI ID (string). An example Vagrantfile template for
AWS is shown below. The example simply sets the AMI for each region.
...
...
@@ -91,6 +96,11 @@ The VirtualBox provider itself can be configured with specific options:
[
text template
](
http://golang.org/pkg/text/template
)
. By default this is
a template that just sets the base MAC address so that networking works.
*
`compression_level`
(integer) - An integer repesenting the
compression level to use when creating the Vagrant box. Valid
values range from 0 to 9, with 0 being no compression and 9 being
the best compression.
The
`vagrantfile_template`
has the
`BaseMACAddress`
variable which is a string
containing the MAC address of the first network interface. This must be set
in the Vagrantfile for networking to work properly with Vagrant. An example
...
...
@@ -111,3 +121,8 @@ The VMware provider itself can be configured with specific options:
[
text template
](
http://golang.org/pkg/text/template
)
. By default no
Vagrantfile is packaged with the box. Note that currently no variables
are available in the template, but this may change in the future.
*
`compression_level`
(integer) - An integer repesenting the
compression level to use when creating the Vagrant box. Valid
values range from 0 to 9, with 0 being no compression and 9 being
the best compression.
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