Skip to content

Commit

Permalink
fix something
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Ban committed Mar 3, 2020
1 parent 0378ac5 commit cba24fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# traefiker
39 changes: 24 additions & 15 deletions traefiker.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ func (d *Docker) Run(ctx context.Context, imagename, imageurl string, labels map
}

hostconfig := &container.HostConfig{
NetworkMode: container.NetworkMode(conf["networks"][0]),
RestartPolicy: container.RestartPolicy{MaximumRetryCount: 0},
Mounts: mm,
}

var nc *network.NetworkingConfig

if len(conf["ports"]) > 0 {
//hostBinding := nat.PortBinding{
// HostIP: "0.0.0.0",
Expand All @@ -169,6 +170,18 @@ func (d *Docker) Run(ctx context.Context, imagename, imageurl string, labels map
links = append(links, l2)
}

if len(conf["networks"]) > 0 {
hostconfig.NetworkMode = container.NetworkMode(conf["networks"][0])
nc = &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
conf["networks"][0]: &network.EndpointSettings{
Links: links,
Aliases: []string{imagename},
},
},
}
}

cont, err := d.cli.ContainerCreate(
context.Background(),
&container.Config{
Expand All @@ -177,17 +190,11 @@ func (d *Docker) Run(ctx context.Context, imagename, imageurl string, labels map
Labels: labels,
},
hostconfig,
&network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
conf["networks"][0]: &network.EndpointSettings{
Links: links,
Aliases: []string{imagename},
},
},
},
nc,
imagename+"_"+strconv.FormatInt(time.Now().UTC().Unix(), 32))
E(err)
d.cli.ContainerStart(ctx, cont.ID, types.ContainerStartOptions{})
err = d.cli.ContainerStart(ctx, cont.ID, types.ContainerStartOptions{})
E(err)
return cont.ID
}

Expand Down Expand Up @@ -268,7 +275,7 @@ func poolReadFrom(r io.Reader) (n int64, err error) {

func walkFnClosure(src string, tw *tar.Writer, buf *bytes.Buffer) filepath.WalkFunc {
return func(path string, info os.FileInfo, err error) error {
log.Println("Walking in ", path)
// log.Println("Walking in ", path)
if err != nil {
// todo: maybe we should return nil
return err
Expand Down Expand Up @@ -394,10 +401,12 @@ func BuildDockerImage(ctx context.Context, conf map[string]string, cli APIClient
for scanner.Scan() {
_ = json.Unmarshal(scanner.Bytes(), &imgProg)
log.Println(
"Build",
imgProg.Status,
imgProg.Progress,
imgProg.Stream)
"Build\033[33m",
strings.TrimRight(imgProg.Status, "\n"),
strings.TrimRight(imgProg.Progress, "\n"),
strings.TrimRight(imgProg.Stream, "\n"),
"\033[0m",
)
}
if err := scanner.Err(); err != nil {
fmt.Println(" :unable to log output for image", imageName, err)
Expand Down

0 comments on commit cba24fa

Please sign in to comment.