1
0

Use volumes to share sshkey and authorized keys instead of copying and add build time variables to docker-compose

This commit is contained in:
nicolas.dorier
2019-09-20 16:39:48 +09:00
parent 21f1af6280
commit c35c606da6
8 changed files with 93 additions and 3 deletions

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using YamlDotNet.RepresentationModel;
namespace DockerGenerator
{
// Replace built time variable ( $<variable_name>? ) in the docker generator
class BuildTimeVariableVisitor : YamlVisitorBase
{
class Context
{
public List<YamlScalarNode> ToRemove = new List<YamlScalarNode>();
}
Stack<Context> _Contexts = new Stack<Context>();
Context CurrentContext
{
get
{
return _Contexts.TryPeek(out var ctx) ? ctx : null;
}
}
protected override void VisitChildren(YamlSequenceNode sequence)
{
_Contexts.Push(new Context());
base.VisitChildren(sequence);
var ctx = _Contexts.Pop();
foreach (var child in ctx.ToRemove)
{
sequence.Children.Remove(child);
}
}
public override void Visit(YamlScalarNode scalar)
{
bool removeNode = false;
scalar.Value = Regex.Replace(scalar.Value, "\\$<(.*?)>\\?", (match) =>
{
var replacedBy = Environment.GetEnvironmentVariable(match.Groups[1].Value);
if (string.IsNullOrEmpty(replacedBy))
{
removeNode = true;
}
return replacedBy;
});
if (removeNode)
CurrentContext?.ToRemove.Add(scalar);
base.Visit(scalar);
}
}
}

View File

@@ -87,7 +87,7 @@ namespace DockerGenerator
output.Add("services", new YamlMappingNode(Merge(services)));
output.Add("volumes", new YamlMappingNode(volumes));
output.Add("networks", new YamlMappingNode(networks));
PostProcess(output);
var dockerImages = ((YamlMappingNode)output["services"]).Children.Select(kv => kv.Value["image"].ToString()).ToList();
dockerImages.Add("btcpayserver/docker-compose-builder:1.24.1");
@@ -119,6 +119,11 @@ namespace DockerGenerator
Console.WriteLine();
}
private void PostProcess(YamlMappingNode output)
{
new BuildTimeVariableVisitor().Visit(output);
}
private KeyValuePair<YamlNode, YamlNode>[] Merge(List<KeyValuePair<YamlNode, YamlNode>> services)
{
return services

View File

@@ -4,6 +4,7 @@
"commandName": "Project",
"commandLineArgs": "pregen",
"environmentVariables": {
"BTCPAY_HOST_SSHKEYFILE": "test.rsa",
"BTCPAYGEN_LIGHTNING": "clightning",
"BTCPAYGEN_CRYPTO4": "ftc",
"BTCPAYGEN_CRYPTO3": "btg",
@@ -13,4 +14,4 @@
}
}
}
}
}