2023-06-01 07:35:18 +00:00
|
|
|
|
using DistTestCore.Marketplace;
|
2023-04-14 08:51:35 +00:00
|
|
|
|
using KubernetesWorkflow;
|
2023-07-04 14:04:18 +00:00
|
|
|
|
using System.Net.Sockets;
|
2023-04-12 11:53:55 +00:00
|
|
|
|
|
|
|
|
|
namespace DistTestCore.Codex
|
|
|
|
|
{
|
|
|
|
|
public class CodexContainerRecipe : ContainerRecipeFactory
|
|
|
|
|
{
|
2023-06-04 06:59:51 +00:00
|
|
|
|
#if Arm64
|
2023-07-04 14:04:18 +00:00
|
|
|
|
public const string DockerImage = "codexstorage/nim-codex:sha-f053135";
|
2023-06-04 06:59:51 +00:00
|
|
|
|
#else
|
2023-07-04 14:04:18 +00:00
|
|
|
|
//public const string DockerImage = "thatbenbierens/nim-codex:dhting";
|
|
|
|
|
public const string DockerImage = "codexstorage/nim-codex:sha-f053135";
|
2023-06-04 06:59:51 +00:00
|
|
|
|
#endif
|
2023-04-13 12:36:17 +00:00
|
|
|
|
public const string MetricsPortTag = "metrics_port";
|
2023-05-29 06:35:46 +00:00
|
|
|
|
public const string DiscoveryPortTag = "discovery-port";
|
2023-04-13 12:36:17 +00:00
|
|
|
|
|
2023-06-07 06:30:10 +00:00
|
|
|
|
// Used by tests for time-constraint assersions.
|
|
|
|
|
public static readonly TimeSpan MaxUploadTimePerMegabyte = TimeSpan.FromSeconds(2.0);
|
|
|
|
|
public static readonly TimeSpan MaxDownloadTimePerMegabyte = TimeSpan.FromSeconds(2.0);
|
|
|
|
|
|
2023-04-14 10:37:05 +00:00
|
|
|
|
protected override string Image => DockerImage;
|
2023-04-12 11:53:55 +00:00
|
|
|
|
|
|
|
|
|
protected override void Initialize(StartupConfig startupConfig)
|
|
|
|
|
{
|
|
|
|
|
var config = startupConfig.Get<CodexStartupConfig>();
|
|
|
|
|
|
2023-07-04 14:04:18 +00:00
|
|
|
|
AddExposedPortAndVar("CODEX_API_PORT");
|
|
|
|
|
AddEnvVar("CODEX_API_BINDADDR", "0.0.0.0");
|
|
|
|
|
|
|
|
|
|
AddEnvVar("CODEX_DATA_DIR", $"datadir{ContainerNumber}");
|
|
|
|
|
AddInternalPortAndVar("CODEX_DISC_PORT", DiscoveryPortTag);
|
|
|
|
|
AddEnvVar("CODEX_LOG_LEVEL", config.LogLevel.ToString()!.ToUpperInvariant());
|
|
|
|
|
|
|
|
|
|
// This makes the node announce itself to its local (pod) IP address.
|
|
|
|
|
AddEnvVar("CODEX_NAT_ADDR", "$(hostname --ip-address)");
|
2023-04-12 11:53:55 +00:00
|
|
|
|
|
|
|
|
|
var listenPort = AddInternalPort();
|
2023-07-04 14:04:18 +00:00
|
|
|
|
AddEnvVar("CODEX_LISTEN_ADDRS", $"/ip4/0.0.0.0/tcp/{listenPort.Number}");
|
2023-04-12 11:53:55 +00:00
|
|
|
|
|
2023-04-24 12:09:23 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(config.BootstrapSpr))
|
|
|
|
|
{
|
2023-07-04 14:04:18 +00:00
|
|
|
|
AddEnvVar("CODEX_BOOTSTRAP_NODE", config.BootstrapSpr);
|
2023-04-24 12:09:23 +00:00
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
if (config.StorageQuota != null)
|
|
|
|
|
{
|
2023-07-04 14:04:18 +00:00
|
|
|
|
AddEnvVar("CODEX_STORAGE_QUOTA", config.StorageQuota.SizeInBytes.ToString()!);
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
2023-06-29 14:03:45 +00:00
|
|
|
|
if (config.BlockTTL != null)
|
|
|
|
|
{
|
|
|
|
|
AddEnvVar("BLOCK_TTL", config.BlockTTL.ToString()!);
|
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
if (config.MetricsEnabled)
|
|
|
|
|
{
|
2023-07-04 14:04:18 +00:00
|
|
|
|
AddEnvVar("CODEX_METRICS", "true");
|
|
|
|
|
AddEnvVar("CODEX_METRICS_ADDRESS", "0.0.0.0");
|
|
|
|
|
AddInternalPortAndVar("CODEX_METRICS_PORT", tag: MetricsPortTag);
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
2023-04-14 08:51:35 +00:00
|
|
|
|
|
|
|
|
|
if (config.MarketplaceConfig != null)
|
|
|
|
|
{
|
|
|
|
|
var gethConfig = startupConfig.Get<GethStartResult>();
|
2023-04-26 09:12:33 +00:00
|
|
|
|
var companionNode = gethConfig.CompanionNode;
|
2023-06-22 12:37:37 +00:00
|
|
|
|
var companionNodeAccount = companionNode.Accounts[GetAccountIndex(config.MarketplaceConfig)];
|
2023-04-26 09:12:33 +00:00
|
|
|
|
Additional(companionNodeAccount);
|
2023-04-14 08:51:35 +00:00
|
|
|
|
|
2023-06-02 08:04:07 +00:00
|
|
|
|
var ip = companionNode.RunningContainer.Pod.PodInfo.Ip;
|
2023-04-21 07:57:52 +00:00
|
|
|
|
var port = companionNode.RunningContainer.Recipe.GetPortByTag(GethContainerRecipe.HttpPortTag).Number;
|
2023-04-14 08:51:35 +00:00
|
|
|
|
|
2023-07-04 14:04:18 +00:00
|
|
|
|
AddEnvVar("CODEX_ETH_PROVIDER", $"ws://{ip}:{port}");
|
|
|
|
|
AddEnvVar("CODEX_ETH_ACCOUNT", companionNodeAccount.Account);
|
|
|
|
|
AddEnvVar("CODEX_MARKETPLACE_ADDRESS", gethConfig.MarketplaceNetwork.Marketplace.Address);
|
|
|
|
|
AddEnvVar("CODEX_PERSISTENCE", "true");
|
2023-06-22 13:58:18 +00:00
|
|
|
|
|
|
|
|
|
if (config.MarketplaceConfig.IsValidator)
|
|
|
|
|
{
|
2023-07-04 14:04:18 +00:00
|
|
|
|
AddEnvVar("CODEX_VALIDATOR", "true");
|
2023-06-22 13:58:18 +00:00
|
|
|
|
}
|
2023-04-14 08:51:35 +00:00
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
2023-06-22 12:37:37 +00:00
|
|
|
|
|
|
|
|
|
private int GetAccountIndex(MarketplaceInitialConfig marketplaceConfig)
|
|
|
|
|
{
|
|
|
|
|
if (marketplaceConfig.AccountIndexOverride != null) return marketplaceConfig.AccountIndexOverride.Value;
|
|
|
|
|
return Index;
|
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|