Skip to content

Commit

Permalink
config.json can have an instances setting to start several nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Ban committed Apr 16, 2022
1 parent b3d6936 commit 3f73d91
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (d *Docker) Run(ctx context.Context, image, imageurl string, labels map[str
}

hostconfig := &container.HostConfig{
RestartPolicy: container.RestartPolicy{MaximumRetryCount: 0},
RestartPolicy: container.RestartPolicy{Name: "always"},
Mounts: mm,
}

Expand Down Expand Up @@ -202,7 +202,7 @@ func (d *Docker) Run(ctx context.Context, image, imageurl string, labels map[str
&cfg,
hostconfig,
nc,
imagename+"_"+strconv.FormatInt(time.Now().UTC().Unix(), 32))
imagename+"_"+strconv.FormatInt(time.Now().UTC().UnixNano(), 32))
E(err)
err = d.cli.ContainerStart(ctx, cont.ID, types.ContainerStartOptions{})
E(err)
Expand Down
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"os"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -108,7 +109,16 @@ func main() {
name, err := d.BuildDockerImage(ctx, conf)
E(err)

d.Run(ctx, name, "", labelconf, dockerconf)
ii := 1
if conf["instances"] != "" {
ii, err = strconv.Atoi(conf["instances"])
if err != nil {
log.Printf("instances must be an integer, defaulting to 1")
}
}
for i := 0; i < ii; i++ {
d.Run(ctx, name, "", labelconf, dockerconf)
}

time.Sleep(2 * time.Second)

Expand Down

0 comments on commit 3f73d91

Please sign in to comment.