Skip to content

Commit

Permalink
Add automatic container restart policy
Browse files Browse the repository at this point in the history
  • Loading branch information
80degreeswest committed Feb 7, 2021
1 parent 165ca45 commit 658937c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.eightydegreeswest</groupId>
<artifactId>bfmgr</artifactId>
<version>1.0.14</version>
<version>1.0.15</version>
<name>bfmgr</name>
<description>Buildfarm Manager</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.HostConfig;
import com.github.dockerjava.api.model.Ports;
import com.github.dockerjava.api.model.RestartPolicy;
import com.github.dockerjava.core.DefaultDockerClientConfig;
import com.github.dockerjava.core.DockerClientBuilder;
import com.github.dockerjava.core.DockerClientConfig;
Expand Down Expand Up @@ -153,7 +154,9 @@ public void createCluster(CreateClusterRequest createClusterRequest) throws IOEx

CreateContainerResponse response = dockerClient.createContainerCmd(redisRepo + ":" + redisTag)
.withName(redisContainer)
.withHostConfig(HostConfig.newHostConfig().withPortBindings(portBindings))
.withHostConfig(HostConfig.newHostConfig()
.withRestartPolicy(RestartPolicy.unlessStoppedRestart())
.withPortBindings(portBindings))
.exec();
dockerClient.startContainerCmd(response.getId()).exec();

Expand All @@ -163,6 +166,7 @@ public void createCluster(CreateClusterRequest createClusterRequest) throws IOEx
response = dockerClient.createContainerCmd(createClusterRequest.getWorkerRepo() + ":" + createClusterRequest.getBuildfarmTag())
.withName(workerContainer)
.withHostConfig(HostConfig.newHostConfig()
.withRestartPolicy(RestartPolicy.unlessStoppedRestart())
.withPortBindings(portBindings)
.withPrivileged(true)
.withBinds(Bind.parse("/tmp/buildfarm:/var/lib/buildfarm-shard-worker"), Bind.parse("/tmp/worker:/tmp/worker"))
Expand All @@ -177,6 +181,7 @@ public void createCluster(CreateClusterRequest createClusterRequest) throws IOEx
response = dockerClient.createContainerCmd(createClusterRequest.getServerRepo() + ":" + createClusterRequest.getBuildfarmTag())
.withName(serverContainer)
.withHostConfig(HostConfig.newHostConfig()
.withRestartPolicy(RestartPolicy.unlessStoppedRestart())
.withPortBindings(portBindings)
.withBinds(Bind.parse("/tmp/buildfarm:/var/lib/buildfarm-server"))
.withNetworkMode("host"))
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/aws.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"Ref":"ServerTag"
},
"\n",
"docker run --name buildfarm-server -p 8980:8980 -v /var/lib/buildfarm-server/server.config:/var/lib/buildfarm-server/server.config ",
"docker run --restart unless-stopped --name buildfarm-server -p 8980:8980 -v /var/lib/buildfarm-server/server.config:/var/lib/buildfarm-server/server.config ",
{
"Ref":"ServerRepo"
},
Expand Down Expand Up @@ -237,7 +237,7 @@
"Ref":"WorkerTag"
},
"\n",
"docker run -d --name buildfarm-worker --privileged -v /var/lib/buildfarm-shard-worker/worker.config:/var/lib/buildfarm-shard-worker/worker.config -v /tmp/worker:/tmp/worker -p 8981:8981 ",
"docker run -d --restart unless-stopped --name buildfarm-worker --privileged -v /var/lib/buildfarm-shard-worker/worker.config:/var/lib/buildfarm-shard-worker/worker.config -v /tmp/worker:/tmp/worker -p 8981:8981 ",
{
"Ref":"WorkerRepo"
},
Expand Down

0 comments on commit 658937c

Please sign in to comment.