2023-06-22 08:17:12 +00:00
|
|
|
|
using DistTestCore;
|
2023-06-22 12:37:37 +00:00
|
|
|
|
using DistTestCore.Codex;
|
|
|
|
|
using DistTestCore.Marketplace;
|
|
|
|
|
using KubernetesWorkflow;
|
|
|
|
|
using System.ComponentModel;
|
2023-06-22 08:17:12 +00:00
|
|
|
|
|
|
|
|
|
namespace CodexNetDeployer
|
|
|
|
|
{
|
|
|
|
|
public class Deployer
|
|
|
|
|
{
|
|
|
|
|
private readonly Configuration config;
|
2023-06-22 12:37:37 +00:00
|
|
|
|
private readonly NullLog log;
|
|
|
|
|
private readonly DefaultTimeSet timeset;
|
2023-06-22 08:17:12 +00:00
|
|
|
|
|
|
|
|
|
public Deployer(Configuration config)
|
|
|
|
|
{
|
|
|
|
|
this.config = config;
|
2023-06-22 12:37:37 +00:00
|
|
|
|
log = new NullLog();
|
|
|
|
|
timeset = new DefaultTimeSet();
|
2023-06-22 08:17:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Deploy()
|
2023-06-22 08:33:21 +00:00
|
|
|
|
{
|
|
|
|
|
Log("Initializing...");
|
2023-06-22 12:37:37 +00:00
|
|
|
|
var (workflowCreator, lifecycle) = CreateFacilities();
|
2023-06-22 08:33:21 +00:00
|
|
|
|
|
|
|
|
|
Log("Preparing configuration...");
|
2023-06-22 12:37:37 +00:00
|
|
|
|
// We trick the Geth companion node into unlocking all of its accounts, by saying we want to start 999 codex nodes.
|
|
|
|
|
var setup = new CodexSetup(999, config.CodexLogLevel);
|
|
|
|
|
setup.WithStorageQuota(config.StorageQuota!.Value.MB()).EnableMarketplace(0.TestTokens());
|
2023-06-22 08:33:21 +00:00
|
|
|
|
|
2023-06-22 12:37:37 +00:00
|
|
|
|
Log("Creating Geth instance and deploying contracts...");
|
|
|
|
|
var gethStarter = new GethStarter(lifecycle, workflowCreator);
|
|
|
|
|
var gethResults = gethStarter.BringOnlineMarketplaceFor(setup);
|
2023-06-22 08:33:21 +00:00
|
|
|
|
|
2023-06-22 12:37:37 +00:00
|
|
|
|
Log("Geth started. Codex contracts deployed.");
|
|
|
|
|
|
|
|
|
|
Log("Starting Codex nodes...");
|
|
|
|
|
|
|
|
|
|
// Each node must have its own IP, so it needs it own pod. Start them 1 at a time.
|
|
|
|
|
var bootstrapSpr = ""; // The first one will be used to bootstrap the others.
|
2023-06-22 13:58:18 +00:00
|
|
|
|
int validatorsLeft = config.NumberOfValidators!.Value;
|
2023-06-22 12:37:37 +00:00
|
|
|
|
for (var i = 0; i < config.NumberOfCodexNodes; i++)
|
2023-06-22 08:33:21 +00:00
|
|
|
|
{
|
2023-06-22 12:37:37 +00:00
|
|
|
|
Console.Write($" - {i} = ");
|
|
|
|
|
var workflow = workflowCreator.CreateWorkflow();
|
|
|
|
|
var workflowStartup = new StartupConfig();
|
|
|
|
|
var codexStart = new CodexStartupConfig(config.CodexLogLevel);
|
|
|
|
|
if (!string.IsNullOrEmpty(bootstrapSpr)) codexStart.BootstrapSpr = bootstrapSpr;
|
|
|
|
|
codexStart.StorageQuota = config.StorageQuota.Value.MB();
|
2023-06-22 13:58:18 +00:00
|
|
|
|
var marketplaceConfig = new MarketplaceInitialConfig(100000.Eth(), 0.TestTokens(), validatorsLeft > 0);
|
2023-06-22 12:37:37 +00:00
|
|
|
|
marketplaceConfig.AccountIndexOverride = i;
|
|
|
|
|
codexStart.MarketplaceConfig = marketplaceConfig;
|
|
|
|
|
workflowStartup.Add(gethResults);
|
|
|
|
|
|
|
|
|
|
var containers = workflow.Start(1, Location.Unspecified, new CodexContainerRecipe(), workflowStartup);
|
|
|
|
|
|
|
|
|
|
var container = containers.Containers.First();
|
|
|
|
|
var address = lifecycle.Configuration.GetAddress(container);
|
|
|
|
|
var codexNode = new CodexNode(log, timeset, address);
|
|
|
|
|
var debugInfo = codexNode.GetDebugInfo();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(debugInfo.spr))
|
|
|
|
|
{
|
|
|
|
|
var pod = container.Pod.PodInfo;
|
|
|
|
|
Console.Write($"Online ({pod.Name} at {pod.Ip} on '{pod.K8SNodeName}'" + Environment.NewLine);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(bootstrapSpr)) bootstrapSpr = debugInfo.spr;
|
2023-06-22 13:58:18 +00:00
|
|
|
|
validatorsLeft--;
|
2023-06-22 12:37:37 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.Write("Unknown failure." + Environment.NewLine);
|
|
|
|
|
}
|
2023-06-22 08:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 12:37:37 +00:00
|
|
|
|
private (WorkflowCreator, TestLifecycle) CreateFacilities()
|
2023-06-22 08:17:12 +00:00
|
|
|
|
{
|
|
|
|
|
var lifecycleConfig = new DistTestCore.Configuration
|
|
|
|
|
(
|
2023-06-22 12:37:37 +00:00
|
|
|
|
kubeConfigFile: null, //config.KubeConfigFile,
|
2023-06-22 08:17:12 +00:00
|
|
|
|
logPath: "null",
|
|
|
|
|
logDebug: false,
|
|
|
|
|
dataFilesPath: "notUsed",
|
2023-06-22 08:33:21 +00:00
|
|
|
|
codexLogLevel: config.CodexLogLevel,
|
2023-06-22 08:17:12 +00:00
|
|
|
|
runnerLocation: config.RunnerLocation
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
var kubeConfig = new KubernetesWorkflow.Configuration(
|
|
|
|
|
k8sNamespacePrefix: config.KubeNamespace,
|
2023-06-22 12:37:37 +00:00
|
|
|
|
kubeConfigFile: null, // config.KubeConfigFile,
|
2023-06-22 08:17:12 +00:00
|
|
|
|
operationTimeout: timeset.K8sOperationTimeout(),
|
|
|
|
|
retryDelay: timeset.WaitForK8sServiceDelay());
|
|
|
|
|
|
2023-06-22 12:37:37 +00:00
|
|
|
|
var workflowCreator = new WorkflowCreator(log, kubeConfig);
|
|
|
|
|
var lifecycle = new TestLifecycle(log, lifecycleConfig, timeset, workflowCreator);
|
|
|
|
|
|
|
|
|
|
return (workflowCreator, lifecycle);
|
2023-06-22 08:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Log(string msg)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(msg);
|
2023-06-22 08:17:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|