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
0287cdd6
Commit
0287cdd6
authored
Nov 09, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/docker: config refactor
parent
8f39edf9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
55 deletions
+60
-55
builder/docker/builder.go
builder/docker/builder.go
+5
-22
builder/docker/config.go
builder/docker/config.go
+23
-6
builder/docker/config_test.go
builder/docker/config_test.go
+32
-27
No files found.
builder/docker/builder.go
View file @
0287cdd6
...
...
@@ -10,33 +10,16 @@ import (
const
BuilderId
=
"packer.docker"
type
Builder
struct
{
config
Config
config
*
Config
runner
multistep
.
Runner
}
func
(
b
*
Builder
)
Prepare
(
raws
...
interface
{})
([]
string
,
error
)
{
md
,
err
:=
common
.
DecodeConfig
(
&
b
.
config
,
raws
...
)
if
err
!=
nil
{
return
nil
,
err
}
b
.
config
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
nil
,
err
}
// Accumulate any errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
warnings
:=
make
([]
string
,
0
)
// Validate the configuration
cwarns
,
cerrs
:=
b
.
config
.
Prepare
()
errs
=
packer
.
MultiErrorAppend
(
errs
,
cerrs
...
)
warnings
=
append
(
warnings
,
cwarns
...
)
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
c
,
warnings
,
errs
:=
NewConfig
(
raws
...
)
if
errs
!=
nil
{
return
warnings
,
errs
}
b
.
config
=
c
return
warnings
,
nil
}
...
...
@@ -52,7 +35,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Setup the state bag and initial state for the steps
state
:=
new
(
multistep
.
BasicStateBag
)
state
.
Put
(
"config"
,
&
b
.
config
)
state
.
Put
(
"config"
,
b
.
config
)
state
.
Put
(
"hook"
,
hook
)
state
.
Put
(
"ui"
,
ui
)
...
...
builder/docker/config.go
View file @
0287cdd6
...
...
@@ -15,8 +15,19 @@ type Config struct {
tpl
*
packer
.
ConfigTemplate
}
func
(
c
*
Config
)
Prepare
()
([]
string
,
[]
error
)
{
errs
:=
make
([]
error
,
0
)
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
()
if
err
!=
nil
{
return
nil
,
nil
,
err
}
errs
:=
common
.
CheckUnusedConfig
(
md
)
templates
:=
map
[
string
]
*
string
{
"export_path"
:
&
c
.
ExportPath
,
...
...
@@ -27,18 +38,24 @@ func (c *Config) Prepare() ([]string, []error) {
var
err
error
*
ptr
,
err
=
c
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
a
ppend
(
errs
=
packer
.
MultiErrorA
ppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
if
c
.
ExportPath
==
""
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"export_path must be specified"
))
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"export_path must be specified"
))
}
if
c
.
Image
==
""
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"image must be specified"
))
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"image must be specified"
))
}
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
return
nil
,
nil
,
errs
}
return
nil
,
errs
return
c
,
nil
,
nil
}
builder/docker/config_test.go
View file @
0287cdd6
package
docker
import
(
"github.com/mitchellh/packer/packer"
"testing"
)
func
testConfig
Struct
(
t
*
testing
.
T
)
*
Config
{
tpl
,
err
:=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
func
testConfig
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
"export_path"
:
"foo"
,
"image"
:
"bar"
,
}
}
return
&
Config
{
ExportPath
:
"foo"
,
Image
:
"bar"
,
tpl
:
tpl
,
func
testConfigStruct
(
t
*
testing
.
T
)
*
Config
{
c
,
warns
,
errs
:=
NewConfig
(
testConfig
())
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
len
(
warns
))
}
if
errs
!=
nil
{
t
.
Fatalf
(
"bad: %#v"
,
errs
)
}
return
c
}
func
TestConfigPrepare_exportPath
(
t
*
testing
.
T
)
{
c
:=
testConfigStruct
(
t
)
raw
:=
testConfig
(
)
// No export path
c
.
ExportPath
=
""
warns
,
errs
:=
c
.
Prepare
(
)
delete
(
raw
,
"export_path"
)
_
,
warns
,
errs
:=
NewConfig
(
raw
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
len
(
errs
)
<=
0
{
t
.
Fatal
f
(
"bad: %#v"
,
errs
)
if
errs
==
nil
{
t
.
Fatal
(
"should error"
)
}
// Good export path
c
.
ExportPath
=
"path
"
warns
,
errs
=
c
.
Prepare
(
)
raw
[
"export_path"
]
=
"good
"
_
,
warns
,
errs
=
NewConfig
(
raw
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"bad: %
#v
"
,
errs
)
if
errs
!=
nil
{
t
.
Fatalf
(
"bad: %
s
"
,
errs
)
}
}
func
TestConfigPrepare_image
(
t
*
testing
.
T
)
{
c
:=
testConfigStruct
(
t
)
raw
:=
testConfig
(
)
// No image
c
.
Image
=
""
warns
,
errs
:=
c
.
Prepare
(
)
delete
(
raw
,
"image"
)
_
,
warns
,
errs
:=
NewConfig
(
raw
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
len
(
errs
)
<=
0
{
t
.
Fatal
f
(
"bad: %#v"
,
errs
)
if
errs
==
nil
{
t
.
Fatal
(
"should error"
)
}
// Good image
c
.
Image
=
"path"
warns
,
errs
=
c
.
Prepare
(
)
raw
[
"image"
]
=
"path"
_
,
warns
,
errs
=
NewConfig
(
raw
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"bad: %
#v
"
,
errs
)
if
errs
!=
nil
{
t
.
Fatalf
(
"bad: %
s
"
,
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