diff --git a/Framework/KubernetesWorkflow/K8sNameUtils.cs b/Framework/KubernetesWorkflow/K8sNameUtils.cs index c888870..65c2228 100644 --- a/Framework/KubernetesWorkflow/K8sNameUtils.cs +++ b/Framework/KubernetesWorkflow/K8sNameUtils.cs @@ -13,7 +13,10 @@ .Replace("]", "-") .Replace(",", "-"); - return result.Trim('-'); + result = result.Trim('-'); + if (result.Length > 62) result = result.Substring(0, 62); + + return result; } } } diff --git a/ProjectPlugins/CodexPlugin/LocalCodexBuilder.cs b/ProjectPlugins/CodexPlugin/LocalCodexBuilder.cs index 5e4b2d0..bd86442 100644 --- a/ProjectPlugins/CodexPlugin/LocalCodexBuilder.cs +++ b/ProjectPlugins/CodexPlugin/LocalCodexBuilder.cs @@ -70,21 +70,34 @@ namespace CodexNetDeployer { var dockerPassword = Environment.GetEnvironmentVariable("DOCKERPASSWORD"); - if (string.IsNullOrEmpty(dockerUsername) || string.IsNullOrEmpty(dockerPassword)) + try { - Log("Environment variable 'DOCKERPASSWORD' not provided."); - Log("Trying system default..."); - Docker("login"); + if (string.IsNullOrEmpty(dockerUsername) || string.IsNullOrEmpty(dockerPassword)) + { + Log("Environment variable 'DOCKERPASSWORD' not provided."); + Log("Trying system default..."); + Docker("login"); + } + else + { + Docker("login", "-u", dockerUsername, "-p", dockerPassword); + } } - else + catch { - Docker("login", "-u", dockerUsername, "-p", dockerPassword); + Log("Docker login failed."); + Log("Please check the docker username and password provided by the constructor arguments and/or"); + Log("set by 'DOCKERUSERNAME' and 'DOCKERPASSWORD' environment variables."); + Log("Note: You can use a docker access token as DOCKERPASSWORD."); + throw; } } private string GenerateImageName() { - return $"{dockerUsername!}/nim-codex-autoimage:{Guid.NewGuid().ToString().ToLowerInvariant()}"; + var tag = Environment.GetEnvironmentVariable("DOCKERTAG"); + if (string.IsNullOrEmpty(tag)) return $"{dockerUsername!}/nim-codex-autoimage:{Guid.NewGuid().ToString().ToLowerInvariant()}"; + return $"{dockerUsername}/nim-codex-autoimage:{tag}"; } private void Docker(params string[] args) diff --git a/Tests/CodexTests/CodexDistTest.cs b/Tests/CodexTests/CodexDistTest.cs index 32c6ec2..f2e863d 100644 --- a/Tests/CodexTests/CodexDistTest.cs +++ b/Tests/CodexTests/CodexDistTest.cs @@ -1,8 +1,10 @@ using CodexContractsPlugin; +using CodexNetDeployer; using CodexPlugin; using Core; using DistTestCore; using DistTestCore.Helpers; +using DistTestCore.Logs; using GethPlugin; using NUnit.Framework.Constraints; @@ -20,6 +22,13 @@ namespace Tests ProjectPlugin.Load(); } + protected override void Initialize(FixtureLog fixtureLog) + { + var localBuilder = new LocalCodexBuilder(fixtureLog); + localBuilder.Intialize(); + localBuilder.Build(); + } + public ICodexNode AddCodex() { return AddCodex(s => { }); diff --git a/Tests/DistTestCore/DistTest.cs b/Tests/DistTestCore/DistTest.cs index 8e9932a..95e69a9 100644 --- a/Tests/DistTestCore/DistTest.cs +++ b/Tests/DistTestCore/DistTest.cs @@ -32,6 +32,8 @@ namespace DistTestCore statusLog = new StatusLog(logConfig, startTime); globalEntryPoint = new EntryPoint(fixtureLog, configuration.GetK8sConfiguration(new DefaultTimeSet(), TestNamespacePrefix), configuration.GetFileManagerFolder()); + + Initialize(fixtureLog); } [OneTimeSetUp] @@ -140,6 +142,10 @@ namespace DistTestCore Stopwatch.Measure(Get().Log, name, action); } + protected virtual void Initialize(FixtureLog fixtureLog) + { + } + protected TestLifecycle Get() { lock (lifecycleLock) diff --git a/Tools/CodexNetDeployer/Configuration.cs b/Tools/CodexNetDeployer/Configuration.cs index fa94c15..3ec20bf 100644 --- a/Tools/CodexNetDeployer/Configuration.cs +++ b/Tools/CodexNetDeployer/Configuration.cs @@ -1,6 +1,5 @@ using ArgsUniform; using CodexPlugin; -using static Org.BouncyCastle.Math.EC.ECCurve; namespace CodexNetDeployer { @@ -16,7 +15,8 @@ namespace CodexNetDeployer public string KubeNamespace { get; set; } = string.Empty; [Uniform("codex-local-repo", "cr", "CODEXLOCALREPOPATH", false, "If set, instead of using the default Codex docker image, the local repository will be used to build an image. " + - "This requires the 'DOCKERUSERNAME' and 'DOCKERPASSWORD' environment variables to be set.")] + "This requires the 'DOCKERUSERNAME' and 'DOCKERPASSWORD' environment variables to be set. (You can omit the password to use your system default, or use a docker access token as DOCKERPASSWORD.) You can set " + + "'DOCKERTAG' to define the image tag. If not set, one will be generated.")] public string CodexLocalRepoPath { get; set; } = string.Empty; [Uniform("nodes", "n", "NODES", true, "Number of Codex nodes to be created.")] @@ -65,35 +65,7 @@ namespace CodexNetDeployer [Uniform("check-connect", "cc", "CHECKCONNECT", false, "If true, deployer check ensure peer-connectivity between all deployed nodes after deployment. Default is false.")] public bool CheckPeerConnection { get; set; } = false; - public Configuration() - { - // dotnet run \ - //--kube - config =/ opt / kubeconfig.yaml \ - //--kube -namespace=codex-continuous-tests \ - //--nodes=5 \ - //--validators=3 \ - //--log-level=Trace \ - //--storage-quota=2048 \ - //--storage-sell=1024 \ - //--min-price=1024 \ - //--max-collateral=1024 \ - //--max-duration=3600000 \ - //--block-ttl=180 \ - //--block-mi=120 \ - //--block-mn=10000 \ - //--metrics=1 \ - //--check-connect=1 - - KubeNamespace = "autodockertest"; - NumberOfCodexNodes = 3; - NumberOfValidators = 1; - StorageQuota = 2048; - StorageSell = 1024; - - CodexLocalRepoPath = "D:/Projects/nim-codex"; - } - - public List Validate() + public List Validate() { var errors = new List();