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
8ec68031
Commit
8ec68031
authored
Nov 09, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/docker: ability to disable pull
parent
0287cdd6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
22 deletions
+81
-22
builder/docker/config.go
builder/docker/config.go
+14
-0
builder/docker/config_test.go
builder/docker/config_test.go
+40
-22
builder/docker/step_pull.go
builder/docker/step_pull.go
+6
-0
builder/docker/step_pull_test.go
builder/docker/step_pull_test.go
+21
-0
No files found.
builder/docker/config.go
View file @
8ec68031
...
...
@@ -11,6 +11,7 @@ type Config struct {
ExportPath
string
`mapstructure:"export_path"`
Image
string
Pull
bool
tpl
*
packer
.
ConfigTemplate
}
...
...
@@ -27,6 +28,19 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
return
nil
,
nil
,
err
}
// Default Pull if it wasn't set
hasPull
:=
false
for
_
,
k
:=
range
md
.
Keys
{
if
k
==
"Pull"
{
hasPull
=
true
break
}
}
if
!
hasPull
{
c
.
Pull
=
true
}
errs
:=
common
.
CheckUnusedConfig
(
md
)
templates
:=
map
[
string
]
*
string
{
...
...
builder/docker/config_test.go
View file @
8ec68031
...
...
@@ -23,50 +23,68 @@ func testConfigStruct(t *testing.T) *Config {
return
c
}
func
TestConfigPrepare_exportPath
(
t
*
testing
.
T
)
{
raw
:=
testConfig
()
// No export path
delete
(
raw
,
"export_path"
)
_
,
warns
,
errs
:=
NewConfig
(
raw
)
func
testConfigErr
(
t
*
testing
.
T
,
warns
[]
string
,
err
error
)
{
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
s
==
nil
{
if
err
==
nil
{
t
.
Fatal
(
"should error"
)
}
}
// Good export path
raw
[
"export_path"
]
=
"good"
_
,
warns
,
errs
=
NewConfig
(
raw
)
func
testConfigOk
(
t
*
testing
.
T
,
warns
[]
string
,
err
error
)
{
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
s
!=
nil
{
t
.
Fatalf
(
"bad: %s"
,
err
s
)
if
err
!=
nil
{
t
.
Fatalf
(
"bad: %s"
,
err
)
}
}
func
TestConfigPrepare_exportPath
(
t
*
testing
.
T
)
{
raw
:=
testConfig
()
// No export path
delete
(
raw
,
"export_path"
)
_
,
warns
,
errs
:=
NewConfig
(
raw
)
testConfigErr
(
t
,
warns
,
errs
)
// Good export path
raw
[
"export_path"
]
=
"good"
_
,
warns
,
errs
=
NewConfig
(
raw
)
testConfigOk
(
t
,
warns
,
errs
)
}
func
TestConfigPrepare_image
(
t
*
testing
.
T
)
{
raw
:=
testConfig
()
// No image
delete
(
raw
,
"image"
)
_
,
warns
,
errs
:=
NewConfig
(
raw
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
errs
==
nil
{
t
.
Fatal
(
"should error"
)
}
testConfigErr
(
t
,
warns
,
errs
)
// Good image
raw
[
"image"
]
=
"path"
_
,
warns
,
errs
=
NewConfig
(
raw
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
testConfigOk
(
t
,
warns
,
errs
)
}
func
TestConfigPrepare_pull
(
t
*
testing
.
T
)
{
raw
:=
testConfig
()
// No pull set
delete
(
raw
,
"pull"
)
c
,
warns
,
errs
:=
NewConfig
(
raw
)
testConfigOk
(
t
,
warns
,
errs
)
if
!
c
.
Pull
{
t
.
Fatal
(
"should pull by default"
)
}
if
errs
!=
nil
{
t
.
Fatalf
(
"bad: %s"
,
errs
)
// Pull set
raw
[
"pull"
]
=
false
c
,
warns
,
errs
=
NewConfig
(
raw
)
testConfigOk
(
t
,
warns
,
errs
)
if
c
.
Pull
{
t
.
Fatal
(
"should not pull"
)
}
}
builder/docker/step_pull.go
View file @
8ec68031
...
...
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
type
StepPull
struct
{}
...
...
@@ -13,6 +14,11 @@ func (s *StepPull) Run(state multistep.StateBag) multistep.StepAction {
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
if
!
config
.
Pull
{
log
.
Println
(
"Pull disabled, won't docker pull"
)
return
multistep
.
ActionContinue
}
ui
.
Say
(
fmt
.
Sprintf
(
"Pulling Docker image: %s"
,
config
.
Image
))
if
err
:=
driver
.
Pull
(
config
.
Image
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error pulling Docker image: %s"
,
err
)
...
...
builder/docker/step_pull_test.go
View file @
8ec68031
...
...
@@ -50,3 +50,24 @@ func TestStepPull_error(t *testing.T) {
t
.
Fatal
(
"should have error"
)
}
}
func
TestStepPull_noPull
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepPull
)
defer
step
.
Cleanup
(
state
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
config
.
Pull
=
false
driver
:=
state
.
Get
(
"driver"
)
.
(
*
MockDriver
)
// run the step
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
// verify we did the right thing
if
driver
.
PullCalled
{
t
.
Fatal
(
"shouldn't have pulled"
)
}
}
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