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

only configure docker autorestart on the main containers #2007

Merged
merged 1 commit into from
Aug 6, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions go/common/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

const _networkName = "node_network"

// volumes is a map from volume name to dir name it will have within the container. If a volume doesn't exist this will create it.
func StartNewContainer(containerName, image string, cmds []string, ports []int, envs, devices, volumes map[string]string) (string, error) {
// StartNewContainer - volumes is a map from volume name to dir name it will have within the container. If a volume doesn't exist this will create it.
func StartNewContainer(containerName, image string, cmds []string, ports []int, envs, devices, volumes map[string]string, autoRestart bool) (string, error) {
ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
Expand Down Expand Up @@ -95,21 +95,27 @@ func StartNewContainer(containerName, image string, cmds []string, ports []int,
"max-file": "3",
}

hc := container.HostConfig{
PortBindings: portBindings,
Mounts: mountVolumes,
Resources: container.Resources{Devices: deviceMapping},
LogConfig: container.LogConfig{Type: "json-file", Config: logOptions},
}

if autoRestart {
hc.RestartPolicy = container.RestartPolicy{Name: "unless-stopped"}
}

// create the container
resp, err := cli.ContainerCreate(ctx, &container.Config{
Image: image,
Entrypoint: cmds,
Tty: false,
ExposedPorts: exposedPorts,
Env: envVars,
},
&container.HostConfig{
PortBindings: portBindings,
Mounts: mountVolumes,
RestartPolicy: container.RestartPolicy{Name: "unless-stopped"},
Resources: container.Resources{Devices: deviceMapping},
LogConfig: container.LogConfig{Type: "json-file", Config: logOptions},
resp, err := cli.ContainerCreate(ctx,
&container.Config{
Image: image,
Entrypoint: cmds,
Tty: false,
ExposedPorts: exposedPorts,
Env: envVars,
},
&hc,
&network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
_networkName: {
Expand Down
6 changes: 3 additions & 3 deletions go/node/docker_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (d *DockerNode) startHost() error {
d.cfg.hostP2PPort,
}

_, err := docker.StartNewContainer(d.cfg.nodeName+"-host", d.cfg.hostImage, cmd, exposedPorts, nil, nil, nil)
_, err := docker.StartNewContainer(d.cfg.nodeName+"-host", d.cfg.hostImage, cmd, exposedPorts, nil, nil, nil, true)

return err
}
Expand Down Expand Up @@ -195,7 +195,7 @@ func (d *DockerNode) startEnclave() error {

// we need the enclave volume to store the db credentials
enclaveVolume := map[string]string{d.cfg.nodeName + "-enclave-volume": _enclaveDataDir}
_, err := docker.StartNewContainer(d.cfg.nodeName+"-enclave", d.cfg.enclaveImage, cmd, exposedPorts, envs, devices, enclaveVolume)
_, err := docker.StartNewContainer(d.cfg.nodeName+"-enclave", d.cfg.enclaveImage, cmd, exposedPorts, envs, devices, enclaveVolume, true)

return err
}
Expand All @@ -222,7 +222,7 @@ func (d *DockerNode) startEdgelessDB() error {
//dbVolume := map[string]string{d.cfg.nodeName + "-db-volume": "/data"}
//_, err := docker.StartNewContainer(d.cfg.nodeName+"-edgelessdb", d.cfg.edgelessDBImage, nil, nil, envs, devices, dbVolume)

_, err := docker.StartNewContainer(d.cfg.nodeName+"-edgelessdb", d.cfg.edgelessDBImage, nil, nil, envs, devices, nil)
_, err := docker.StartNewContainer(d.cfg.nodeName+"-edgelessdb", d.cfg.edgelessDBImage, nil, nil, envs, devices, nil, true)

return err
}
2 changes: 1 addition & 1 deletion testnet/launcher/eth2network/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (n *Eth2Network) Start() error {
// keep a volume of binaries to avoid downloading
volume := map[string]string{"eth2_bin": "/home/obscuro/go-obscuro/integration/.build/eth2_bin/"}

_, err := docker.StartNewContainer("eth2network", "testnetobscuronet.azurecr.io/obscuronet/eth2network:latest", cmds, exposedPorts, nil, nil, volume)
_, err := docker.StartNewContainer("eth2network", "testnetobscuronet.azurecr.io/obscuronet/eth2network:latest", cmds, exposedPorts, nil, nil, volume, false)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion testnet/launcher/faucet/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (n *DockerFaucet) Start() error {
"--serverPort", fmt.Sprintf("%d", n.cfg.faucetPort),
}

_, err := docker.StartNewContainer("faucet", n.cfg.dockerImage, cmds, []int{n.cfg.faucetPort}, nil, nil, nil)
_, err := docker.StartNewContainer("faucet", n.cfg.dockerImage, cmds, []int{n.cfg.faucetPort}, nil, nil, nil, false)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion testnet/launcher/fundsrecovery/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (n *FundsRecovery) Start() error {
`, n.cfg.l1HTTPURL, n.cfg.l1privateKey),
}

containerID, err := docker.StartNewContainer("recover-funds", n.cfg.dockerImage, cmds, nil, envs, nil, nil)
containerID, err := docker.StartNewContainer("recover-funds", n.cfg.dockerImage, cmds, nil, envs, nil, nil, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion testnet/launcher/gateway/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (n *DockerGateway) Start() error {
"--logPath", "sys_out",
}

_, err := docker.StartNewContainer("gateway", n.cfg.dockerImage, cmds, []int{n.cfg.gatewayHTTPPort, n.cfg.gatewayWSPort}, nil, nil, nil)
_, err := docker.StartNewContainer("gateway", n.cfg.dockerImage, cmds, []int{n.cfg.gatewayHTTPPort, n.cfg.gatewayWSPort}, nil, nil, nil, true)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion testnet/launcher/l1contractdeployer/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (n *ContractDeployer) Start() error {
`, n.cfg.l1HTTPURL, n.cfg.privateKey),
}

containerID, err := docker.StartNewContainer("hh-l1-deployer", n.cfg.dockerImage, cmds, ports, envs, nil, nil)
containerID, err := docker.StartNewContainer("hh-l1-deployer", n.cfg.dockerImage, cmds, ports, envs, nil, nil, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion testnet/launcher/l2contractdeployer/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (n *ContractDeployer) Start() error {
`, n.cfg.l1HTTPURL, n.cfg.l1privateKey, n.cfg.l2PrivateKey, n.cfg.hocPKString, n.cfg.pocPKString),
}

containerID, err := docker.StartNewContainer("hh-l2-deployer", n.cfg.dockerImage, cmds, ports, envs, nil, nil)
containerID, err := docker.StartNewContainer("hh-l2-deployer", n.cfg.dockerImage, cmds, ports, envs, nil, nil, false)
if err != nil {
return err
}
Expand Down