Skip to content

Commit

Permalink
wrap setup container method
Browse files Browse the repository at this point in the history
  • Loading branch information
drish committed Dec 10, 2017
1 parent 8ebf279 commit 555c274
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions builder.go
Expand Up @@ -6,8 +6,10 @@ import (
"errors"
"fmt"
"io"
"os"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
)

Expand Down Expand Up @@ -48,6 +50,8 @@ func (l *LocalBuilder) PullImage() error {
rd := bufio.NewReader(out)

for {
// TODO: not read lines
// not read lines, add spinner til done
str, _, err := rd.ReadLine()
if err != nil {
if err == io.EOF {
Expand All @@ -63,6 +67,37 @@ func (l *LocalBuilder) PullImage() error {
// SetupContainer creates the container locally
func (l *LocalBuilder) SetupContainer() error {
fmt.Println("Setting up container for:", l.Image)

cli, err := client.NewEnvClient()

if err != nil {
return errors.New("failed to connect to local docker")
}

config := &container.Config{
Image: l.Image,
Volumes: map[string]struct{}{
"/tmp": {},
},
OpenStdin: true,
}

bindPath, err := os.Getwd()
if err != nil {
return errors.New("failed to get current directory")
}

hostConfig := &container.HostConfig{
Binds: []string{bindPath + ":/tmp"},
}

c, err := cli.ContainerCreate(context.Background(), config, hostConfig, nil, "namerino")

if err != nil {
return errors.New("failed creating container")
}

fmt.Println("Created container: ", c.ID)
return nil
}

Expand Down

0 comments on commit 555c274

Please sign in to comment.