cs-codex-dist-tests/DistTestCore/Codex/CodexContainerRecipe.cs

78 lines
3.1 KiB
C#
Raw Normal View History

using DistTestCore.Marketplace;
2023-04-14 08:51:35 +00:00
using KubernetesWorkflow;
2023-04-12 11:53:55 +00:00
namespace DistTestCore.Codex
{
public class CodexContainerRecipe : ContainerRecipeFactory
{
#if Arm64
public const string DockerImage = "codexstorage/nim-codex:sha-7b88ea0";
#else
public const string DockerImage = "thatbenbierens/nim-codex:dhting";
//public const string DockerImage = "codexstorage/nim-codex:sha-7b88ea0";
#endif
2023-04-13 12:36:17 +00:00
public const string MetricsPortTag = "metrics_port";
public const string DiscoveryPortTag = "discovery-port";
2023-04-13 12:36:17 +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>();
AddExposedPortAndVar("API_PORT");
AddEnvVar("DATA_DIR", $"datadir{ContainerNumber}");
AddInternalPortAndVar("DISC_PORT", DiscoveryPortTag);
AddEnvVar("LOG_LEVEL", config.LogLevel.ToString()!.ToUpperInvariant());
2023-04-12 11:53:55 +00:00
var listenPort = AddInternalPort();
AddEnvVar("LISTEN_ADDRS", $"/ip4/0.0.0.0/tcp/{listenPort.Number}");
if (!string.IsNullOrEmpty(config.BootstrapSpr))
{
AddEnvVar("BOOTSTRAP_SPR", config.BootstrapSpr);
}
2023-04-12 11:53:55 +00:00
if (config.StorageQuota != null)
{
AddEnvVar("STORAGE_QUOTA", config.StorageQuota.SizeInBytes.ToString()!);
}
if (config.MetricsEnabled)
{
AddEnvVar("METRICS_ADDR", "0.0.0.0");
2023-04-13 12:36:17 +00:00
AddInternalPortAndVar("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>();
var companionNode = gethConfig.CompanionNode;
2023-06-22 12:37:37 +00:00
var companionNodeAccount = companionNode.Accounts[GetAccountIndex(config.MarketplaceConfig)];
Additional(companionNodeAccount);
2023-04-14 08:51:35 +00:00
var ip = companionNode.RunningContainer.Pod.PodInfo.Ip;
var port = companionNode.RunningContainer.Recipe.GetPortByTag(GethContainerRecipe.HttpPortTag).Number;
2023-04-14 08:51:35 +00:00
2023-04-18 11:45:48 +00:00
AddEnvVar("ETH_PROVIDER", $"ws://{ip}:{port}");
AddEnvVar("ETH_ACCOUNT", companionNodeAccount.Account);
2023-04-18 11:45:48 +00:00
AddEnvVar("ETH_MARKETPLACE_ADDRESS", gethConfig.MarketplaceNetwork.Marketplace.Address);
AddEnvVar("PERSISTENCE", "1");
2023-06-22 13:58:18 +00:00
if (config.MarketplaceConfig.IsValidator)
{
AddEnvVar("VALIDATOR", "1");
}
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
}
}