Browse Source

Show proper error message if using incompatible options

dcg-latest
nicolas.dorier 5 years ago
parent
commit
5d031d9638
No known key found for this signature in database GPG Key ID: 6618763EF09186FE
  1. 16
      docker-compose-generator/src/DockerComposeDefinition.cs
  2. 3
      docker-compose-generator/src/Properties/launchSettings.json

16
docker-compose-generator/src/DockerComposeDefinition.cs

@ -54,6 +54,7 @@ namespace DockerGenerator
var volumes = new List<KeyValuePair<YamlNode, YamlNode>>();
var networks = new List<KeyValuePair<YamlNode, YamlNode>>();
var exclusives = new List<(FragmentName FragmentName, string Exclusivity)>();
var incompatibles = new List<(FragmentName FragmentName, string Exclusivity)>();
foreach (var fragment in Fragments.Where(NotExcluded))
{
@ -92,6 +93,13 @@ namespace DockerGenerator
exclusives.Add((fragment, node.ToString()));
}
}
if (doc.Children.ContainsKey("incompatible") && doc.Children["incompatible"] is YamlSequenceNode fragmentIncompatibleRoot)
{
foreach (var node in fragmentIncompatibleRoot)
{
incompatibles.Add((fragment, node.ToString()));
}
}
if (doc.Children.ContainsKey("required") && doc.Children["required"] is YamlSequenceNode fragmentRequireRoot)
{
foreach (var node in fragmentRequireRoot)
@ -126,6 +134,14 @@ namespace DockerGenerator
if (exclusiveConflict != null)
throw new YamlBuildException($"The fragments {String.Join(", ", exclusiveConflict.Select(e => e.FragmentName))} can't be used simultaneously (group '{exclusiveConflict.Key}')");
var groups = exclusives.ToDictionary(e => e.Exclusivity, e => e.FragmentName);
var incompatible = incompatibles
.Select(i => groups.TryGetValue(i.Exclusivity, out _) ? (i.FragmentName, i.Exclusivity) : (null, null))
.Where(i => i.Exclusivity != null)
.FirstOrDefault();
if (incompatible.Exclusivity != null)
throw new YamlBuildException($"The fragment {incompatible.FragmentName} is incompatible with '{incompatible.Exclusivity}'");
Console.WriteLine($"Selected fragments:");
foreach (var fragment in processedFragments)
{

3
docker-compose-generator/src/Properties/launchSettings.json

@ -11,8 +11,7 @@
"BTCPAYGEN_CRYPTO2": "ltc",
"BTCPAYGEN_CRYPTO1": "btc",
"BTCPAYGEN_REVERSEPROXY": "nginx",
"BTCPAYGEN_ADDITIONAL_FRAGMENTS": "opt-save-storage",
"BTCPAYGEN_EXCLUDE_FRAGMENTS": "postgres"
"BTCPAYGEN_ADDITIONAL_FRAGMENTS": "opt-save-storage;opt-txindex"
}
}
}

Loading…
Cancel
Save