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
faf327ee
Commit
faf327ee
authored
May 27, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/docker: convert to new interpolation
parent
7d0f9483
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
42 deletions
+22
-42
builder/docker/builder.go
builder/docker/builder.go
+1
-1
builder/docker/config.go
builder/docker/config.go
+16
-39
builder/docker/driver_docker.go
builder/docker/driver_docker.go
+5
-2
No files found.
builder/docker/builder.go
View file @
faf327ee
...
...
@@ -26,7 +26,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
driver
:=
&
DockerDriver
{
Tpl
:
b
.
config
.
tpl
,
Ui
:
ui
}
driver
:=
&
DockerDriver
{
Ctx
:
b
.
config
.
ctx
,
Ui
:
ui
}
if
err
:=
driver
.
Verify
();
err
!=
nil
{
return
nil
,
err
}
...
...
builder/docker/config.go
View file @
faf327ee
...
...
@@ -2,8 +2,12 @@ package docker
import
(
"fmt"
"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"
)
type
Config
struct
{
...
...
@@ -22,23 +26,26 @@ type Config struct {
LoginPassword
string
`mapstructure:"login_password"`
LoginServer
string
`mapstructure:"login_server"`
tpl
*
packer
.
ConfigTemplate
ctx
*
interpolate
.
Context
}
func
NewConfig
(
raws
...
interface
{})
(
*
Config
,
[]
string
,
error
)
{
c
:=
new
(
Config
)
md
,
err
:=
common
.
DecodeConfig
(
c
,
raws
...
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
c
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
var
md
mapstructure
.
Metadata
err
:=
config
.
Decode
(
&
c
,
&
config
.
DecodeOpts
{
Metadata
:
&
md
,
Interpolate
:
true
,
InterpolateFilter
:
&
interpolate
.
RenderFilter
{
Exclude
:
[]
string
{
"run_command"
,
},
},
},
raws
...
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
c
.
tpl
.
UserVars
=
c
.
PackerUserVars
// Defaults
if
len
(
c
.
RunCommand
)
==
0
{
c
.
RunCommand
=
[]
string
{
...
...
@@ -61,37 +68,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
c
.
Pull
=
true
}
errs
:=
common
.
CheckUnusedConfig
(
md
)
templates
:=
map
[
string
]
*
string
{
"export_path"
:
&
c
.
ExportPath
,
"image"
:
&
c
.
Image
,
"login_email"
:
&
c
.
LoginEmail
,
"login_username"
:
&
c
.
LoginUsername
,
"login_password"
:
&
c
.
LoginPassword
,
"login_server"
:
&
c
.
LoginServer
,
}
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
c
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
for
k
,
v
:=
range
c
.
Volumes
{
var
err
error
v
,
err
=
c
.
tpl
.
Process
(
v
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing volumes[%s]: %s"
,
k
,
err
))
}
c
.
Volumes
[
k
]
=
v
}
var
errs
*
packer
.
MultiError
if
c
.
Image
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"image must be specified"
))
...
...
builder/docker/driver_docker.go
View file @
faf327ee
...
...
@@ -11,11 +11,12 @@ import (
"sync"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
)
type
DockerDriver
struct
{
Ui
packer
.
Ui
Tpl
*
packer
.
ConfigTemplate
Ctx
*
interpolate
.
Context
l
sync
.
Mutex
}
...
...
@@ -185,6 +186,8 @@ func (d *DockerDriver) StartContainer(config *ContainerConfig) (string, error) {
// Build up the template data
var
tplData
startContainerTemplate
tplData
.
Image
=
config
.
Image
ctx
:=
*
d
.
Ctx
ctx
.
Data
=
&
tplData
// Args that we're going to pass to Docker
args
:=
[]
string
{
"run"
}
...
...
@@ -192,7 +195,7 @@ func (d *DockerDriver) StartContainer(config *ContainerConfig) (string, error) {
args
=
append
(
args
,
"-v"
,
fmt
.
Sprintf
(
"%s:%s"
,
host
,
guest
))
}
for
_
,
v
:=
range
config
.
RunCommand
{
v
,
err
:=
d
.
Tpl
.
Process
(
v
,
&
tplData
)
v
,
err
:=
interpolate
.
Render
(
v
,
&
ctx
)
if
err
!=
nil
{
return
""
,
err
}
...
...
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