Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Switch Docker Driver to use the API instead of CLI #4186

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
32 changes: 32 additions & 0 deletions builder/docker/api_reader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package docker

import (
"bufio"
"io"
"strings"

"github.com/mitchellh/packer/packer"
)

func readAndStream(output io.Reader, ui packer.Ui) error {
buf := bufio.NewReader(output)
exitCh := make(chan error)

go func() {
var line string
var err error

for ; err == nil; line, err = buf.ReadString('\n') {
if len(line) != 0 {
ui.Message(strings.TrimSpace(line))
}
}
exitCh <- err
}()

err := <-exitCh
if err == io.EOF {
return nil
}
return err
}
24 changes: 17 additions & 7 deletions builder/docker/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package docker

import (
"log"
"os"

"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
Expand Down Expand Up @@ -30,19 +31,28 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}

func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
driver := &DockerDriver{Ctx: &b.config.ctx, Ui: ui}
if err := driver.Verify(); err != nil {
return nil, err

var driver Driver

if os.Getenv("PACKER_DOCKER_API") != "" {
driver = &DockerApiDriver{Ctx: &b.config.ctx, Config: b.config.DockerHostConfig, Ui: ui}
} else {
driver = &DockerDriver{Ctx: &b.config.ctx, Ui: ui}
}

version, err := driver.Version()
if err != nil {
if err := driver.Verify(); err != nil {
return nil, err
}
log.Printf("[DEBUG] Docker version: %s", version.String())

/*
version, err := driver.Version()
if err != nil {
return nil, err
}
log.Printf("[DEBUG] Docker version: %s", version.String())
*/

steps := []multistep.Step{
&StepTempDir{},
&StepPull{},
&StepRun{},
&communicator.StepConnect{
Expand Down
Loading