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
cab26651
Commit
cab26651
authored
Jun 14, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/docker: support custom communicators
parent
7fc69828
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
117 additions
and
7 deletions
+117
-7
builder/docker/builder.go
builder/docker/builder.go
+10
-1
builder/docker/comm.go
builder/docker/comm.go
+52
-0
builder/docker/config.go
builder/docker/config.go
+10
-0
builder/docker/driver.go
builder/docker/driver.go
+4
-0
builder/docker/driver_docker.go
builder/docker/driver_docker.go
+17
-0
builder/docker/driver_mock.go
builder/docker/driver_mock.go
+11
-0
builder/docker/step_connect_docker.go
builder/docker/step_connect_docker.go
+5
-6
helper/communicator/step_connect.go
helper/communicator/step_connect.go
+8
-0
No files found.
builder/docker/builder.go
View file @
cab26651
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/communicator"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
)
)
...
@@ -42,7 +43,15 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -42,7 +43,15 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
StepTempDir
{},
&
StepTempDir
{},
&
StepPull
{},
&
StepPull
{},
&
StepRun
{},
&
StepRun
{},
&
StepProvision
{},
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
Comm
,
Host
:
commHost
,
SSHConfig
:
sshConfig
(
&
b
.
config
.
Comm
),
CustomConnect
:
map
[
string
]
multistep
.
Step
{
"docker"
:
&
StepConnectDocker
{},
},
},
&
common
.
StepProvision
{},
}
}
if
b
.
config
.
Commit
{
if
b
.
config
.
Commit
{
...
...
builder/docker/comm.go
0 → 100644
View file @
cab26651
package
docker
import
(
"fmt"
"io/ioutil"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/communicator/ssh"
"github.com/mitchellh/packer/helper/communicator"
gossh
"golang.org/x/crypto/ssh"
)
func
commHost
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
containerId
:=
state
.
Get
(
"container_id"
)
.
(
string
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
return
driver
.
IPAddress
(
containerId
)
}
func
sshConfig
(
comm
*
communicator
.
Config
)
func
(
state
multistep
.
StateBag
)
(
*
gossh
.
ClientConfig
,
error
)
{
return
func
(
state
multistep
.
StateBag
)
(
*
gossh
.
ClientConfig
,
error
)
{
if
comm
.
SSHPrivateKey
!=
""
{
// key based auth
bytes
,
err
:=
ioutil
.
ReadFile
(
comm
.
SSHPrivateKey
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error setting up SSH config: %s"
,
err
)
}
privateKey
:=
string
(
bytes
)
signer
,
err
:=
gossh
.
ParsePrivateKey
([]
byte
(
privateKey
))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error setting up SSH config: %s"
,
err
)
}
return
&
gossh
.
ClientConfig
{
User
:
comm
.
SSHUsername
,
Auth
:
[]
gossh
.
AuthMethod
{
gossh
.
PublicKeys
(
signer
),
},
},
nil
}
else
{
// password based auth
return
&
gossh
.
ClientConfig
{
User
:
comm
.
SSHUsername
,
Auth
:
[]
gossh
.
AuthMethod
{
gossh
.
Password
(
comm
.
SSHPassword
),
gossh
.
KeyboardInteractive
(
ssh
.
PasswordKeyboardInteractive
(
comm
.
SSHPassword
)),
},
},
nil
}
}
}
builder/docker/config.go
View file @
cab26651
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/communicator"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
"github.com/mitchellh/packer/template/interpolate"
...
@@ -13,6 +14,7 @@ import (
...
@@ -13,6 +14,7 @@ import (
type
Config
struct
{
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
common
.
PackerConfig
`mapstructure:",squash"`
Comm
communicator
.
Config
`mapstructure:",squash"`
Commit
bool
Commit
bool
ExportPath
string
`mapstructure:"export_path"`
ExportPath
string
`mapstructure:"export_path"`
...
@@ -69,7 +71,15 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
...
@@ -69,7 +71,15 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
c
.
Pull
=
true
c
.
Pull
=
true
}
}
// Default to the normal Docker type
if
c
.
Comm
.
Type
==
""
{
c
.
Comm
.
Type
=
"docker"
}
var
errs
*
packer
.
MultiError
var
errs
*
packer
.
MultiError
if
es
:=
c
.
Comm
.
Prepare
(
&
c
.
ctx
);
len
(
es
)
>
0
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
es
...
)
}
if
c
.
Image
==
""
{
if
c
.
Image
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"image must be specified"
))
fmt
.
Errorf
(
"image must be specified"
))
...
...
builder/docker/driver.go
View file @
cab26651
...
@@ -22,6 +22,10 @@ type Driver interface {
...
@@ -22,6 +22,10 @@ type Driver interface {
// Import imports a container from a tar file
// Import imports a container from a tar file
Import
(
path
,
repo
string
)
(
string
,
error
)
Import
(
path
,
repo
string
)
(
string
,
error
)
// IPAddress returns the address of the container that can be used
// for external access.
IPAddress
(
id
string
)
(
string
,
error
)
// Login. This will lock the driver from performing another Login
// Login. This will lock the driver from performing another Login
// until Logout is called. Therefore, any users MUST call Logout.
// until Logout is called. Therefore, any users MUST call Logout.
Login
(
repo
,
email
,
username
,
password
string
)
error
Login
(
repo
,
email
,
username
,
password
string
)
error
...
...
builder/docker/driver_docker.go
View file @
cab26651
...
@@ -116,6 +116,23 @@ func (d *DockerDriver) Import(path string, repo string) (string, error) {
...
@@ -116,6 +116,23 @@ func (d *DockerDriver) Import(path string, repo string) (string, error) {
return
strings
.
TrimSpace
(
stdout
.
String
()),
nil
return
strings
.
TrimSpace
(
stdout
.
String
()),
nil
}
}
func
(
d
*
DockerDriver
)
IPAddress
(
id
string
)
(
string
,
error
)
{
var
stderr
,
stdout
bytes
.
Buffer
cmd
:=
exec
.
Command
(
"docker"
,
"inspect"
,
"--format"
,
"{{ .NetworkSettings.IPAddress }}"
,
id
)
cmd
.
Stdout
=
&
stdout
cmd
.
Stderr
=
&
stderr
if
err
:=
cmd
.
Run
();
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Error: %s
\n\n
Stderr: %s"
,
err
,
stderr
.
String
())
}
return
strings
.
TrimSpace
(
stdout
.
String
()),
nil
}
func
(
d
*
DockerDriver
)
Login
(
repo
,
email
,
user
,
pass
string
)
error
{
func
(
d
*
DockerDriver
)
Login
(
repo
,
email
,
user
,
pass
string
)
error
{
d
.
l
.
Lock
()
d
.
l
.
Lock
()
...
...
builder/docker/driver_mock.go
View file @
cab26651
...
@@ -23,6 +23,11 @@ type MockDriver struct {
...
@@ -23,6 +23,11 @@ type MockDriver struct {
ImportId
string
ImportId
string
ImportErr
error
ImportErr
error
IPAddressCalled
bool
IPAddressID
string
IPAddressResult
string
IPAddressErr
error
LoginCalled
bool
LoginCalled
bool
LoginEmail
string
LoginEmail
string
LoginUsername
string
LoginUsername
string
...
@@ -104,6 +109,12 @@ func (d *MockDriver) Import(path, repo string) (string, error) {
...
@@ -104,6 +109,12 @@ func (d *MockDriver) Import(path, repo string) (string, error) {
return
d
.
ImportId
,
d
.
ImportErr
return
d
.
ImportId
,
d
.
ImportErr
}
}
func
(
d
*
MockDriver
)
IPAddress
(
id
string
)
(
string
,
error
)
{
d
.
IPAddressCalled
=
true
d
.
IPAddressID
=
id
return
d
.
IPAddressResult
,
d
.
IPAddressErr
}
func
(
d
*
MockDriver
)
Login
(
r
,
e
,
u
,
p
string
)
error
{
func
(
d
*
MockDriver
)
Login
(
r
,
e
,
u
,
p
string
)
error
{
d
.
LoginCalled
=
true
d
.
LoginCalled
=
true
d
.
LoginRepo
=
r
d
.
LoginRepo
=
r
...
...
builder/docker/step_
provision
.go
→
builder/docker/step_
connect_docker
.go
View file @
cab26651
...
@@ -2,12 +2,11 @@ package docker
...
@@ -2,12 +2,11 @@ package docker
import
(
import
(
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
)
)
type
Step
Provision
struct
{}
type
Step
ConnectDocker
struct
{}
func
(
s
*
Step
Provision
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
func
(
s
*
Step
ConnectDocker
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
containerId
:=
state
.
Get
(
"container_id"
)
.
(
string
)
containerId
:=
state
.
Get
(
"container_id"
)
.
(
string
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
tempDir
:=
state
.
Get
(
"temp_dir"
)
.
(
string
)
tempDir
:=
state
.
Get
(
"temp_dir"
)
.
(
string
)
...
@@ -28,8 +27,8 @@ func (s *StepProvision) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -28,8 +27,8 @@ func (s *StepProvision) Run(state multistep.StateBag) multistep.StepAction {
Version
:
version
,
Version
:
version
,
}
}
prov
:=
common
.
StepProvision
{
Comm
:
comm
}
state
.
Put
(
"communicator"
,
comm
)
return
prov
.
Run
(
state
)
return
multistep
.
ActionContinue
}
}
func
(
s
*
Step
Provision
)
Cleanup
(
state
multistep
.
StateBag
)
{}
func
(
s
*
Step
ConnectDocker
)
Cleanup
(
state
multistep
.
StateBag
)
{}
helper/communicator/step_connect.go
View file @
cab26651
...
@@ -32,6 +32,11 @@ type StepConnect struct {
...
@@ -32,6 +32,11 @@ type StepConnect struct {
// connecting via WinRM.
// connecting via WinRM.
WinRMConfig
func
(
multistep
.
StateBag
)
(
*
WinRMConfig
,
error
)
WinRMConfig
func
(
multistep
.
StateBag
)
(
*
WinRMConfig
,
error
)
// CustomConnect can be set to have custom connectors for specific
// types. These take highest precedence so you can also override
// existing types.
CustomConnect
map
[
string
]
multistep
.
Step
substep
multistep
.
Step
substep
multistep
.
Step
}
}
...
@@ -50,6 +55,9 @@ func (s *StepConnect) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -50,6 +55,9 @@ func (s *StepConnect) Run(state multistep.StateBag) multistep.StepAction {
WinRMConfig
:
s
.
WinRMConfig
,
WinRMConfig
:
s
.
WinRMConfig
,
},
},
}
}
for
k
,
v
:=
range
s
.
CustomConnect
{
typeMap
[
k
]
=
v
}
step
,
ok
:=
typeMap
[
s
.
Config
.
Type
]
step
,
ok
:=
typeMap
[
s
.
Config
.
Type
]
if
!
ok
{
if
!
ok
{
...
...
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