Commit 622b9f45 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/docker: lock around Login

parent e9611dfb
...@@ -20,10 +20,11 @@ type Driver interface { ...@@ -20,10 +20,11 @@ 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)
// Login // Login. This will lock the driver from performing another Login
// until Logout is called. Therefore, any users MUST call Logout.
Login(repo, email, username, password string) error Login(repo, email, username, password string) error
// Logout // Logout. This can only be called if Login succeeded.
Logout(repo string) error Logout(repo string) error
// Pull should pull down the given image. // Pull should pull down the given image.
......
...@@ -3,17 +3,21 @@ package docker ...@@ -3,17 +3,21 @@ package docker
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/mitchellh/packer/packer"
"io" "io"
"log" "log"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"sync"
"github.com/mitchellh/packer/packer"
) )
type DockerDriver struct { type DockerDriver struct {
Ui packer.Ui Ui packer.Ui
Tpl *packer.ConfigTemplate Tpl *packer.ConfigTemplate
l sync.Mutex
} }
func (d *DockerDriver) DeleteImage(id string) error { func (d *DockerDriver) DeleteImage(id string) error {
...@@ -110,6 +114,8 @@ func (d *DockerDriver) Import(path string, repo string) (string, error) { ...@@ -110,6 +114,8 @@ func (d *DockerDriver) Import(path string, repo string) (string, error) {
} }
func (d *DockerDriver) Login(repo, email, user, pass string) error { func (d *DockerDriver) Login(repo, email, user, pass string) error {
d.l.Lock()
args := []string{"login"} args := []string{"login"}
if email != "" { if email != "" {
args = append(args, "-e", email) args = append(args, "-e", email)
...@@ -125,7 +131,12 @@ func (d *DockerDriver) Login(repo, email, user, pass string) error { ...@@ -125,7 +131,12 @@ func (d *DockerDriver) Login(repo, email, user, pass string) error {
} }
cmd := exec.Command("docker", args...) cmd := exec.Command("docker", args...)
return runAndStream(cmd, d.Ui) err := runAndStream(cmd, d.Ui)
if err != nil {
d.l.Unlock()
}
return err
} }
func (d *DockerDriver) Logout(repo string) error { func (d *DockerDriver) Logout(repo string) error {
...@@ -135,7 +146,9 @@ func (d *DockerDriver) Logout(repo string) error { ...@@ -135,7 +146,9 @@ func (d *DockerDriver) Logout(repo string) error {
} }
cmd := exec.Command("docker", args...) cmd := exec.Command("docker", args...)
return runAndStream(cmd, d.Ui) err := runAndStream(cmd, d.Ui)
d.l.Unlock()
return err
} }
func (d *DockerDriver) Pull(image string) error { func (d *DockerDriver) Pull(image string) error {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment