2023-09-11 09:59:33 +00:00
|
|
|
|
//using DistTestCore.Marketplace;
|
2023-09-12 11:32:06 +00:00
|
|
|
|
using Core;
|
2023-04-14 08:51:35 +00:00
|
|
|
|
using KubernetesWorkflow;
|
2023-09-08 07:39:56 +00:00
|
|
|
|
using Utils;
|
2023-04-12 11:53:55 +00:00
|
|
|
|
|
2023-09-11 09:59:33 +00:00
|
|
|
|
namespace CodexPlugin
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
2023-09-04 07:08:34 +00:00
|
|
|
|
public class CodexContainerRecipe : DefaultContainerRecipe
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
2023-08-17 09:06:45 +00:00
|
|
|
|
private const string DefaultDockerImage = "codexstorage/nim-codex:latest-dist-tests";
|
2023-07-21 07:34:37 +00:00
|
|
|
|
|
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-09-04 07:08:34 +00:00
|
|
|
|
// Used by tests for time-constraint assertions.
|
2023-06-07 06:30:10 +00:00
|
|
|
|
public static readonly TimeSpan MaxUploadTimePerMegabyte = TimeSpan.FromSeconds(2.0);
|
|
|
|
|
public static readonly TimeSpan MaxDownloadTimePerMegabyte = TimeSpan.FromSeconds(2.0);
|
|
|
|
|
|
2023-08-07 13:51:44 +00:00
|
|
|
|
public override string AppName => "codex";
|
2023-07-17 09:12:14 +00:00
|
|
|
|
public override string Image { get; }
|
2023-09-08 11:47:49 +00:00
|
|
|
|
|
2023-07-17 09:12:14 +00:00
|
|
|
|
public CodexContainerRecipe()
|
2023-07-14 08:18:37 +00:00
|
|
|
|
{
|
2023-07-17 09:12:14 +00:00
|
|
|
|
Image = GetDockerImage();
|
2023-09-08 11:47:49 +00:00
|
|
|
|
|
2023-09-08 16:13:54 +00:00
|
|
|
|
Resources.Requests = new ContainerResourceSet(milliCPUs: 1000, memory: 6.GB());
|
|
|
|
|
Resources.Limits = new ContainerResourceSet(milliCPUs: 4000, memory: 12.GB());
|
2023-07-14 08:18:37 +00:00
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
|
2023-09-04 07:08:34 +00:00
|
|
|
|
protected override void InitializeRecipe(StartupConfig startupConfig)
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
|
|
|
|
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");
|
|
|
|
|
|
2023-09-07 06:19:19 +00:00
|
|
|
|
var dataDir = $"datadir{ContainerNumber}";
|
|
|
|
|
AddEnvVar("CODEX_DATA_DIR", dataDir);
|
2023-09-07 08:37:52 +00:00
|
|
|
|
AddVolume($"codex/{dataDir}", GetVolumeCapacity(config));
|
2023-09-07 06:19:19 +00:00
|
|
|
|
|
2023-07-04 14:04:18 +00:00
|
|
|
|
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.
|
2023-07-13 08:05:40 +00:00
|
|
|
|
AddEnvVar("NAT_IP_AUTO", "true");
|
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)
|
|
|
|
|
{
|
2023-07-14 08:45:26 +00:00
|
|
|
|
AddEnvVar("CODEX_BLOCK_TTL", config.BlockTTL.ToString()!);
|
2023-06-29 14:03:45 +00:00
|
|
|
|
}
|
2023-08-14 13:51:03 +00:00
|
|
|
|
if (config.BlockMaintenanceInterval != null)
|
|
|
|
|
{
|
|
|
|
|
AddEnvVar("CODEX_BLOCK_MI", Convert.ToInt32(config.BlockMaintenanceInterval.Value.TotalSeconds).ToString());
|
|
|
|
|
}
|
2023-08-14 14:37:31 +00:00
|
|
|
|
if (config.BlockMaintenanceNumber != null)
|
|
|
|
|
{
|
|
|
|
|
AddEnvVar("CODEX_BLOCK_MN", config.BlockMaintenanceNumber.ToString()!);
|
|
|
|
|
}
|
2023-09-11 09:59:33 +00:00
|
|
|
|
//if (config.MetricsMode != Metrics.MetricsMode.None)
|
|
|
|
|
//{
|
|
|
|
|
// var metricsPort = AddInternalPort(MetricsPortTag);
|
|
|
|
|
// AddEnvVar("CODEX_METRICS", "true");
|
|
|
|
|
// AddEnvVar("CODEX_METRICS_ADDRESS", "0.0.0.0");
|
|
|
|
|
// AddEnvVar("CODEX_METRICS_PORT", metricsPort);
|
|
|
|
|
// AddPodAnnotation("prometheus.io/scrape", "true");
|
|
|
|
|
// AddPodAnnotation("prometheus.io/port", metricsPort.Number.ToString());
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//if (config.MarketplaceConfig != null)
|
|
|
|
|
//{
|
|
|
|
|
// var gethConfig = startupConfig.Get<GethStartResult>();
|
|
|
|
|
// var companionNode = gethConfig.CompanionNode;
|
|
|
|
|
// var companionNodeAccount = companionNode.Accounts[GetAccountIndex(config.MarketplaceConfig)];
|
|
|
|
|
// Additional(companionNodeAccount);
|
|
|
|
|
|
|
|
|
|
// var ip = companionNode.RunningContainer.Pod.PodInfo.Ip;
|
|
|
|
|
// var port = companionNode.RunningContainer.Recipe.GetPortByTag(GethContainerRecipe.HttpPortTag).Number;
|
|
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
|
|
|
|
|
|
// if (config.MarketplaceConfig.IsValidator)
|
|
|
|
|
// {
|
|
|
|
|
// AddEnvVar("CODEX_VALIDATOR", "true");
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
2023-06-22 12:37:37 +00:00
|
|
|
|
|
2023-09-08 07:39:56 +00:00
|
|
|
|
private ByteSize GetVolumeCapacity(CodexStartupConfig config)
|
2023-09-07 08:37:52 +00:00
|
|
|
|
{
|
2023-09-08 07:39:56 +00:00
|
|
|
|
if (config.StorageQuota != null) return config.StorageQuota;
|
|
|
|
|
// Default Codex quota: 8 Gb, using +20% to be safe.
|
|
|
|
|
return 8.GB().Multiply(1.2);
|
2023-09-07 08:37:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 09:59:33 +00:00
|
|
|
|
//private int GetAccountIndex(MarketplaceInitialConfig marketplaceConfig)
|
|
|
|
|
//{
|
|
|
|
|
// if (marketplaceConfig.AccountIndexOverride != null) return marketplaceConfig.AccountIndexOverride.Value;
|
|
|
|
|
// return Index;
|
|
|
|
|
//}
|
2023-07-17 09:12:14 +00:00
|
|
|
|
|
|
|
|
|
private string GetDockerImage()
|
|
|
|
|
{
|
|
|
|
|
var image = Environment.GetEnvironmentVariable("CODEXDOCKERIMAGE");
|
|
|
|
|
if (!string.IsNullOrEmpty(image)) return image;
|
2023-07-21 07:34:37 +00:00
|
|
|
|
return DefaultDockerImage;
|
2023-07-17 09:12:14 +00:00
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|