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
2e4882f0
Commit
2e4882f0
authored
Sep 05, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/docker: can login to pull
parent
622b9f45
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
2 deletions
+77
-2
CHANGELOG.md
CHANGELOG.md
+1
-0
builder/docker/config.go
builder/docker/config.go
+12
-2
builder/docker/step_pull.go
builder/docker/step_pull.go
+23
-0
builder/docker/step_pull_test.go
builder/docker/step_pull_test.go
+29
-0
website/source/docs/builders/docker.html.markdown
website/source/docs/builders/docker.html.markdown
+12
-0
No files found.
CHANGELOG.md
View file @
2e4882f0
...
@@ -15,6 +15,7 @@ FEATURES:
...
@@ -15,6 +15,7 @@ FEATURES:
Packer will look in the PWD and the directory with
`packer`
for
Packer will look in the PWD and the directory with
`packer`
for
binaries named
`packer-TYPE-NAME`
.
binaries named
`packer-TYPE-NAME`
.
*
builder/docker: Images can now be committed instead of exported. [GH-1198]
*
builder/docker: Images can now be committed instead of exported. [GH-1198]
*
builder/docker: Can now specify login credentials to pull images.
*
builder/virtualbox-ovf: New
`import_flags`
setting can be used to add
*
builder/virtualbox-ovf: New
`import_flags`
setting can be used to add
new command line flags to
`VBoxManage import`
to allow things such
new command line flags to
`VBoxManage import`
to allow things such
as EULAs to be accepted. [GH-1383]
as EULAs to be accepted. [GH-1383]
...
...
builder/docker/config.go
View file @
2e4882f0
...
@@ -15,6 +15,12 @@ type Config struct {
...
@@ -15,6 +15,12 @@ type Config struct {
Pull
bool
Pull
bool
RunCommand
[]
string
`mapstructure:"run_command"`
RunCommand
[]
string
`mapstructure:"run_command"`
Login
bool
LoginEmail
string
`mapstructure:"login_email"`
LoginUsername
string
`mapstructure:"login_username"`
LoginPassword
string
`mapstructure:"login_password"`
LoginServer
string
`mapstructure:"login_server"`
tpl
*
packer
.
ConfigTemplate
tpl
*
packer
.
ConfigTemplate
}
}
...
@@ -59,8 +65,12 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
...
@@ -59,8 +65,12 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
errs
:=
common
.
CheckUnusedConfig
(
md
)
errs
:=
common
.
CheckUnusedConfig
(
md
)
templates
:=
map
[
string
]
*
string
{
templates
:=
map
[
string
]
*
string
{
"export_path"
:
&
c
.
ExportPath
,
"export_path"
:
&
c
.
ExportPath
,
"image"
:
&
c
.
Image
,
"image"
:
&
c
.
Image
,
"login_email"
:
&
c
.
LoginEmail
,
"login_username"
:
&
c
.
LoginUsername
,
"login_password"
:
&
c
.
LoginPassword
,
"login_server"
:
&
c
.
LoginServer
,
}
}
for
n
,
ptr
:=
range
templates
{
for
n
,
ptr
:=
range
templates
{
...
...
builder/docker/step_pull.go
View file @
2e4882f0
...
@@ -20,6 +20,29 @@ func (s *StepPull) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -20,6 +20,29 @@ func (s *StepPull) Run(state multistep.StateBag) multistep.StepAction {
}
}
ui
.
Say
(
fmt
.
Sprintf
(
"Pulling Docker image: %s"
,
config
.
Image
))
ui
.
Say
(
fmt
.
Sprintf
(
"Pulling Docker image: %s"
,
config
.
Image
))
if
config
.
Login
{
ui
.
Message
(
"Logging in..."
)
err
:=
driver
.
Login
(
config
.
LoginServer
,
config
.
LoginEmail
,
config
.
LoginUsername
,
config
.
LoginPassword
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error logging in: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
defer
func
()
{
ui
.
Message
(
"Logging out..."
)
if
err
:=
driver
.
Logout
(
config
.
LoginServer
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error logging out: %s"
,
err
))
}
}()
}
if
err
:=
driver
.
Pull
(
config
.
Image
);
err
!=
nil
{
if
err
:=
driver
.
Pull
(
config
.
Image
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error pulling Docker image: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error pulling Docker image: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
state
.
Put
(
"error"
,
err
)
...
...
builder/docker/step_pull_test.go
View file @
2e4882f0
...
@@ -51,6 +51,35 @@ func TestStepPull_error(t *testing.T) {
...
@@ -51,6 +51,35 @@ func TestStepPull_error(t *testing.T) {
}
}
}
}
func
TestStepPull_login
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepPull
)
defer
step
.
Cleanup
(
state
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
*
MockDriver
)
config
.
Login
=
true
// run the step
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
// verify we pulled
if
!
driver
.
PullCalled
{
t
.
Fatal
(
"should've pulled"
)
}
// verify we logged in
if
!
driver
.
LoginCalled
{
t
.
Fatal
(
"should've logged in"
)
}
if
!
driver
.
LogoutCalled
{
t
.
Fatal
(
"should've logged out"
)
}
}
func
TestStepPull_noPull
(
t
*
testing
.
T
)
{
func
TestStepPull_noPull
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
state
:=
testState
(
t
)
step
:=
new
(
StepPull
)
step
:=
new
(
StepPull
)
...
...
website/source/docs/builders/docker.html.markdown
View file @
2e4882f0
...
@@ -74,6 +74,18 @@ described.
...
@@ -74,6 +74,18 @@ described.
### Optional:
### Optional:
*
`login`
(boolean) - Defaults to false. If true, the builder will
login in order to pull the image. The builder only logs in for the
duration of the pull. It always logs out afterwards.
*
`login_email`
(string) - The email to use to authenticate to login.
*
`login_username`
(string) - The username to use to authenticate to login.
*
`login_password`
(string) - The password to use to authenticate to login.
*
`login_server`
(string) - The server address to login to.
*
`pull`
(boolean) - If true, the configured image will be pulled using
*
`pull`
(boolean) - If true, the configured image will be pulled using
`docker pull`
prior to use. Otherwise, it is assumed the image already
`docker pull`
prior to use. Otherwise, it is assumed the image already
exists and can be used. This defaults to true if not set.
exists and can be used. This defaults to true if not set.
...
...
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