builder/docker: driver supports login/logout

This commit is contained in:
Mitchell Hashimoto 2014-09-05 14:26:19 -07:00
parent 5db91c84bf
commit d32b4b4f84
3 changed files with 61 additions and 0 deletions

View File

@ -20,6 +20,12 @@ type Driver interface {
// Import imports a container from a tar file
Import(path, repo string) (string, error)
// Login
Login(repo, email, username, password string) error
// Logout
Logout(repo string) error
// Pull should pull down the given image.
Pull(image string) error

View File

@ -109,6 +109,35 @@ func (d *DockerDriver) Import(path string, repo string) (string, error) {
return strings.TrimSpace(stdout.String()), nil
}
func (d *DockerDriver) Login(repo, email, user, pass string) error {
args := []string{"login"}
if email != "" {
args = append(args, "-e", email)
}
if user != "" {
args = append(args, "-u", user)
}
if pass != "" {
args = append(args, "-p", pass)
}
if repo != "" {
args = append(args, repo)
}
cmd := exec.Command("docker", args...)
return runAndStream(cmd, d.Ui)
}
func (d *DockerDriver) Logout(repo string) error {
args := []string{"logout"}
if repo != "" {
args = append(args, repo)
}
cmd := exec.Command("docker", args...)
return runAndStream(cmd, d.Ui)
}
func (d *DockerDriver) Pull(image string) error {
cmd := exec.Command("docker", "pull", image)
return runAndStream(cmd, d.Ui)

View File

@ -21,6 +21,17 @@ type MockDriver struct {
ImportId string
ImportErr error
LoginCalled bool
LoginEmail string
LoginUsername string
LoginPassword string
LoginRepo string
LoginErr error
LogoutCalled bool
LogoutRepo string
LogoutErr error
PushCalled bool
PushName string
PushErr error
@ -87,6 +98,21 @@ func (d *MockDriver) Import(path, repo string) (string, error) {
return d.ImportId, d.ImportErr
}
func (d *MockDriver) Login(r, e, u, p string) error {
d.LoginCalled = true
d.LoginRepo = r
d.LoginEmail = e
d.LoginUsername = u
d.LoginPassword = p
return d.LoginErr
}
func (d *MockDriver) Logout(r string) error {
d.LogoutCalled = true
d.LogoutRepo = r
return d.LogoutErr
}
func (d *MockDriver) Pull(image string) error {
d.PullCalled = true
d.PullImage = image