Skip to content

Commit

Permalink
Add docker configuration #15 (#16)
Browse files Browse the repository at this point in the history
- Add docker setup for testnet and main.
- Add instructions on starting multiple instances.
- Todo: Create a .bat file that launch everything with a single command, including docker build.
  • Loading branch information
sondreb authored Jul 30, 2018
1 parent 9352497 commit c65a85f
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 23 deletions.
15 changes: 15 additions & 0 deletions Docker/City.Chain.TestNet/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM microsoft/dotnet:2.1-sdk

RUN git clone https://github.com/CityChainFoundation/city-chain.git \
&& cd /city-chain/src/City.Chain \
&& dotnet build

VOLUME /root/.citychain

WORKDIR /city-chain/src/City.Chain

COPY city.conf.docker /root/.citychain/city/CityTest/city.conf

EXPOSE 24333 24334 24335 24336

CMD ["dotnet", "run", "-testnet"]
4 changes: 4 additions & 0 deletions Docker/City.Chain.TestNet/city.conf.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
server=1
rpcbind=127.0.0.1
rpcallowip=127.0.0.1
testnet=1
15 changes: 15 additions & 0 deletions Docker/City.Chain/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM microsoft/dotnet:2.1-sdk

RUN git clone https://github.com/CityChainFoundation/city-chain.git \
&& cd /city-chain/src/City.Chain \
&& dotnet build

VOLUME /root/.citychain

WORKDIR /city-chain/src/City.Chain

COPY city.conf.docker /root/.citychain/city/CityMain/city.conf

EXPOSE 4333 4334 4335 4336

CMD ["dotnet", "run"]
3 changes: 3 additions & 0 deletions Docker/City.Chain/city.conf.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
server=1
rpcbind=127.0.0.1
rpcallowip=127.0.0.1
21 changes: 21 additions & 0 deletions Docker/DOCKER-CITYCHAIN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# City Chain: Docker Setup

Please first refer to the [README.md](README.md) for introduction to the Docker setup, then use this
file for additional setup.

## Run multiple instances as daemons

docker run -d IMAGE
docker run -d IMAGE

## List running instances

docker ps

## Run a full local network with port forward:

docker run -d -p 24333:24333 -p 24334:24334 -p 24335:24335 -p 24336:24336 IMAGE
docker run -d -p 25333:24333 -p 25334:24334 -p 25335:24335 -p 25336:24336 IMAGE
docker run -d -p 26333:24333 -p 26334:24334 -p 26335:24335 -p 26336:24336 IMAGE
docker run -d -p 27333:24333 -p 27334:24334 -p 27335:24335 -p 27336:24336 IMAGE

1 change: 1 addition & 0 deletions src/City.Chain.DNS/City.Chain.DNS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\City\City.csproj" />
<ProjectReference Include="..\NBitcoin\NBitcoin.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.Api\Stratis.Bitcoin.Features.Api.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.BlockStore\Stratis.Bitcoin.Features.BlockStore.csproj" />
Expand Down
8 changes: 7 additions & 1 deletion src/City.Chain.sln
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "City.Chain", "City.Chain\Ci
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "City.Chain.DNS", "City.Chain.DNS\City.Chain.DNS.csproj", "{823DFC41-BE0F-43E0-91EE-3675BF3D1348}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "City.Chain.Tests", "City.Chain.Tests\City.Chain.Tests.csproj", "{575C08F7-C789-4604-AB76-A53D329AF236}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "City.Chain.Tests", "City.Chain.Tests\City.Chain.Tests.csproj", "{575C08F7-C789-4604-AB76-A53D329AF236}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "City", "City\City.csproj", "{FB0B01EE-0190-431B-B9E0-3E6653928BFB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -363,6 +365,10 @@ Global
{575C08F7-C789-4604-AB76-A53D329AF236}.Debug|Any CPU.Build.0 = Debug|Any CPU
{575C08F7-C789-4604-AB76-A53D329AF236}.Release|Any CPU.ActiveCfg = Release|Any CPU
{575C08F7-C789-4604-AB76-A53D329AF236}.Release|Any CPU.Build.0 = Release|Any CPU
{FB0B01EE-0190-431B-B9E0-3E6653928BFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB0B01EE-0190-431B-B9E0-3E6653928BFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB0B01EE-0190-431B-B9E0-3E6653928BFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB0B01EE-0190-431B-B9E0-3E6653928BFB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions src/City.Chain/City.Chain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<ItemGroup>
<ProjectReference Include="..\City.Chain.Features.SimpleWallet\City.Chain.Features.SimpleWallet.csproj" />
<ProjectReference Include="..\City\City.csproj" />
<ProjectReference Include="..\NBitcoin\NBitcoin.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.Api\Stratis.Bitcoin.Features.Api.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.Apps\Stratis.Bitcoin.Features.Apps.csproj" />
Expand Down
52 changes: 34 additions & 18 deletions src/City.Chain/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static void GenerateAddressKeyPair(Network network)
}

/// <summary>
/// City.Chain daemon can be launched with options to specify coin and network, using the parameters -coin and -network. It defaults to City main network.
/// City.Chain daemon can be launched with options to specify coin and network, using the parameters -chain and -testnet. It defaults to City main network.
/// </summary>
/// <example>
/// dotnet city.chain.dll -coin bitcoin -network regtest
Expand All @@ -50,25 +50,41 @@ public static async Task Main(string[] args)
{
try
{
var coinIndex = Array.IndexOf(args, "-coin");
var coinValue = (coinIndex > -1) ? args[coinIndex + 1] : "city";
// To avoid modifying Stratis source, we'll parse the arguments and set some hard-coded defaults for City Chain, like the ports.
var configReader = new TextFileConfiguration(args ?? new string[] { });

var networkIdentifier = "main";

var networkIndex = Array.IndexOf(args, "-network");
var networkValue = (networkIndex > -1) ? args[networkIndex + 1] : "";
if (configReader.GetOrDefault<bool>("testnet", false))
{
networkIdentifier = "testnet";
}
else if (configReader.GetOrDefault<bool>("regtest", false))
{
networkIdentifier = "regtest";
}

var network = GetNetwork(coinValue, networkValue);
// City Chain daemon supports multiple networks, supply the chain parameter to change it.
// Example: -chain=bitcoin
var chain = configReader.GetOrDefault<string>("chain", "city");

if (network == null)
var networkConfiguration = new NetworkConfigurations().GetNetwork(networkIdentifier, chain);

if (networkConfiguration == null)
{
throw new ArgumentNullException($"The supplied coin ({coinValue}) and network ({networkValue}) parameters did not result in a valid network.");
throw new ArgumentException($"The supplied chain ({chain}) and network ({networkIdentifier}) parameters did not result in a valid network.");
}

var network = GetNetwork(networkConfiguration.Identifier, networkConfiguration.Chain);

if (args.Contains("-generate"))
{
GenerateAddressKeyPair(network);
return;
}

args = args.Append("-apiport=" + networkConfiguration.ApiPort).Append("-wsport=" + networkConfiguration.WsPort).ToArray();

var nodeSettings = new NodeSettings(
args: args,
protocolVersion: ProtocolVersion.ALT_PROTOCOL_VERSION,
Expand Down Expand Up @@ -99,15 +115,15 @@ public static async Task Main(string[] args)
}
}

public static Network GetNetwork(string coin, string network)
public static Network GetNetwork(string network, string chain)
{
if (coin == "city")
if (chain == "city")
{
if (network == "")
if (network == "main")
{
return Networks.CityMain;
}
else if (network == "test")
else if (network == "testnet")
{
return Networks.CityTest;
}
Expand All @@ -116,13 +132,13 @@ public static Network GetNetwork(string coin, string network)
return Networks.CityRegTest;
}
}
else if (coin == "bitcoin")
else if (chain == "bitcoin")
{
if (network == "")
if (network == "main")
{
return Networks.Main;
}
else if (network == "test")
else if (network == "testnet")
{
return Networks.TestNet;
}
Expand All @@ -131,13 +147,13 @@ public static Network GetNetwork(string coin, string network)
return Networks.RegTest;
}
}
else if (coin == "stratis")
else if (chain == "stratis")
{
if (network == "")
if (network == "main")
{
return Networks.StratisMain;
}
else if (network == "test")
else if (network == "testnet")
{
return Networks.StratisTest;
}
Expand Down
7 changes: 7 additions & 0 deletions src/City/City.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

</Project>
80 changes: 80 additions & 0 deletions src/City/NetworkConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace City
{
public class NetworkConfiguration
{
public string Identifier { get; set; }

public string Chain { get; set; }

public string Name { get; set; }

public int Port { get; set; }

public int RpcPort { get; set; }

public int ApiPort { get; set; }

public int WsPort { get; set; }

}

public class NetworkConfigurations
{
private NetworkConfiguration[] networks;

public NetworkConfigurations()
{
networks = new NetworkConfiguration[] {

new NetworkConfiguration() {
Identifier = "main",
Chain = "city",
Name = "City Main",
Port = 4333,
RpcPort = 4334,
ApiPort = 4335,
WsPort = 4336
},


new NetworkConfiguration() {
Identifier = "regtest",
Chain = "city",
Name = "City RegTest",
Port = 14333,
RpcPort = 14334,
ApiPort = 14335,
WsPort = 14336
},

new NetworkConfiguration() {
Identifier = "testnet",
Chain = "city",
Name = "City Test",
Port = 24333 ,
RpcPort = 24334,
ApiPort = 24335,
WsPort = 24336
},


};

}

public NetworkConfiguration[] GetNetworks()
{
return this.networks;
}

public NetworkConfiguration GetNetwork(string identifier, string chain)
{
return this.networks.FirstOrDefault(n => n.Identifier == identifier && n.Chain == chain);
}
}
}
8 changes: 4 additions & 4 deletions src/NBitcoin/NetworkDefinitions/CityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public CityTest()
};

string[] seedNodes = {
"10.0.0.122", // city-chain.org (node3)
"10.0.0.192", // citychain.foundation (node3)
"10.0.0.122", // City 1 Node #1
"10.0.0.192" // City 2 Node #1
"10.0.0.192:24333", // city-chain.org (node3)
"10.0.0.192:25333", // citychain.foundation (node3)
"10.0.0.192:26333", // City 1 Node #1
"10.0.0.192:27333" // City 2 Node #1
// As more cities are included in the City Chain, consider adding their official nodes to the seeds.
};
this.SeedNodes = ConvertToNetworkAddresses(seedNodes, this.DefaultPort).ToList();
Expand Down

0 comments on commit c65a85f

Please sign in to comment.