Skip to content

Commit ef8178e

Browse files
Docker upgrades (#48)
* rebased * made Lighthouse more flexible in terms of its external Docker support.
1 parent 5feba7c commit ef8178e

5 files changed

+52
-12
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* -crlf

build-docker.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
if [ -z ${1} ]; then
4+
# no version number passed in, get last release tag from github
5+
release_tag=`git describe --tags $(git rev-list --tags --max-count=1)`
6+
else
7+
# can pass a target release tag e.g. bash docker-build.sh v1.0.2
8+
# must include the "v" at the front of the version number e.g. "v1.0.2" NOT "1.0.2"
9+
release_tag=$1
10+
fi
11+
12+
docker build -t petabridge/lighthouse:netcore1.1 -t petabridge/lighthouse:${release_tag} -t petabridge/lighthouse:latest .

src/Lighthouse/LighthouseHostFactory.cs

+30-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ public static class LighthouseHostFactory
1414
{
1515
public static ActorSystem LaunchLighthouse(string ipAddress = null, int? specifiedPort = null, string systemName = null)
1616
{
17+
systemName = systemName ?? Environment.GetEnvironmentVariable("ACTORSYSTEM")?.Trim();
18+
ipAddress = ipAddress ?? Environment.GetEnvironmentVariable("CLUSTER_IP")?.Trim();
19+
if (specifiedPort == null)
20+
{
21+
var envPort = Environment.GetEnvironmentVariable("CLUSTER_PORT")?.Trim();
22+
if (!string.IsNullOrEmpty(envPort) && int.TryParse(envPort, out var actualPort))
23+
{
24+
specifiedPort = actualPort;
25+
}
26+
}
27+
1728
var clusterConfig = ConfigurationFactory.ParseString(File.ReadAllText("akka.hocon"));
1829

1930
var lighthouseConfig = clusterConfig.GetConfig("lighthouse");
@@ -23,9 +34,13 @@ public static ActorSystem LaunchLighthouse(string ipAddress = null, int? specifi
2334
}
2435

2536
var remoteConfig = clusterConfig.GetConfig("akka.remote");
26-
ipAddress = ipAddress ??
27-
remoteConfig.GetString("dot-netty.tcp.public-hostname") ??
28-
"127.0.0.1"; //localhost as a final default
37+
38+
if (string.IsNullOrEmpty(ipAddress))
39+
{
40+
ipAddress = remoteConfig.GetString("dot-netty.tcp.public-hostname") ??
41+
"127.0.0.1"; //localhost as a final default
42+
}
43+
2944
int port = specifiedPort ?? remoteConfig.GetInt("dot-netty.tcp.port");
3045

3146
if (port == 0) throw new ConfigurationException("Need to specify an explicit port for Lighthouse. Found an undefined port or a port value of 0 in App.config.");
@@ -40,7 +55,19 @@ public static ActorSystem LaunchLighthouse(string ipAddress = null, int? specifi
4055
selfAddress = new Address("akka.tcp", systemName, ipAddress.Trim(), port).ToString();
4156
Console.WriteLine("[Lighthouse] Parse successful.");
4257

58+
var clusterSeeds = Environment.GetEnvironmentVariable("CLUSTER_SEEDS")?.Trim();
59+
4360
var seeds = clusterConfig.GetStringList("akka.cluster.seed-nodes");
61+
if (!string.IsNullOrEmpty(clusterSeeds))
62+
{
63+
var tempSeeds = clusterSeeds.Trim('[', ']').Split(',');
64+
if (tempSeeds.Any())
65+
{
66+
seeds = tempSeeds;
67+
}
68+
}
69+
70+
4471
if (!seeds.Contains(selfAddress))
4572
{
4673
seeds.Add(selfAddress);

src/Lighthouse/LighthouseService.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ public class LighthouseService
2828

2929
private ActorSystem _lighthouseSystem;
3030

31-
/*
32-
* var ipAddress = ;
33-
var actorSystemName = Environment.GetEnvironmentVariable("actorSystemName");
34-
*/
35-
36-
public LighthouseService() : this(Environment.GetEnvironmentVariable("CONTAINER_IP"), null, Environment.GetEnvironmentVariable("ACTORSYSTEM")) { }
31+
public LighthouseService() : this(null, null, null) { }
3732

3833
public LighthouseService(string ipAddress, int? port, string actorSystemName)
3934
{

src/Lighthouse/get-dockerip.sh

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/bin/sh
2-
host=$(hostname -i)
3-
echo "Docker container bound on $host"
4-
export CONTAINER_IP="$host"
2+
3+
if [ -z "$CLUSTER_IP"]; then
4+
host=$(hostname -i)
5+
echo "Docker container bound on $host"
6+
export CLUSTER_IP="$host"
7+
else
8+
echo "Docker container bound on $CLUSTER_IP"
9+
fi
510

611
exec "$@"

0 commit comments

Comments
 (0)