diff --git a/ProjectPlugins/DeployAndRunPlugin/CoreInterfaceExtensions.cs b/ProjectPlugins/DeployAndRunPlugin/CoreInterfaceExtensions.cs new file mode 100644 index 00000000..262e27d6 --- /dev/null +++ b/ProjectPlugins/DeployAndRunPlugin/CoreInterfaceExtensions.cs @@ -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().Run(runConfig); + } + } +} diff --git a/ProjectPlugins/DeployAndRunPlugin/DeployAndRunContainerRecipe.cs b/ProjectPlugins/DeployAndRunPlugin/DeployAndRunContainerRecipe.cs new file mode 100644 index 00000000..12435a88 --- /dev/null +++ b/ProjectPlugins/DeployAndRunPlugin/DeployAndRunContainerRecipe.cs @@ -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(); + + 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; } + } +} \ No newline at end of file diff --git a/ProjectPlugins/DeployAndRunPlugin/DeployAndRunPlugin.cs b/ProjectPlugins/DeployAndRunPlugin/DeployAndRunPlugin.cs new file mode 100644 index 00000000..14405443 --- /dev/null +++ b/ProjectPlugins/DeployAndRunPlugin/DeployAndRunPlugin.cs @@ -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(); + } + } +} diff --git a/ProjectPlugins/DeployAndRunPlugin/DeployAndRunPlugin.csproj b/ProjectPlugins/DeployAndRunPlugin/DeployAndRunPlugin.csproj new file mode 100644 index 00000000..66d0737a --- /dev/null +++ b/ProjectPlugins/DeployAndRunPlugin/DeployAndRunPlugin.csproj @@ -0,0 +1,14 @@ + + + + net7.0 + enable + enable + + + + + + + +