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
dc1e67b6
Commit
dc1e67b6
authored
May 27, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-processor/*: interpolation
parent
2b4df93f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
100 deletions
+49
-100
post-processor/atlas/post-processor.go
post-processor/atlas/post-processor.go
+11
-25
post-processor/compress/post-processor.go
post-processor/compress/post-processor.go
+9
-30
post-processor/vagrant-cloud/post-processor.go
post-processor/vagrant-cloud/post-processor.go
+17
-21
post-processor/vsphere/post-processor.go
post-processor/vsphere/post-processor.go
+12
-24
No files found.
post-processor/atlas/post-processor.go
View file @
dc1e67b6
...
...
@@ -10,7 +10,9 @@ import (
"github.com/hashicorp/atlas-go/v1"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
)
const
BuildEnvKey
=
"ATLAS_BUILD_ID"
...
...
@@ -39,7 +41,7 @@ type Config struct {
// This shouldn't ever be set outside of unit tests.
Test
bool
`mapstructure:"test"`
tpl
*
packer
.
ConfigTemplate
ctx
interpolate
.
Context
user
,
name
string
buildId
int
}
...
...
@@ -50,38 +52,22 @@ type PostProcessor struct {
}
func
(
p
*
PostProcessor
)
Configure
(
raws
...
interface
{})
error
{
_
,
err
:=
common
.
DecodeConfig
(
&
p
.
config
,
raws
...
)
err
:=
config
.
Decode
(
&
p
.
config
,
&
config
.
DecodeOpts
{
Interpolate
:
true
,
InterpolateFilter
:
&
interpolate
.
RenderFilter
{
Exclude
:
[]
string
{},
},
},
raws
...
)
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
.
UserVars
=
p
.
config
.
PackerUserVars
templates
:=
map
[
string
]
*
string
{
"artifact"
:
&
p
.
config
.
Artifact
,
"type"
:
&
p
.
config
.
Type
,
"server_address"
:
&
p
.
config
.
ServerAddr
,
"token"
:
&
p
.
config
.
Token
,
}
errs
:=
new
(
packer
.
MultiError
)
for
key
,
ptr
:=
range
templates
{
*
ptr
,
err
=
p
.
config
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
key
,
err
))
}
}
required
:=
map
[
string
]
*
string
{
"artifact"
:
&
p
.
config
.
Artifact
,
"artifact_type"
:
&
p
.
config
.
Type
,
}
var
errs
*
packer
.
MultiError
for
key
,
ptr
:=
range
required
{
if
*
ptr
==
""
{
errs
=
packer
.
MultiErrorAppend
(
...
...
@@ -89,7 +75,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
}
}
if
len
(
errs
.
Errors
)
>
0
{
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
return
errs
}
...
...
post-processor/compress/post-processor.go
View file @
dc1e67b6
...
...
@@ -8,7 +8,9 @@ import (
"os"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
)
type
Config
struct
{
...
...
@@ -16,7 +18,7 @@ type Config struct {
OutputPath
string
`mapstructure:"output"`
tpl
*
packer
.
ConfigTemplate
ctx
interpolate
.
Context
}
type
PostProcessor
struct
{
...
...
@@ -24,39 +26,16 @@ type PostProcessor struct {
}
func
(
self
*
PostProcessor
)
Configure
(
raws
...
interface
{})
error
{
_
,
err
:=
common
.
DecodeConfig
(
&
self
.
config
,
raws
...
)
err
:=
config
.
Decode
(
&
self
.
config
,
&
config
.
DecodeOpts
{
Interpolate
:
true
,
InterpolateFilter
:
&
interpolate
.
RenderFilter
{
Exclude
:
[]
string
{},
},
},
raws
...
)
if
err
!=
nil
{
return
err
}
self
.
config
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
err
}
self
.
config
.
tpl
.
UserVars
=
self
.
config
.
PackerUserVars
templates
:=
map
[
string
]
*
string
{
"output"
:
&
self
.
config
.
OutputPath
,
}
errs
:=
new
(
packer
.
MultiError
)
for
key
,
ptr
:=
range
templates
{
if
*
ptr
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"%s must be set"
,
key
))
}
*
ptr
,
err
=
self
.
config
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
key
,
err
))
}
}
if
len
(
errs
.
Errors
)
>
0
{
return
errs
}
return
nil
}
...
...
post-processor/vagrant-cloud/post-processor.go
View file @
dc1e67b6
...
...
@@ -6,11 +6,14 @@ package vagrantcloud
import
(
"fmt"
"log"
"strings"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"log"
"strings"
"github.com/mitchellh/packer/template/interpolate"
)
const
VAGRANT_CLOUD_URL
=
"https://vagrantcloud.com/api/v1"
...
...
@@ -28,7 +31,7 @@ type Config struct {
BoxDownloadUrl
string
`mapstructure:"box_download_url"`
tpl
*
packer
.
ConfigTemplate
ctx
interpolate
.
Context
}
type
boxDownloadUrlTemplate
struct
{
...
...
@@ -43,16 +46,17 @@ type PostProcessor struct {
}
func
(
p
*
PostProcessor
)
Configure
(
raws
...
interface
{})
error
{
_
,
err
:=
common
.
DecodeConfig
(
&
p
.
config
,
raws
...
)
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
err
:=
config
.
Decode
(
&
p
.
config
,
&
config
.
DecodeOpts
{
Interpolate
:
true
,
InterpolateFilter
:
&
interpolate
.
RenderFilter
{
Exclude
:
[]
string
{
"box_download_url"
,
},
},
},
raws
...
)
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
.
UserVars
=
p
.
config
.
PackerUserVars
// Default configuration
if
p
.
config
.
VagrantCloudUrl
==
""
{
...
...
@@ -76,15 +80,6 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
}
}
// Template process
for
key
,
ptr
:=
range
templates
{
*
ptr
,
err
=
p
.
config
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
key
,
err
))
}
}
if
len
(
errs
.
Errors
)
>
0
{
return
errs
}
...
...
@@ -111,10 +106,11 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
// The name of the provider for vagrant cloud, and vagrant
providerName
:=
providerFromBuilderName
(
artifact
.
Id
())
boxDownloadUrl
,
err
:=
p
.
config
.
tpl
.
Process
(
p
.
config
.
BoxDownloadUrl
,
&
boxDownloadUrlTemplate
{
p
.
config
.
ctx
.
Data
=
&
boxDownloadUrlTemplate
{
ArtifactId
:
artifact
.
Id
(),
Provider
:
providerName
,
})
}
boxDownloadUrl
,
err
:=
interpolate
.
Render
(
p
.
config
.
BoxDownloadUrl
,
&
p
.
config
.
ctx
)
if
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"Error processing box_download_url: %s"
,
err
)
}
...
...
post-processor/vsphere/post-processor.go
View file @
dc1e67b6
...
...
@@ -3,12 +3,15 @@ package vsphere
import
(
"bytes"
"fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"log"
"net/url"
"os/exec"
"strings"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
)
var
builtins
=
map
[
string
]
string
{
...
...
@@ -31,7 +34,7 @@ type Config struct {
VMName
string
`mapstructure:"vm_name"`
VMNetwork
string
`mapstructure:"vm_network"`
tpl
*
packer
.
ConfigTemplate
ctx
interpolate
.
Context
}
type
PostProcessor
struct
{
...
...
@@ -39,16 +42,15 @@ type PostProcessor struct {
}
func
(
p
*
PostProcessor
)
Configure
(
raws
...
interface
{})
error
{
_
,
err
:=
common
.
DecodeConfig
(
&
p
.
config
,
raws
...
)
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
,
err
=
packer
.
NewConfigTemplate
(
)
err
:=
config
.
Decode
(
&
p
.
config
,
&
config
.
DecodeOpts
{
Interpolate
:
true
,
InterpolateFilter
:
&
interpolate
.
RenderFilter
{
Exclude
:
[]
string
{},
},
},
raws
...
)
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
.
UserVars
=
p
.
config
.
PackerUserVars
// Defaults
if
p
.
config
.
DiskMode
==
""
{
...
...
@@ -81,20 +83,6 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
}
}
// Then define the ones that are optional
templates
[
"datastore"
]
=
&
p
.
config
.
Datastore
templates
[
"vm_network"
]
=
&
p
.
config
.
VMNetwork
templates
[
"vm_folder"
]
=
&
p
.
config
.
VMFolder
// Template process
for
key
,
ptr
:=
range
templates
{
*
ptr
,
err
=
p
.
config
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
key
,
err
))
}
}
if
len
(
errs
.
Errors
)
>
0
{
return
errs
}
...
...
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