Adds deploy-and-run plugin

This commit is contained in:
benbierens 2023-10-31 11:15:08 +01:00
parent e87f255f48
commit bfdbebb36e
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,13 @@
using Core;
using KubernetesWorkflow;
namespace DeployAndRunPlugin
{
public static class CoreInterfaceExtensions
{
public static RunningContainer DeployAndRunContinuousTests(this CoreInterface ci, RunConfig runConfig)
{
return ci.GetPlugin<DeployAndRunPlugin>().Run(runConfig);
}
}
}

View File

@ -0,0 +1,43 @@
using KubernetesWorkflow;
namespace DeployAndRunPlugin
{
public class DeployAndRunContainerRecipe : ContainerRecipeFactory
{
public override string AppName => "deploy-and-run";
public override string Image => "thatbenbierens/dist-tests-deployandrun:initial";
protected override void Initialize(StartupConfig config)
{
var setup = config.Get<RunConfig>();
if (setup.CodexImageOverride != null)
{
AddEnvVar("CODEXDOCKERIMAGE", setup.CodexImageOverride);
}
AddEnvVar("DNR_REP", setup.Replications.ToString());
AddEnvVar("DNR_NAME", setup.Name);
AddEnvVar("DNR_FILTER", setup.Filter);
AddEnvVar("DNR_DURATION", setup.Duration.TotalSeconds.ToString());
}
}
public class RunConfig
{
public RunConfig(string name, string filter, TimeSpan duration, int replications, string? codexImageOverride = null)
{
Name = name;
Filter = filter;
Duration = duration;
Replications = replications;
CodexImageOverride = codexImageOverride;
}
public string Name { get; }
public string Filter { get; }
public TimeSpan Duration { get; }
public int Replications { get; }
public string? CodexImageOverride { get; }
}
}

View File

@ -0,0 +1,35 @@
using Core;
using KubernetesWorkflow;
namespace DeployAndRunPlugin
{
public class DeployAndRunPlugin : IProjectPlugin
{
private readonly IPluginTools tools;
public DeployAndRunPlugin(IPluginTools tools)
{
this.tools = tools;
}
public void Announce()
{
tools.GetLog().Log("Deploy-and-Run plugin loaded.");
}
public void Decommission()
{
}
public RunningContainer Run(RunConfig config)
{
var workflow = tools.CreateWorkflow();
var startupConfig = new StartupConfig();
startupConfig.NameOverride = "dnr-" + config.Name;
startupConfig.Add(config);
var containers = workflow.Start(1, new DeployAndRunContainerRecipe(), startupConfig);
return containers.Containers.Single();
}
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Framework\Core\Core.csproj" />
<ProjectReference Include="..\..\Framework\KubernetesWorkflow\KubernetesWorkflow.csproj" />
</ItemGroup>
</Project>