2023-04-12 11:53:55 +00:00
|
|
|
|
namespace KubernetesWorkflow
|
|
|
|
|
{
|
|
|
|
|
public abstract class ContainerRecipeFactory
|
|
|
|
|
{
|
|
|
|
|
private readonly List<Port> exposedPorts = new List<Port>();
|
|
|
|
|
private readonly List<Port> internalPorts = new List<Port>();
|
|
|
|
|
private readonly List<EnvVar> envVars = new List<EnvVar>();
|
2023-04-14 10:37:05 +00:00
|
|
|
|
private readonly List<object> additionals = new List<object>();
|
2023-04-12 11:53:55 +00:00
|
|
|
|
private RecipeComponentFactory factory = null!;
|
|
|
|
|
|
2023-04-14 08:51:35 +00:00
|
|
|
|
public ContainerRecipe CreateRecipe(int index, int containerNumber, RecipeComponentFactory factory, StartupConfig config)
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
|
|
|
|
this.factory = factory;
|
|
|
|
|
ContainerNumber = containerNumber;
|
2023-04-14 08:51:35 +00:00
|
|
|
|
Index = index;
|
2023-04-12 11:53:55 +00:00
|
|
|
|
|
|
|
|
|
Initialize(config);
|
|
|
|
|
|
2023-04-14 10:37:05 +00:00
|
|
|
|
var recipe = new ContainerRecipe(containerNumber, Image, exposedPorts.ToArray(), internalPorts.ToArray(), envVars.ToArray(), additionals.ToArray());
|
2023-04-13 08:11:33 +00:00
|
|
|
|
|
|
|
|
|
exposedPorts.Clear();
|
|
|
|
|
internalPorts.Clear();
|
|
|
|
|
envVars.Clear();
|
2023-04-14 10:37:05 +00:00
|
|
|
|
additionals.Clear();
|
2023-04-13 08:11:33 +00:00
|
|
|
|
this.factory = null!;
|
|
|
|
|
|
|
|
|
|
return recipe;
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-17 09:12:14 +00:00
|
|
|
|
public abstract string Image { get; }
|
2023-04-12 11:53:55 +00:00
|
|
|
|
protected int ContainerNumber { get; private set; } = 0;
|
2023-04-14 08:51:35 +00:00
|
|
|
|
protected int Index { get; private set; } = 0;
|
2023-04-12 11:53:55 +00:00
|
|
|
|
protected abstract void Initialize(StartupConfig config);
|
|
|
|
|
|
2023-04-13 12:36:17 +00:00
|
|
|
|
protected Port AddExposedPort(string tag = "")
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
2023-04-13 12:36:17 +00:00
|
|
|
|
var p = factory.CreatePort(tag);
|
2023-04-12 11:53:55 +00:00
|
|
|
|
exposedPorts.Add(p);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 12:36:17 +00:00
|
|
|
|
protected Port AddInternalPort(string tag = "")
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
2023-04-13 12:36:17 +00:00
|
|
|
|
var p = factory.CreatePort(tag);
|
2023-04-12 11:53:55 +00:00
|
|
|
|
internalPorts.Add(p);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 12:36:17 +00:00
|
|
|
|
protected void AddExposedPortAndVar(string name, string tag = "")
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
2023-04-13 12:36:17 +00:00
|
|
|
|
AddEnvVar(name, AddExposedPort(tag));
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 12:36:17 +00:00
|
|
|
|
protected void AddInternalPortAndVar(string name, string tag = "")
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
2023-04-13 12:36:17 +00:00
|
|
|
|
AddEnvVar(name, AddInternalPort(tag));
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void AddEnvVar(string name, string value)
|
|
|
|
|
{
|
|
|
|
|
envVars.Add(factory.CreateEnvVar(name, value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void AddEnvVar(string name, Port value)
|
|
|
|
|
{
|
|
|
|
|
envVars.Add(factory.CreateEnvVar(name, value.Number));
|
|
|
|
|
}
|
2023-04-14 10:37:05 +00:00
|
|
|
|
|
|
|
|
|
protected void Additional(object userData)
|
|
|
|
|
{
|
|
|
|
|
additionals.Add(userData);
|
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|