From 0bcf83c49a14af00add447f35db07bbddb4d9ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miha=20Marki=C4=8D?= Date: Sat, 24 Feb 2024 12:06:35 +0100 Subject: [PATCH] Splits DockerComposeSettings into standalone settings --- args-parser-2.linq | 254 +++++++++-------- .../Build/DockerComposeBuildFixture.cs | 40 +-- .../Compose/Build/DockerComposeBuildTest.cs | 32 ++- .../Compose/DockerComposeFixture.cs | 36 +++ .../Compose/Exec/DockerComposeExecFixture.cs | 44 +-- .../Compose/Exec/DockerComposeExecTest.cs | 15 ++ .../Compose/Port/DockerComposePortFixture.cs | 42 +-- .../Compose/Port/DockerComposePortTest.cs | 15 ++ .../Compose/Ps/DockerComposePsFixture.cs | 38 +-- .../Compose/Ps/DockerComposePsTest.cs | 14 + .../Compose/Run/DockerComposeRunFixture.cs | 41 +-- .../Compose/Run/DockerComposeRunTest.cs | 14 + .../Compose/Up/DockerComposeUpFixture.cs | 45 +--- .../Compose/Up/DockerComposeUpTest.cs | 13 + src/Cake.Docker/BuildX/Build/args.txt | 8 +- .../Build/Docker.Aliases.ComposeBuild.cs | 19 +- .../Build/DockerComposeBuildSettings.cs | 96 ++++--- .../Compose/Cp/Docker.Aliases.ComposeCp.cs | 7 +- .../Compose/Cp/DockerComposeCpSettings.cs | 38 ++- .../Create/Docker.Aliases.ComposeCreate.cs | 12 +- .../Create/DockerComposeCreateSettings.cs | 82 +++--- .../Compose/DockerComposeSettings.cs | 14 +- .../Down/Docker.Aliases.ComposeDown.cs | 8 +- .../Compose/Down/DockerComposeDownSettings.cs | 56 ++-- .../Exec/Docker.Aliases.ComposeExec.cs | 12 +- .../Compose/Exec/DockerComposeExecSettings.cs | 82 +++--- .../Kill/Docker.Aliases.ComposeKill.cs | 8 +- .../Compose/Kill/DockerComposeKillSettings.cs | 32 ++- .../Logs/Docker.Aliases.ComposeLogs.cs | 8 +- .../Compose/Logs/DockerComposeLogsSettings.cs | 90 +++---- .../Pause/Docker.Aliases.ComposePause.cs | 11 +- .../Port/Docker.Aliases.ComposePort.cs | 8 +- .../Compose/Ps/Docker.Aliases.ComposePs.cs | 11 +- .../Compose/Ps/DockerComposePsSettings.cs | 110 ++++---- .../Pull/Docker.Aliases.ComposePull.cs | 9 +- .../Compose/Pull/DockerComposePullSettings.cs | 56 ++-- .../Push/Docker.Aliases.ComposePush.cs | 9 +- .../Compose/Push/DockerComposePushSettings.cs | 42 ++- .../Restart/Docker.Aliases.ComposeRestart.cs | 10 +- .../Restart/DockerComposeRestartSettings.cs | 30 +-- .../Compose/Rm/Docker.Aliases.ComposeRm.cs | 11 +- .../Compose/Rm/DockerComposeRmSettings.cs | 38 ++- .../Compose/Run/Docker.Aliases.ComposeRun.cs | 18 +- .../Compose/Run/DockerComposeRunSettings.cs | 194 +++++++------ .../Scale/Docker.Aliases.ComposeScale.cs | 10 +- .../Scale/DockerComposeScaleSettings.cs | 22 +- .../Start/Docker.Aliases.ComposeStart.cs | 10 +- .../Stop/Docker.Aliases.ComposeStop.cs | 11 +- .../Compose/Stop/DockerComposeSTopSettings.cs | 22 +- .../Unpause/Docker.Aliases.ComposeUnpause.cs | 11 +- .../Compose/Up/Docker.Aliases.ComposeUp.cs | 10 +- .../Compose/Up/DockerComposeUpSettings.cs | 255 +++++++++--------- src/Cake.Docker/GenericDockerRunner.cs | 67 +++++ 53 files changed, 1153 insertions(+), 1037 deletions(-) create mode 100644 src/Cake.Docker.Tests/Compose/DockerComposeFixture.cs diff --git a/args-parser-2.linq b/args-parser-2.linq index 8295b08..9de9219 100644 --- a/args-parser-2.linq +++ b/args-parser-2.linq @@ -1,128 +1,170 @@ - + + System.Collections.Immutable + -string path = @"Compose\Run"; -string file = Path.Combine(Path.GetDirectoryName(Util.CurrentQueryPath)!, $@"src\Cake.Docker\{path}\args.txt"); -//string file = @"D:\GitProjects\Righthand\Cake\Cake.Docker\src\Cake.Docker\Compose\Up\args.txt"; -string[] lines = File.ReadAllLines(file); - -Regex regex = new Regex( - "--(?[a-z0-9,\\-]+)(?:\\s(?\\w+))?\\s+(?.+" + - ")", - RegexOptions.IgnoreCase - | RegexOptions.Multiline - | RegexOptions.CultureInvariant - | RegexOptions.Compiled - ); - -Dictionary> data = new Dictionary>(); -List? current = null; -foreach (string line in lines.Where(l =>!string.IsNullOrEmpty(l)).Select(l => l.TrimStart())) +void Main() { - if (line.StartsWith("-")) + string[] commands = new[] { "Build", "Cp", "Create", "Down", "Exec", "Kill", "Logs", "Pause", "Port", "Ps", "Pull", "Push", "Restart", "Rm", "Run", "Scale", "Start", "Stop", "Unpase", "Up" }; + foreach (string command in commands) { - current = new List(); - data.Add(line, current); + CreateSettings(@$"Compose\{command}", true); } - else +} + +int CountSpaces(string line) +{ + int result = 0; + foreach (char c in line) { - current.Add(line.Trim()); + if (c != ' ') + { + break; + } + result++; } + return result; } -string className = path.Replace(@"\", ""); -"namespace Cake.Docker".Dump(); -"{".Dump(); -"/// ".Dump(); -$"/// Settings for docker {string.Join(" ", path.Split('\\').Select(p => p.ToLower()))}.".Dump(); -"/// ".Dump(); -$"public sealed class Docker{className}Settings : DockerComposeSettings".Dump(); -"{".Dump(); -foreach (var pair in data) + +void CreateSettings(string command, bool outputToFile) { - string line = pair.Key; - - var match = regex.Match(line); - if (!match.Success) + string file = Path.Combine(Path.GetDirectoryName(Util.CurrentQueryPath)!, $@"src\Cake.Docker\{command}\args.txt"); + if (!File.Exists(file)) { - ("FAILED to match " + line).Dump(); + file.Dump("Skipping, does not exist"); + return; } - else + string className = command.Replace(@"\", ""); + string settingsFile = Path.Combine(Path.GetDirectoryName(Util.CurrentQueryPath)!, $@"src\Cake.Docker\{command}\\Docker{className}Settings.cs"); + //string file = @"D:\GitProjects\Righthand\Cake\Cake.Docker\src\Cake.Docker\Compose\Up\args.txt"; + string[] lines = File.ReadAllLines(file); + //string.Join(Environment.NewLine, lines).Dump(); + + Regex regex = new Regex( + "--(?[a-z0-9,\\-]+)(?:\\s(?\\w+))?\\s+(?.+" + + ")", + RegexOptions.IgnoreCase + | RegexOptions.Multiline + | RegexOptions.CultureInvariant + | RegexOptions.Compiled + ); + + Dictionary> data = new Dictionary>(); + List? current = null; + foreach (string line in lines.Where(l => !string.IsNullOrEmpty(l))) { - string rawName = match.Groups["Argument"].Value; - string type = match.Groups["Type"].Value; - string info = match.Groups["Info"].Value; - string name = ""; - bool upperCase = true; - foreach (char c in rawName) + int offset = CountSpaces(line); + var trimmed = line.AsSpan().Trim(); + if (offset < 34 && trimmed.StartsWith("-")) { - if (upperCase) - { - name += char.ToUpper(c); - upperCase = false; - } - else - { - if (c == '-') - { - upperCase = true; - } - else - { - name += c; - } - } + current = new List(); + data.Add(line, current); } - List comment = new List(); - comment.Add(info); - comment.AddRange(pair.Value.Select(l => $"\t{l}")); - "/// ".Dump(); - foreach (string commentLine in comment) + current!.Add(trimmed.ToString()); + } + StringBuilder sb = new(); + + sb.AppendLine("namespace Cake.Docker;"); + sb.AppendLine("/// "); + sb.AppendLine($"/// Settings for docker {string.Join(" ", command.Split('\\').Select(p => p.ToLower()))}."); + sb.AppendLine("/// "); + sb.AppendLine($"public sealed class Docker{className}Settings : AutoToolSettings"); + sb.AppendLine("{"); + foreach (var pair in data) + { + string line = pair.Key; + + var match = regex.Match(line); + if (!match.Success) { - ("/// " + commentLine - .Replace("<", "<") - .Replace(">", ">")) - .Dump(); + ("FAILED to match " + line).Dump(); } - "/// ".Dump(); - string netType; - switch (type) + else { - case "duration": - netType = "TimeSpan?"; - break; - case "int?": - case "int": - case "uint": - netType = "int?"; - break; - case "value": - if (info.EndsWith("[])")) - { - netType = "string[]?"; + string rawName = match.Groups["Argument"].Value; + string type = match.Groups["Type"].Value; + string info = match.Groups["Info"].Value; + string name = ""; + bool upperCase = true; + foreach (char c in rawName) + { + if (upperCase) + { + name += char.ToUpper(c); + upperCase = false; } else { - netType = "string="; + if (c == '-') + { + upperCase = true; + } + else + { + name += c; + } } - break; - case "string": - netType = "string?"; - break; - case "strings": - netType = "string[]?"; - break; - case "stringArray": - netType = "string[]?"; - break; - default: - netType = "bool?"; - break; - } - if (type == "stringArray") - { - "[AutoProperty(AutoArrayType=AutoArrayType.List)]".Dump(); + } + List comment = new List(); + comment.Add(info); + comment.AddRange(pair.Value.Skip(1).Select(l => $"{l}")); + sb.AppendLine("\t/// "); + foreach (string commentLine in comment) + { + sb.AppendLine("\t/// " + commentLine + .Replace("<", "<") + .Replace(">", ">")); + } + sb.AppendLine("\t/// "); + string netType; + switch (type) + { + case "duration": + netType = "TimeSpan?"; + break; + case "int?": + case "int": + case "uint": + case "bytes": + netType = "int?"; + break; + case "value": + if (info.EndsWith("[])")) + { + netType = "string[]?"; + } + else + { + netType = "string?="; + } + break; + case "string": + netType = "string?"; + break; + case "strings": + netType = "string[]?"; + break; + case "stringArray": + netType = "string[]?"; + break; + default: + netType = "bool?"; + break; + } + if (type == "stringArray") + { + sb.AppendLine("\t[AutoProperty(AutoArrayType=AutoArrayType.List)]"); + } + sb.AppendLine($"\tpublic {netType} {name} {{ get; set; }}"); } - $"public {netType} {name} {{ get; set; }}".Dump(); } -} -"}".Dump(); -"}".Dump(); + sb.AppendLine("}"); + if (outputToFile) + { + File.WriteAllText(settingsFile, sb.ToString()); + } + else + { + sb.Dump(); + } + +} \ No newline at end of file diff --git a/src/Cake.Docker.Tests/Compose/Build/DockerComposeBuildFixture.cs b/src/Cake.Docker.Tests/Compose/Build/DockerComposeBuildFixture.cs index bf797de..3e995ab 100644 --- a/src/Cake.Docker.Tests/Compose/Build/DockerComposeBuildFixture.cs +++ b/src/Cake.Docker.Tests/Compose/Build/DockerComposeBuildFixture.cs @@ -1,39 +1,11 @@ -using Cake.Core; -using Cake.Core.Configuration; -using Cake.Core.Diagnostics; -using Cake.Core.IO; -using Cake.Testing.Fixtures; -using System; +using Cake.Docker.Tests.Compose; -namespace Cake.Docker.Tests.Build +namespace Cake.Docker.Tests.Build; + +public class DockerComposeBuildFixture : DockerComposeFixture { - public class DockerComposeBuildFixture : ToolFixture, ICakeContext + protected override void RunTool() { - public string[] Services { get; set; } = []; - - IFileSystem ICakeContext.FileSystem => FileSystem; - - ICakeEnvironment ICakeContext.Environment => Environment; - - public ICakeLog Log => Log; - - ICakeArguments ICakeContext.Arguments => throw new NotImplementedException(); - - IProcessRunner ICakeContext.ProcessRunner => ProcessRunner; - - public IRegistry Registry => Registry; - - public ICakeDataResolver Data => throw new NotImplementedException(); - - ICakeConfiguration ICakeContext.Configuration => throw new NotImplementedException(); - - public DockerComposeBuildFixture(): base("docker") - { - ProcessRunner.Process.SetStandardOutput(Array.Empty()); - } - protected override void RunTool() - { - this.DockerComposeBuild(Settings, Services); - } + this.DockerComposeBuild(Settings, ComposeSettings, Services); } } diff --git a/src/Cake.Docker.Tests/Compose/Build/DockerComposeBuildTest.cs b/src/Cake.Docker.Tests/Compose/Build/DockerComposeBuildTest.cs index e22a8c6..2636de7 100644 --- a/src/Cake.Docker.Tests/Compose/Build/DockerComposeBuildTest.cs +++ b/src/Cake.Docker.Tests/Compose/Build/DockerComposeBuildTest.cs @@ -10,12 +10,13 @@ public void WhenParallelFlagIsSet_CommandLineIsCorrect() { var fixture = new DockerComposeBuildFixture { - Settings = new DockerComposeBuildSettings { Parallel = 2 }, + ComposeSettings = new DockerComposeSettings { Parallel = 2, }, + Settings = new DockerComposeBuildSettings { }, }; var actual = fixture.Run(); - Assert.That(actual.Args, Is.EqualTo("compose build --parallel 2")); + Assert.That(actual.Args, Is.EqualTo("compose --parallel 2 build")); } [Test] @@ -23,7 +24,8 @@ public void WhenParallelFlagIsSetToFalse_CommandLineDoesNotHaveRm() { var fixture = new DockerComposeBuildFixture { - Settings = new DockerComposeBuildSettings { Parallel = null }, + ComposeSettings = new DockerComposeSettings { Parallel = null, }, + Settings = new DockerComposeBuildSettings { }, }; var actual = fixture.Run(); @@ -32,28 +34,42 @@ public void WhenParallelFlagIsSetToFalse_CommandLineDoesNotHaveRm() } [Test] - public void WhenFilesFlagIsUsed_CommandLineIncludesIt() + public void WhenFilesAreUsed_CommandLineIncludesIt() { var fixture = new DockerComposeBuildFixture { - Settings = new DockerComposeBuildSettings { File = ["alfa.yaml"] }, + ComposeSettings = new DockerComposeSettings { File = ["alfa.yaml"], }, + Settings = new DockerComposeBuildSettings { }, }; var actual = fixture.Run(); - Assert.That(actual.Args, Is.EqualTo("compose build --file \"alfa.yaml\"")); + Assert.That(actual.Args, Is.EqualTo("compose --file \"alfa.yaml\" build")); } [Test] public void WhenTwoFilesAreProvided_CommandLineIncludesThem() { var fixture = new DockerComposeBuildFixture { - Settings = new DockerComposeBuildSettings { File = ["alfa.yaml", "beta.yaml"] }, + ComposeSettings = new DockerComposeSettings { File = ["alfa.yaml", "beta.yaml"], }, }; var actual = fixture.Run(); - Assert.That(actual.Args, Is.EqualTo("compose build --file \"alfa.yaml\" --file \"beta.yaml\"")); + Assert.That(actual.Args, Is.EqualTo("compose --file \"alfa.yaml\" --file \"beta.yaml\" build")); + } + [Test] + public void WhenFilesAreUsedAndMemoryIsSet_CommandLineIncludesIt() + { + var fixture = new DockerComposeBuildFixture + { + ComposeSettings = new DockerComposeSettings { File = ["alfa.yaml"], }, + Settings = new DockerComposeBuildSettings { Memory = 1024, }, + }; + + var actual = fixture.Run(); + + Assert.That(actual.Args, Is.EqualTo("compose --file \"alfa.yaml\" build --memory 1024")); } } } diff --git a/src/Cake.Docker.Tests/Compose/DockerComposeFixture.cs b/src/Cake.Docker.Tests/Compose/DockerComposeFixture.cs new file mode 100644 index 0000000..c744eca --- /dev/null +++ b/src/Cake.Docker.Tests/Compose/DockerComposeFixture.cs @@ -0,0 +1,36 @@ +using Cake.Core.Configuration; +using Cake.Core.Diagnostics; +using Cake.Core.IO; +using Cake.Core; +using Cake.Core.Tooling; +using Cake.Testing.Fixtures; +using System; + +namespace Cake.Docker.Tests.Compose; + +public abstract class DockerComposeFixture : ToolFixture, ICakeContext + where TSettings: ToolSettings, new() +{ + public DockerComposeSettings ComposeSettings { get; set; } + public string[] Services { get; set; } = []; + + IFileSystem ICakeContext.FileSystem => FileSystem; + + ICakeEnvironment ICakeContext.Environment => Environment; + + public ICakeLog Log => Log; + + ICakeArguments ICakeContext.Arguments => throw new NotImplementedException(); + + IProcessRunner ICakeContext.ProcessRunner => ProcessRunner; + + public IRegistry Registry => Registry; + + public ICakeDataResolver Data => throw new NotImplementedException(); + + ICakeConfiguration ICakeContext.Configuration => throw new NotImplementedException(); + public DockerComposeFixture() : base("docker") + { + ProcessRunner.Process.SetStandardOutput(Array.Empty()); + } +} diff --git a/src/Cake.Docker.Tests/Compose/Exec/DockerComposeExecFixture.cs b/src/Cake.Docker.Tests/Compose/Exec/DockerComposeExecFixture.cs index daec55a..c4f0b65 100644 --- a/src/Cake.Docker.Tests/Compose/Exec/DockerComposeExecFixture.cs +++ b/src/Cake.Docker.Tests/Compose/Exec/DockerComposeExecFixture.cs @@ -1,41 +1,13 @@ -using Cake.Core; -using Cake.Core.Configuration; -using Cake.Core.Diagnostics; -using Cake.Core.IO; -using Cake.Testing.Fixtures; -using System; +namespace Cake.Docker.Tests.Compose.Exec; -namespace Cake.Docker.Tests.Compose.Exec +public class DockerComposeExecFixture : DockerComposeFixture { - public class DockerComposeExecFixture : ToolFixture, ICakeContext + public string Service { get; set; } + public string Command { get; set; } + public string[] Args { get; set; } = []; + + protected override void RunTool() { - public string Service { get; set; } - public string Command { get; set; } - public string[] Args { get; set; } = []; - - IFileSystem ICakeContext.FileSystem => FileSystem; - - ICakeEnvironment ICakeContext.Environment => Environment; - - public ICakeLog Log => Log; - - ICakeArguments ICakeContext.Arguments => throw new NotImplementedException(); - - IProcessRunner ICakeContext.ProcessRunner => ProcessRunner; - - public IRegistry Registry => Registry; - - public ICakeDataResolver Data => Data; - - ICakeConfiguration ICakeContext.Configuration => throw new NotImplementedException(); - - public DockerComposeExecFixture() : base("docker") - { - ProcessRunner.Process.SetStandardOutput(Array.Empty()); - } - protected override void RunTool() - { - this.DockerComposeExec(Settings, Service, Command, Args); - } + this.DockerComposeExec(Settings, Service, Command, ComposeSettings, Args); } } diff --git a/src/Cake.Docker.Tests/Compose/Exec/DockerComposeExecTest.cs b/src/Cake.Docker.Tests/Compose/Exec/DockerComposeExecTest.cs index b891f1f..4a00864 100644 --- a/src/Cake.Docker.Tests/Compose/Exec/DockerComposeExecTest.cs +++ b/src/Cake.Docker.Tests/Compose/Exec/DockerComposeExecTest.cs @@ -19,5 +19,20 @@ public void WhenDisablePseudoTtyIsSet_AddsItsArgument() Assert.That(actual.Args, Is.EqualTo("compose exec service command")); } + [Test] + public void WhenParallelFlagIsSet_CommandLineIsCorrect() + { + var fixture = new DockerComposeExecFixture + { + Service = "service", + Command = "command", + ComposeSettings = new DockerComposeSettings { Parallel = 2, }, + Settings = new DockerComposeExecSettings { }, + }; + + var actual = fixture.Run(); + + Assert.That(actual.Args, Is.EqualTo("compose --parallel 2 exec service command")); + } } } diff --git a/src/Cake.Docker.Tests/Compose/Port/DockerComposePortFixture.cs b/src/Cake.Docker.Tests/Compose/Port/DockerComposePortFixture.cs index 4da846a..340e158 100644 --- a/src/Cake.Docker.Tests/Compose/Port/DockerComposePortFixture.cs +++ b/src/Cake.Docker.Tests/Compose/Port/DockerComposePortFixture.cs @@ -1,41 +1,11 @@ -using Cake.Core; -using Cake.Core.Configuration; -using Cake.Core.Diagnostics; -using Cake.Core.IO; -using Cake.Testing.Fixtures; -using System; +namespace Cake.Docker.Tests.Compose.Port; -namespace Cake.Docker.Tests.Compose.Port +public class DockerComposePortFixture : DockerComposeFixture { - public class DockerComposePortFixture : ToolFixture, ICakeContext + public string Service { get; set; } + public int Port { get; set; } + protected override void RunTool() { - public string Service { get; set; } - - public int Port { get; set; } - - IFileSystem ICakeContext.FileSystem => FileSystem; - - ICakeEnvironment ICakeContext.Environment => Environment; - - public ICakeLog Log => Log; - - ICakeArguments ICakeContext.Arguments => throw new NotImplementedException(); - - IProcessRunner ICakeContext.ProcessRunner => ProcessRunner; - - public IRegistry Registry => Registry; - - public ICakeDataResolver Data => throw new NotImplementedException(); - - ICakeConfiguration ICakeContext.Configuration => throw new NotImplementedException(); - - public DockerComposePortFixture(): base("docker") - { - ProcessRunner.Process.SetStandardOutput(Array.Empty()); - } - protected override void RunTool() - { - this.DockerComposePort(Settings, Service, Port); - } + this.DockerComposePort(Settings, Service, Port, ComposeSettings); } } diff --git a/src/Cake.Docker.Tests/Compose/Port/DockerComposePortTest.cs b/src/Cake.Docker.Tests/Compose/Port/DockerComposePortTest.cs index b9784d6..0846c02 100644 --- a/src/Cake.Docker.Tests/Compose/Port/DockerComposePortTest.cs +++ b/src/Cake.Docker.Tests/Compose/Port/DockerComposePortTest.cs @@ -34,5 +34,20 @@ public void WhenServiceAndPortAndIndexAreSet_CommandLineIsCorrect() Assert.That(actual.Args, Is.EqualTo("compose port --index 2 serviceA 8080")); } + [Test] + public void WhenParallelFlagIsSet_CommandLineIsCorrect() + { + var fixture = new DockerComposePortFixture + { + Settings = new DockerComposePortSettings { Index = 2 }, + Service = "serviceA", + Port = 8080, + ComposeSettings = new DockerComposeSettings { Parallel = 2, }, + }; + + var actual = fixture.Run(); + + Assert.That(actual.Args, Is.EqualTo("compose --parallel 2 port --index 2 serviceA 8080")); + } } } diff --git a/src/Cake.Docker.Tests/Compose/Ps/DockerComposePsFixture.cs b/src/Cake.Docker.Tests/Compose/Ps/DockerComposePsFixture.cs index e4475d3..886e54a 100644 --- a/src/Cake.Docker.Tests/Compose/Ps/DockerComposePsFixture.cs +++ b/src/Cake.Docker.Tests/Compose/Ps/DockerComposePsFixture.cs @@ -1,39 +1,9 @@ -using Cake.Core; -using Cake.Core.Configuration; -using Cake.Core.Diagnostics; -using Cake.Core.IO; -using Cake.Testing.Fixtures; -using System; +namespace Cake.Docker.Tests.Compose.Ps; -namespace Cake.Docker.Tests.Compose.Ps +public class DockerComposePsFixture : DockerComposeFixture { - public class DockerComposePsFixture : ToolFixture, ICakeContext + protected override void RunTool() { - public string[] Services { get; set; } = []; - - IFileSystem ICakeContext.FileSystem => FileSystem; - - ICakeEnvironment ICakeContext.Environment => Environment; - - public ICakeLog Log => Log; - - ICakeArguments ICakeContext.Arguments => throw new NotImplementedException(); - - IProcessRunner ICakeContext.ProcessRunner => ProcessRunner; - - public IRegistry Registry => Registry; - - public ICakeDataResolver Data => throw new NotImplementedException(); - - ICakeConfiguration ICakeContext.Configuration => throw new NotImplementedException(); - - public DockerComposePsFixture(): base("docker") - { - ProcessRunner.Process.SetStandardOutput(Array.Empty()); - } - protected override void RunTool() - { - this.DockerComposePs(Settings, Services); - } + this.DockerComposePs(Settings, ComposeSettings, Services); } } diff --git a/src/Cake.Docker.Tests/Compose/Ps/DockerComposePsTest.cs b/src/Cake.Docker.Tests/Compose/Ps/DockerComposePsTest.cs index bc839f4..a86f89e 100644 --- a/src/Cake.Docker.Tests/Compose/Ps/DockerComposePsTest.cs +++ b/src/Cake.Docker.Tests/Compose/Ps/DockerComposePsTest.cs @@ -59,5 +59,19 @@ public void WhenQuietIsSet_CommandLineIsCorrect() Assert.That(actual.Args, Is.EqualTo("compose ps --quiet serviceA serviceB serviceC")); } + [Test] + public void WhenParallelFlagIsSet_CommandLineIsCorrect() + { + var fixture = new DockerComposePsFixture + { + ComposeSettings = new DockerComposeSettings { Parallel = 2, }, + Settings = new DockerComposePsSettings { Quiet = true }, + Services = ["serviceA", "serviceB", "serviceC"], + }; + + var actual = fixture.Run(); + + Assert.That(actual.Args, Is.EqualTo("compose --parallel 2 ps --quiet serviceA serviceB serviceC")); + } } } diff --git a/src/Cake.Docker.Tests/Compose/Run/DockerComposeRunFixture.cs b/src/Cake.Docker.Tests/Compose/Run/DockerComposeRunFixture.cs index 5d27164..2f2030b 100644 --- a/src/Cake.Docker.Tests/Compose/Run/DockerComposeRunFixture.cs +++ b/src/Cake.Docker.Tests/Compose/Run/DockerComposeRunFixture.cs @@ -1,39 +1,12 @@ -using Cake.Core; -using Cake.Core.Configuration; -using Cake.Core.Diagnostics; -using Cake.Core.IO; -using Cake.Testing.Fixtures; -using System; +using Cake.Docker.Tests.Compose; -namespace Cake.Docker.Tests.Run +namespace Cake.Docker.Tests.Run; + +public class DockerComposeRunFixture : DockerComposeFixture { - public class DockerComposeRunFixture : ToolFixture, ICakeContext + public string Command { get; set; } + protected override void RunTool() { - public string Command { get; set; } - - IFileSystem ICakeContext.FileSystem => FileSystem; - - ICakeEnvironment ICakeContext.Environment => Environment; - - public ICakeLog Log => Log; - - ICakeArguments ICakeContext.Arguments => throw new NotImplementedException(); - - IProcessRunner ICakeContext.ProcessRunner => ProcessRunner; - - public IRegistry Registry => Registry; - - public ICakeDataResolver Data => throw new NotImplementedException(); - - ICakeConfiguration ICakeContext.Configuration => throw new NotImplementedException(); - - public DockerComposeRunFixture(): base("docker") - { - ProcessRunner.Process.SetStandardOutput(Array.Empty()); - } - protected override void RunTool() - { - this.DockerComposeRun(Settings, Command); - } + this.DockerComposeRun(Settings, Command, ComposeSettings); } } diff --git a/src/Cake.Docker.Tests/Compose/Run/DockerComposeRunTest.cs b/src/Cake.Docker.Tests/Compose/Run/DockerComposeRunTest.cs index 8355e86..af9c375 100644 --- a/src/Cake.Docker.Tests/Compose/Run/DockerComposeRunTest.cs +++ b/src/Cake.Docker.Tests/Compose/Run/DockerComposeRunTest.cs @@ -45,5 +45,19 @@ public void WhenTwoVolumesAreSet_CommandLineIsCorrect() Assert.That(actual.Args, Is.EqualTo("compose run --volume \"host:guest\" --volume \"host2:guest2\" cmd")); } + [Test] + public void WhenParallelFlagIsSet_CommandLineIsCorrect() + { + var fixture = new DockerComposeRunFixture + { + ComposeSettings = new DockerComposeSettings { Parallel = 2, }, + Command = "cmd", + Settings = new DockerComposeRunSettings { Entrypoint = "somepoint" }, + }; + + var actual = fixture.Run(); + + Assert.That(actual.Args, Is.EqualTo("compose --parallel 2 run --entrypoint \"somepoint\" cmd")); + } } } diff --git a/src/Cake.Docker.Tests/Compose/Up/DockerComposeUpFixture.cs b/src/Cake.Docker.Tests/Compose/Up/DockerComposeUpFixture.cs index 394fec6..4da6923 100644 --- a/src/Cake.Docker.Tests/Compose/Up/DockerComposeUpFixture.cs +++ b/src/Cake.Docker.Tests/Compose/Up/DockerComposeUpFixture.cs @@ -1,43 +1,16 @@ -using Cake.Core; -using Cake.Core.Configuration; -using Cake.Core.Diagnostics; -using Cake.Core.IO; -using Cake.Testing.Fixtures; -using System; +using Cake.Docker.Tests.Compose; -namespace Cake.Docker.Tests.Up +namespace Cake.Docker.Tests.Up; + +public class DockerComposeUpFixture : DockerComposeFixture { - public class DockerComposeUpFixture : ToolFixture, ICakeContext + public string Service { get; set; } + protected override void RunTool() { - public string Service { get; set; } - - IFileSystem ICakeContext.FileSystem => FileSystem; - - ICakeEnvironment ICakeContext.Environment => Environment; - - public ICakeLog Log => Log; - - ICakeArguments ICakeContext.Arguments => throw new NotImplementedException(); - - IProcessRunner ICakeContext.ProcessRunner => ProcessRunner; - - public IRegistry Registry => Registry; - - public ICakeDataResolver Data => throw new NotImplementedException(); - - ICakeConfiguration ICakeContext.Configuration => throw new NotImplementedException(); - - public DockerComposeUpFixture(): base("docker") - { - ProcessRunner.Process.SetStandardOutput(Array.Empty()); - } - protected override void RunTool() + this.DockerComposeUp(Settings, ComposeSettings, Service); + if(string.IsNullOrEmpty(Service)) { - this.DockerComposeUp(Settings, Service); - if(string.IsNullOrEmpty(Service)) - { - this.DockerComposeUp(Settings); - } + this.DockerComposeUp(Settings, ComposeSettings); } } } diff --git a/src/Cake.Docker.Tests/Compose/Up/DockerComposeUpTest.cs b/src/Cake.Docker.Tests/Compose/Up/DockerComposeUpTest.cs index 54c7242..8f78168 100644 --- a/src/Cake.Docker.Tests/Compose/Up/DockerComposeUpTest.cs +++ b/src/Cake.Docker.Tests/Compose/Up/DockerComposeUpTest.cs @@ -70,5 +70,18 @@ public void WhenWaitTimeoutIsSet_CommandLineIsCorrect() Assert.That(actual.Args, Is.EqualTo("compose up --wait-timeout 1")); } + [Test] + public void WhenParallelFlagIsSet_CommandLineIsCorrect() + { + var fixture = new DockerComposeUpFixture + { + ComposeSettings = new DockerComposeSettings { Parallel = 2, }, + Settings = new DockerComposeUpSettings { WaitTimeout = 1 }, + }; + + var actual = fixture.Run(); + + Assert.That(actual.Args, Is.EqualTo("compose --parallel 2 up --wait-timeout 1")); + } } } diff --git a/src/Cake.Docker/BuildX/Build/args.txt b/src/Cake.Docker/BuildX/Build/args.txt index 3ce8e9c..64e19d6 100644 --- a/src/Cake.Docker/BuildX/Build/args.txt +++ b/src/Cake.Docker/BuildX/Build/args.txt @@ -3,6 +3,9 @@ --allow strings Allow extra privileged entitlement (e.g., "network.host", "security.insecure") + --annotation stringArray Add annotation to the image + --attest stringArray Attestation parameters (format: + "type=sbom,generator=image") --build-arg stringArray Set build-time variables --build-context stringArray Additional build contexts (e.g., name=path) @@ -13,7 +16,8 @@ --cache-to stringArray Cache export destinations (e.g., "user/app:cache", "type=local,dest=path/to/dir") - --cgroup-parent string Optional parent cgroup for the container + --cgroup-parent string Set the parent cgroup for the "RUN" + instructions during build -f, --file string Name of the Dockerfile (default: "PATH/Dockerfile") --iidfile string Write the image ID to the file @@ -32,11 +36,13 @@ ("auto", "plain", "tty"). Use plain to show container output (default "auto") + --provenance string Shorthand for "--attest=type=provenance" --pull Always attempt to pull all referenced images --push Shorthand for "--output=type=registry" -q, --quiet Suppress the build output and print image ID on success + --sbom string Shorthand for "--attest=type=sbom" --secret stringArray Secret to expose to the build (format: "id=mysecret[,src=/local/secret]") diff --git a/src/Cake.Docker/Compose/Build/Docker.Aliases.ComposeBuild.cs b/src/Cake.Docker/Compose/Build/Docker.Aliases.ComposeBuild.cs index a58f25b..6c0832f 100644 --- a/src/Cake.Docker/Compose/Build/Docker.Aliases.ComposeBuild.cs +++ b/src/Cake.Docker/Compose/Build/Docker.Aliases.ComposeBuild.cs @@ -7,29 +7,22 @@ namespace Cake.Docker // Contains functionality for working with docker-compose build command. partial class DockerAliases { - /// - /// Runs docker-compose build with default settings. - /// - /// The context. - /// The list of services. - [CakeMethodAlias] - public static void DockerComposeBuild(this ICakeContext context, params string[] services) - { - DockerComposeBuild(context, new DockerComposeBuildSettings(), services); - } - /// /// Runs docker-compose build given . /// /// The context. /// The list of services. + /// Compose settings /// The settings. [CakeMethodAlias] - public static void DockerComposeBuild(this ICakeContext context, DockerComposeBuildSettings settings, params string[] services) + public static void DockerComposeBuild(this ICakeContext context, + DockerComposeBuildSettings settings, + DockerComposeSettings? composeSettings = null, + params string[] services) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose build", settings ?? new DockerComposeBuildSettings(), services); + runner.Run("compose", composeSettings ?? new DockerComposeSettings(), "build", settings, services); } } diff --git a/src/Cake.Docker/Compose/Build/DockerComposeBuildSettings.cs b/src/Cake.Docker/Compose/Build/DockerComposeBuildSettings.cs index a8778c1..2242233 100644 --- a/src/Cake.Docker/Compose/Build/DockerComposeBuildSettings.cs +++ b/src/Cake.Docker/Compose/Build/DockerComposeBuildSettings.cs @@ -1,50 +1,48 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose build. +/// +public sealed class DockerComposeBuildSettings : AutoToolSettings { - /// - /// Settings for docker compose build. - /// - public sealed class DockerComposeBuildSettings : DockerComposeSettings - { - /// - /// Set build-time variables for services. - /// - [AutoProperty(AutoArrayType = AutoArrayType.List)] - public string[] BuildArg { get; set; } - /// - /// Set builder to use. - /// - public string Builder { get; set; } - /// - /// Set memory limit for the build container. - /// Not supported by BuildKit. - /// - public bool Memory { get; set; } - /// - /// Do not use cache when building the image - /// - public bool NoCache { get; set; } - /// - /// Always attempt to pull a newer version of - /// the image. - /// - public bool Pull { get; set; } - /// - /// Push service images. - /// - public bool Push { get; set; } - /// - /// Don't print anything to STDOUT - /// - public bool Quiet { get; set; } - /// - /// Set SSH authentications used when - /// building service images. (use 'default' - /// for using your default SSH Agent) - /// - public string Ssh { get; set; } - /// - /// Also build dependencies (transitively). - /// - public bool WithDependencies { get; set; } - } -} \ No newline at end of file + /// + /// Set build-time variables for services. + /// + [AutoProperty(AutoArrayType=AutoArrayType.List)] + public string[]? BuildArg { get; set; } + /// + /// Set builder to use. + /// + public string? Builder { get; set; } + /// + /// Set memory limit for the build container. + /// Not supported by BuildKit. + /// + public int? Memory { get; set; } + /// + /// Do not use cache when building the image + /// + public bool? NoCache { get; set; } + /// + /// Always attempt to pull a newer version of + /// the image. + /// + public bool? Pull { get; set; } + /// + /// Push service images. + /// + public bool? Push { get; set; } + /// + /// Don't print anything to STDOUT + /// + public bool? Quiet { get; set; } + /// + /// Set SSH authentications used when + /// building service images. (use 'default' + /// for using your default SSH Agent) + /// + public string? Ssh { get; set; } + /// + /// Also build dependencies (transitively). + /// + public bool? WithDependencies { get; set; } +} diff --git a/src/Cake.Docker/Compose/Cp/Docker.Aliases.ComposeCp.cs b/src/Cake.Docker/Compose/Cp/Docker.Aliases.ComposeCp.cs index 0a6d391..948c90d 100644 --- a/src/Cake.Docker/Compose/Cp/Docker.Aliases.ComposeCp.cs +++ b/src/Cake.Docker/Compose/Cp/Docker.Aliases.ComposeCp.cs @@ -26,7 +26,8 @@ public static void DockerComposeCp(this ICakeContext context, string source, str /// Destination path. /// The settings. [CakeMethodAlias] - public static void DockerComposeCp(this ICakeContext context, string source, string destination, DockerComposeCpSettings settings) + public static void DockerComposeCp(this ICakeContext context, string source, string destination, DockerComposeCpSettings settings, + DockerComposeSettings? composeSettings = null) { ArgumentNullException.ThrowIfNull(context); if (string.IsNullOrEmpty(source)) @@ -38,7 +39,9 @@ public static void DockerComposeCp(this ICakeContext context, string source, str throw new ArgumentNullException(nameof(destination)); } var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose cp", settings ?? new DockerComposeCpSettings(), new[] { source, destination }); + runner.Run( + "compose", composeSettings ?? new DockerComposeSettings(), + "cp", settings ?? new DockerComposeCpSettings(), new[] { source, destination }); } } } diff --git a/src/Cake.Docker/Compose/Cp/DockerComposeCpSettings.cs b/src/Cake.Docker/Compose/Cp/DockerComposeCpSettings.cs index c74c988..ad646a2 100644 --- a/src/Cake.Docker/Compose/Cp/DockerComposeCpSettings.cs +++ b/src/Cake.Docker/Compose/Cp/DockerComposeCpSettings.cs @@ -1,21 +1,19 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose cp. +/// +public sealed class DockerComposeCpSettings : AutoToolSettings { - /// - /// Settings for docker compose cp. - /// - public sealed class DockerComposeCpSettings : DockerComposeSettings - { - /// - /// Archive mode (copy all uid/gid information) - /// - public bool? Archive { get; set; } - /// - /// Always follow symbol link in SRC_PATH - /// - public bool? FollowLink { get; set; } - /// - /// index of the container if service has multiple replicas - /// - public int? Index { get; set; } - } -} \ No newline at end of file + /// + /// Archive mode (copy all uid/gid information) + /// + public bool? Archive { get; set; } + /// + /// Always follow symbol link in SRC_PATH + /// + public bool? FollowLink { get; set; } + /// + /// index of the container if service has multiple replicas + /// + public int? Index { get; set; } +} diff --git a/src/Cake.Docker/Compose/Create/Docker.Aliases.ComposeCreate.cs b/src/Cake.Docker/Compose/Create/Docker.Aliases.ComposeCreate.cs index 77d3222..9803624 100644 --- a/src/Cake.Docker/Compose/Create/Docker.Aliases.ComposeCreate.cs +++ b/src/Cake.Docker/Compose/Create/Docker.Aliases.ComposeCreate.cs @@ -15,7 +15,7 @@ partial class DockerAliases [CakeMethodAlias] public static void DockerComposeCreate(this ICakeContext context, params string[] services) { - DockerComposeCreate(context, new DockerComposeCreateSettings(), services); + DockerComposeCreate(context, new DockerComposeCreateSettings(), null, services); } /// @@ -25,11 +25,17 @@ public static void DockerComposeCreate(this ICakeContext context, params string[ /// The list of services. /// The settings. [CakeMethodAlias] - public static void DockerComposeCreate(this ICakeContext context, DockerComposeCreateSettings settings, params string[] services) + public static void DockerComposeCreate(this ICakeContext context, + DockerComposeCreateSettings settings, + DockerComposeSettings? composeSettings = null, + params string[] services) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose create", settings ?? new DockerComposeCreateSettings(), services); + runner.Run( + "compose", composeSettings ?? new DockerComposeSettings(), + "create", settings ?? new DockerComposeCreateSettings(), + services); } } diff --git a/src/Cake.Docker/Compose/Create/DockerComposeCreateSettings.cs b/src/Cake.Docker/Compose/Create/DockerComposeCreateSettings.cs index 12c6510..4c44f03 100644 --- a/src/Cake.Docker/Compose/Create/DockerComposeCreateSettings.cs +++ b/src/Cake.Docker/Compose/Create/DockerComposeCreateSettings.cs @@ -1,43 +1,41 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose create. +/// +public sealed class DockerComposeCreateSettings : AutoToolSettings { - /// - /// Settings for docker compose create. - /// - public sealed class DockerComposeCreateSettings : DockerComposeSettings - { - /// - /// Build images before starting containers. - /// - public bool? Build { get; set; } - /// - /// Recreate containers even if their configuration - /// and image haven't changed. - /// - public bool? ForceRecreate { get; set; } - /// - /// Don't build an image, even if it's policy. - /// - public bool? NoBuild { get; set; } - /// - /// If containers already exist, don't recreate - /// them. Incompatible with --force-recreate. - /// - public bool? NoRecreate { get; set; } - /// - /// Pull image before running - /// ("always"|"missing"|"never"|"build") (default - /// "policy") - /// - public string? Pull { get; set; } - /// - /// Remove containers for services not defined in - /// the Compose file. - /// - public bool? RemoveOrphans { get; set; } - /// - /// Scale SERVICE to NUM instances. Overrides the - /// scale setting in the Compose file if present. - /// - public bool? Scale { get; set; } - } -} \ No newline at end of file + /// + /// Build images before starting containers. + /// + public bool? Build { get; set; } + /// + /// Recreate containers even if their configuration + /// and image haven't changed. + /// + public bool? ForceRecreate { get; set; } + /// + /// Don't build an image, even if it's policy. + /// + public bool? NoBuild { get; set; } + /// + /// If containers already exist, don't recreate + /// them. Incompatible with --force-recreate. + /// + public bool? NoRecreate { get; set; } + /// + /// Pull image before running + /// ("always"|"missing"|"never"|"build") (default + /// "policy") + /// + public string? Pull { get; set; } + /// + /// Remove containers for services not defined in + /// the Compose file. + /// + public bool? RemoveOrphans { get; set; } + /// + /// Scale SERVICE to NUM instances. Overrides the + /// scale setting in the Compose file if present. + /// + public bool? Scale { get; set; } +} diff --git a/src/Cake.Docker/Compose/DockerComposeSettings.cs b/src/Cake.Docker/Compose/DockerComposeSettings.cs index b1a53c7..c0012c4 100644 --- a/src/Cake.Docker/Compose/DockerComposeSettings.cs +++ b/src/Cake.Docker/Compose/DockerComposeSettings.cs @@ -10,7 +10,7 @@ public class DockerComposeSettings : AutoToolSettings /// characters ("never"|"always"|"auto") /// (default "auto") /// - public string Ansi { get; set; } + public string? Ansi { get; set; } /// /// Run compose in backward compatibility mode /// @@ -23,12 +23,12 @@ public class DockerComposeSettings : AutoToolSettings /// Specify an alternate environment file. /// [AutoProperty(AutoArrayType = AutoArrayType.List)] - public string[] EnvFile { get; set; } + public string[]? EnvFile { get; set; } /// /// Compose configuration files /// [AutoProperty(AutoArrayType = AutoArrayType.List)] - public string[] File { get; set; } + public string[]? File { get; set; } /// /// Control max parallelism, -1 for /// unlimited (default -1) @@ -38,21 +38,21 @@ public class DockerComposeSettings : AutoToolSettings /// Specify a profile to enable /// [AutoProperty(AutoArrayType = AutoArrayType.List)] - public string[] Profile { get; set; } + public string[]? Profile { get; set; } /// /// Set type of progress output (auto, /// tty, plain, quiet) (default "auto") /// - public string Progress { get; set; } + public string? Progress { get; set; } /// /// Specify an alternate working directory /// (default: the path of the, first /// specified, Compose file) /// - public string ProjectDirectory { get; set; } + public string? ProjectDirectory { get; set; } /// /// Project name /// - public string ProjectName { get; set; } + public string? ProjectName { get; set; } } } \ No newline at end of file diff --git a/src/Cake.Docker/Compose/Down/Docker.Aliases.ComposeDown.cs b/src/Cake.Docker/Compose/Down/Docker.Aliases.ComposeDown.cs index 2e76ff4..3370b17 100644 --- a/src/Cake.Docker/Compose/Down/Docker.Aliases.ComposeDown.cs +++ b/src/Cake.Docker/Compose/Down/Docker.Aliases.ComposeDown.cs @@ -23,11 +23,15 @@ public static void DockerComposeDown(this ICakeContext context) /// The context. /// The settings. [CakeMethodAlias] - public static void DockerComposeDown(this ICakeContext context, DockerComposeDownSettings settings) + public static void DockerComposeDown(this ICakeContext context, DockerComposeDownSettings settings, + DockerComposeSettings? composeSettings = null) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose down", settings ?? new DockerComposeDownSettings(), Array.Empty()); + runner.Run( + "compose", composeSettings ?? new DockerComposeSettings(), + "down", settings ?? new DockerComposeDownSettings(), + Array.Empty()); } } diff --git a/src/Cake.Docker/Compose/Down/DockerComposeDownSettings.cs b/src/Cake.Docker/Compose/Down/DockerComposeDownSettings.cs index e42ccdf..273fc94 100644 --- a/src/Cake.Docker/Compose/Down/DockerComposeDownSettings.cs +++ b/src/Cake.Docker/Compose/Down/DockerComposeDownSettings.cs @@ -1,30 +1,28 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose down. +/// +public sealed class DockerComposeDownSettings : AutoToolSettings { - /// - /// Settings for docker compose down. - /// - public sealed class DockerComposeDownSettings : DockerComposeSettings - { - /// - /// Remove containers for services not defined in - /// the Compose file. - /// - public bool? RemoveOrphans { get; set; } - /// - /// Remove images used by services. "local" remove - /// only images that don't have a custom tag - /// ("local"|"all") - /// - public string? Rmi { get; set; } - /// - /// Specify a shutdown timeout in seconds - /// - public int? Timeout { get; set; } - /// - /// Remove named volumes declared in the "volumes" - /// section of the Compose file and anonymous - /// volumes attached to containers. - /// - public bool? Volumes { get; set; } - } -} \ No newline at end of file + /// + /// Remove containers for services not defined in + /// the Compose file. + /// + public bool? RemoveOrphans { get; set; } + /// + /// Remove images used by services. "local" remove + /// only images that don't have a custom tag + /// ("local"|"all") + /// + public string? Rmi { get; set; } + /// + /// Specify a shutdown timeout in seconds + /// + public int? Timeout { get; set; } + /// + /// Remove named volumes declared in the "volumes" + /// section of the Compose file and anonymous + /// volumes attached to containers. + /// + public bool? Volumes { get; set; } +} diff --git a/src/Cake.Docker/Compose/Exec/Docker.Aliases.ComposeExec.cs b/src/Cake.Docker/Compose/Exec/Docker.Aliases.ComposeExec.cs index 1c75b53..fdb5057 100644 --- a/src/Cake.Docker/Compose/Exec/Docker.Aliases.ComposeExec.cs +++ b/src/Cake.Docker/Compose/Exec/Docker.Aliases.ComposeExec.cs @@ -18,7 +18,7 @@ partial class DockerAliases [CakeMethodAlias] public static void DockerComposeExec(this ICakeContext context, string service, string command, params string[] args) { - DockerComposeExec(context, new DockerComposeExecSettings(), service, command, args); + DockerComposeExec(context, new DockerComposeExecSettings(), service, command, composeSettings: null, args); } /// @@ -30,7 +30,11 @@ public static void DockerComposeExec(this ICakeContext context, string service, /// The arguments. /// The settings. [CakeMethodAlias] - public static void DockerComposeExec(this ICakeContext context, DockerComposeExecSettings settings, string service, string command, params string[] args) + public static void DockerComposeExec(this ICakeContext context, + DockerComposeExecSettings settings, + string service, string command, + DockerComposeSettings? composeSettings = null, + params string[] args) { ArgumentNullException.ThrowIfNull(context); if (string.IsNullOrEmpty(service)) @@ -51,7 +55,9 @@ public static void DockerComposeExec(this ICakeContext context, DockerComposeExe arguments.AddRange(args); } - runner.Run("compose exec", settings ?? new DockerComposeExecSettings(), arguments.ToArray()); + runner.Run("compose", composeSettings ?? new DockerComposeSettings(), + "exec", settings ?? new DockerComposeExecSettings(), + arguments.ToArray()); } } } diff --git a/src/Cake.Docker/Compose/Exec/DockerComposeExecSettings.cs b/src/Cake.Docker/Compose/Exec/DockerComposeExecSettings.cs index 850ee7f..0a9a6b4 100644 --- a/src/Cake.Docker/Compose/Exec/DockerComposeExecSettings.cs +++ b/src/Cake.Docker/Compose/Exec/DockerComposeExecSettings.cs @@ -1,43 +1,41 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose exec. +/// +public sealed class DockerComposeExecSettings : AutoToolSettings { - /// - /// Settings for docker compose exec. - /// - public sealed class DockerComposeExecSettings : DockerComposeSettings - { - /// - /// Detached mode: Run command in the - /// background. - /// - public bool? Detach { get; set; } - /// - /// Set environment variables - /// - [AutoProperty(AutoArrayType = AutoArrayType.List)] - public string[]? Env { get; set; } - /// - /// index of the container if service - /// has multiple replicas - /// - public int? Index { get; set; } - /// - /// compose exec Disable pseudo-TTY allocation. By - /// default docker compose exec - /// allocates a TTY. - /// - public bool? NoTTY { get; set; } - /// - /// Give extended privileges to the process. - /// - public bool? Privileged { get; set; } - /// - /// Run the command as this user. - /// - public string? User { get; set; } - /// - /// Path to workdir directory for this - /// command. - /// - public string? Workdir { get; set; } - } -} \ No newline at end of file + /// + /// Detached mode: Run command in the + /// background. + /// + public bool? Detach { get; set; } + /// + /// Set environment variables + /// + [AutoProperty(AutoArrayType=AutoArrayType.List)] + public string[]? Env { get; set; } + /// + /// index of the container if service + /// has multiple replicas + /// + public int? Index { get; set; } + /// + /// compose exec Disable pseudo-TTY allocation. By + /// default docker compose exec + /// allocates a TTY. + /// + public bool? NoTTY { get; set; } + /// + /// Give extended privileges to the process. + /// + public bool? Privileged { get; set; } + /// + /// Run the command as this user. + /// + public string? User { get; set; } + /// + /// Path to workdir directory for this + /// command. + /// + public string? Workdir { get; set; } +} diff --git a/src/Cake.Docker/Compose/Kill/Docker.Aliases.ComposeKill.cs b/src/Cake.Docker/Compose/Kill/Docker.Aliases.ComposeKill.cs index a7f0cef..ac17e6d 100644 --- a/src/Cake.Docker/Compose/Kill/Docker.Aliases.ComposeKill.cs +++ b/src/Cake.Docker/Compose/Kill/Docker.Aliases.ComposeKill.cs @@ -23,11 +23,15 @@ public static void DockerComposeKill(this ICakeContext context) /// The context. /// The settings. [CakeMethodAlias] - public static void DockerComposeKill(this ICakeContext context, DockerComposeKillSettings settings) + public static void DockerComposeKill(this ICakeContext context, DockerComposeKillSettings settings, + DockerComposeSettings? composeSettings = null) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose kill", settings ?? new DockerComposeKillSettings(), Array.Empty()); + runner.Run( + "compose", composeSettings ?? new DockerComposeSettings(), + "kill", settings ?? new DockerComposeKillSettings(), + Array.Empty()); } } diff --git a/src/Cake.Docker/Compose/Kill/DockerComposeKillSettings.cs b/src/Cake.Docker/Compose/Kill/DockerComposeKillSettings.cs index d307ad2..62a8cda 100644 --- a/src/Cake.Docker/Compose/Kill/DockerComposeKillSettings.cs +++ b/src/Cake.Docker/Compose/Kill/DockerComposeKillSettings.cs @@ -1,18 +1,16 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose kill. +/// +public sealed class DockerComposeKillSettings : AutoToolSettings { - /// - /// Settings for docker compose kill. - /// - public sealed class DockerComposeKillSettings : DockerComposeSettings - { - /// - /// Remove containers for services not defined in - /// the Compose file. - /// - public bool? RemoveOrphans { get; set; } - /// - /// SIGNAL to send to the container. (default "SIGKILL") - /// - public string? Signal { get; set; } - } -} \ No newline at end of file + /// + /// Remove containers for services not defined in + /// the Compose file. + /// + public bool? RemoveOrphans { get; set; } + /// + /// SIGNAL to send to the container. (default "SIGKILL") + /// + public string? Signal { get; set; } +} diff --git a/src/Cake.Docker/Compose/Logs/Docker.Aliases.ComposeLogs.cs b/src/Cake.Docker/Compose/Logs/Docker.Aliases.ComposeLogs.cs index 547b86f..d07cb0b 100644 --- a/src/Cake.Docker/Compose/Logs/Docker.Aliases.ComposeLogs.cs +++ b/src/Cake.Docker/Compose/Logs/Docker.Aliases.ComposeLogs.cs @@ -25,11 +25,15 @@ public static IEnumerable DockerComposeLogs(this ICakeContext context) /// The context. /// The settings. [CakeMethodAlias] - public static IEnumerable DockerComposeLogs(this ICakeContext context, DockerComposeLogsSettings settings) + public static IEnumerable DockerComposeLogs(this ICakeContext context, DockerComposeLogsSettings settings, + DockerComposeSettings? composeSettings = null) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - return runner.RunWithResult("compose logs", settings ?? new DockerComposeLogsSettings(), r => r.ToArray()); + return runner.RunWithResult( + "compose",composeSettings ?? new DockerComposeSettings(), + "logs", settings ?? new DockerComposeLogsSettings(), + r => r.ToArray()); } } diff --git a/src/Cake.Docker/Compose/Logs/DockerComposeLogsSettings.cs b/src/Cake.Docker/Compose/Logs/DockerComposeLogsSettings.cs index 35e72f4..c504fb8 100644 --- a/src/Cake.Docker/Compose/Logs/DockerComposeLogsSettings.cs +++ b/src/Cake.Docker/Compose/Logs/DockerComposeLogsSettings.cs @@ -1,47 +1,45 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose logs. +/// +public sealed class DockerComposeLogsSettings : AutoToolSettings { - /// - /// Settings for docker compose logs. - /// - public sealed class DockerComposeLogsSettings : DockerComposeSettings - { - /// - /// Follow log output. - /// - public bool? Follow { get; set; } - /// - /// index of the container if service has multiple - /// replicas - /// - public int? Index { get; set; } - /// - /// Produce monochrome output. - /// - public bool? NoColor { get; set; } - /// - /// Don't print prefix in logs. - /// - public bool? NoLogPrefix { get; set; } - /// - /// Show logs since timestamp (e.g. - /// 2013-01-02T13:23:37Z) or relative (e.g. 42m for - /// 42 minutes) - /// - public string? Since { get; set; } - /// - /// Number of lines to show from the end of the logs - /// for each container. (default "all") - /// - public string? Tail { get; set; } - /// - /// Show timestamps. - /// - public bool? Timestamps { get; set; } - /// - /// Show logs before a timestamp (e.g. - /// 2013-01-02T13:23:37Z) or relative (e.g. 42m for - /// 42 minutes) - /// - public string? Until { get; set; } - } -} \ No newline at end of file + /// + /// Follow log output. + /// + public bool? Follow { get; set; } + /// + /// index of the container if service has multiple + /// replicas + /// + public int? Index { get; set; } + /// + /// Produce monochrome output. + /// + public bool? NoColor { get; set; } + /// + /// Don't print prefix in logs. + /// + public bool? NoLogPrefix { get; set; } + /// + /// Show logs since timestamp (e.g. + /// 2013-01-02T13:23:37Z) or relative (e.g. 42m for + /// 42 minutes) + /// + public string? Since { get; set; } + /// + /// Number of lines to show from the end of the logs + /// for each container. (default "all") + /// + public string? Tail { get; set; } + /// + /// Show timestamps. + /// + public bool? Timestamps { get; set; } + /// + /// Show logs before a timestamp (e.g. + /// 2013-01-02T13:23:37Z) or relative (e.g. 42m for + /// 42 minutes) + /// + public string? Until { get; set; } +} diff --git a/src/Cake.Docker/Compose/Pause/Docker.Aliases.ComposePause.cs b/src/Cake.Docker/Compose/Pause/Docker.Aliases.ComposePause.cs index 00ddaad..da36312 100644 --- a/src/Cake.Docker/Compose/Pause/Docker.Aliases.ComposePause.cs +++ b/src/Cake.Docker/Compose/Pause/Docker.Aliases.ComposePause.cs @@ -15,7 +15,7 @@ partial class DockerAliases [CakeMethodAlias] public static void DockerComposePause(this ICakeContext context, params string[] services) { - DockerComposePause(context, new DockerComposeSettings(), services); + DockerComposePause(context, new DockerComposeSettings(), null, services); } /// /// Runs docker-compose pause. @@ -24,11 +24,16 @@ public static void DockerComposePause(this ICakeContext context, params string[] /// The settings. /// The list of services. [CakeMethodAlias] - public static void DockerComposePause(this ICakeContext context, DockerComposeSettings settings, params string[] services) + public static void DockerComposePause(this ICakeContext context, DockerComposeSettings settings, + DockerComposeSettings? composeSettings = null, + params string[] services) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose pause", settings ?? new DockerComposeSettings(), services); + runner.Run( + "compose", composeSettings ?? new (), + "pause", settings ?? new DockerComposeSettings(), + services); } } } \ No newline at end of file diff --git a/src/Cake.Docker/Compose/Port/Docker.Aliases.ComposePort.cs b/src/Cake.Docker/Compose/Port/Docker.Aliases.ComposePort.cs index f221078..2e25e40 100644 --- a/src/Cake.Docker/Compose/Port/Docker.Aliases.ComposePort.cs +++ b/src/Cake.Docker/Compose/Port/Docker.Aliases.ComposePort.cs @@ -27,13 +27,17 @@ public static void DockerComposePort(this ICakeContext context, string service, /// The service. /// The private port of the container. [CakeMethodAlias] - public static IEnumerable DockerComposePort(this ICakeContext context, DockerComposePortSettings settings, string service, int port) + public static IEnumerable DockerComposePort(this ICakeContext context, DockerComposePortSettings settings, string service, int port + , DockerComposeSettings? composeSettings = null) { ArgumentNullException.ThrowIfNull(context); ArgumentNullException.ThrowIfNull(service); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); var arguments = new List { service, port.ToString() }; - return runner.RunWithResult("compose port", settings ?? new DockerComposePortSettings(), r => r.ToArray(), arguments.ToArray()); + return runner.RunWithResult( + "compose", composeSettings ?? new(), + "port", settings ?? new(), + r => r.ToArray(), arguments.ToArray()); } } } \ No newline at end of file diff --git a/src/Cake.Docker/Compose/Ps/Docker.Aliases.ComposePs.cs b/src/Cake.Docker/Compose/Ps/Docker.Aliases.ComposePs.cs index fcb4209..0b26b11 100644 --- a/src/Cake.Docker/Compose/Ps/Docker.Aliases.ComposePs.cs +++ b/src/Cake.Docker/Compose/Ps/Docker.Aliases.ComposePs.cs @@ -16,7 +16,7 @@ public partial class DockerAliases /// The list of services. [CakeMethodAlias] public static void DockerComposePs(this ICakeContext context, params string[] services) => - DockerComposePs(context, new DockerComposePsSettings(), services); + DockerComposePs(context, new DockerComposePsSettings(), null, services); /// /// Runs docker-compose ps. @@ -25,11 +25,16 @@ public static void DockerComposePs(this ICakeContext context, params string[] se /// The settings. /// The list of services. [CakeMethodAlias] - public static IEnumerable DockerComposePs(this ICakeContext context, DockerComposePsSettings settings, params string[] services) + public static IEnumerable DockerComposePs(this ICakeContext context, DockerComposePsSettings settings, + DockerComposeSettings? composeSettings = null, + params string[] services) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - var result = runner.RunWithResult("compose ps", settings ?? new DockerComposePsSettings(), r => r.ToArray(), services); + var result = runner.RunWithResult( + "compose", composeSettings ?? new(), + "ps", settings ?? new (), + r => r.ToArray(), services); return result; } } diff --git a/src/Cake.Docker/Compose/Ps/DockerComposePsSettings.cs b/src/Cake.Docker/Compose/Ps/DockerComposePsSettings.cs index 4b3115b..2d2ba45 100644 --- a/src/Cake.Docker/Compose/Ps/DockerComposePsSettings.cs +++ b/src/Cake.Docker/Compose/Ps/DockerComposePsSettings.cs @@ -1,59 +1,57 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose ps. +/// +public sealed class DockerComposePsSettings : AutoToolSettings { + /// + /// Show all stopped containers (including those + /// created by the run command) + /// + public bool? All { get; set; } /// - /// Settings for docker compose ps. + /// Filter services by a property (supported + /// filters: status). /// - public sealed class DockerComposePsSettings : DockerComposeSettings - { - /// - /// Show all stopped containers (including those - /// created by the run command) - /// - public bool? All { get; set; } - /// - /// Filter services by a property (supported - /// filters: status). - /// - [AutoProperty(Format = "--filter {1}")] - public string[]? Filter { get; set; } - /// - /// Format output using a custom template: - /// 'table': Print output in table - /// format with column headers (default) - /// 'table TEMPLATE': Print output in table - /// format using the given Go template - /// 'json': Print in JSON format - /// 'TEMPLATE': Print output using the - /// given Go template. - /// Refer to - /// https://docs.docker.com/go/formatting/ for - /// more information about formatting output - /// with templates (default "table") - /// - public string? Format { get; set; } - /// - /// Don't truncate output - /// - public bool? NoTrunc { get; set; } - /// - /// Include orphaned services (not declared by - /// project) (default true) - /// - public bool? Orphans { get; set; } - /// - /// Only display IDs - /// - public bool? Quiet { get; set; } - /// - /// Display services - /// - public bool? Services { get; set; } - /// - /// Filter services by status. Values: [paused | - /// restarting | removing | running | dead | - /// created | exited] - /// - [AutoProperty(AutoArrayType = AutoArrayType.List)] - public string[]? Status { get; set; } - } -} \ No newline at end of file + [AutoProperty(Format = "--filter {1}")] + public string[]? Filter { get; set; } + /// + /// Format output using a custom template: + /// 'table': Print output in table + /// format with column headers (default) + /// 'table TEMPLATE': Print output in table + /// format using the given Go template + /// 'json': Print in JSON format + /// 'TEMPLATE': Print output using the + /// given Go template. + /// Refer to + /// https://docs.docker.com/go/formatting/ for + /// more information about formatting output + /// with templates (default "table") + /// + public string? Format { get; set; } + /// + /// Don't truncate output + /// + public bool? NoTrunc { get; set; } + /// + /// Include orphaned services (not declared by + /// project) (default true) + /// + public bool? Orphans { get; set; } + /// + /// Only display IDs + /// + public bool? Quiet { get; set; } + /// + /// Display services + /// + public bool? Services { get; set; } + /// + /// Filter services by status. Values: [paused | + /// restarting | removing | running | dead | + /// created | exited] + /// + [AutoProperty(AutoArrayType=AutoArrayType.List)] + public string[]? Status { get; set; } +} diff --git a/src/Cake.Docker/Compose/Pull/Docker.Aliases.ComposePull.cs b/src/Cake.Docker/Compose/Pull/Docker.Aliases.ComposePull.cs index 2cf8e50..ac0a713 100644 --- a/src/Cake.Docker/Compose/Pull/Docker.Aliases.ComposePull.cs +++ b/src/Cake.Docker/Compose/Pull/Docker.Aliases.ComposePull.cs @@ -15,7 +15,7 @@ partial class DockerAliases [CakeMethodAlias] public static void DockerComposePull(this ICakeContext context, params string[] services) { - DockerComposePull(context, new DockerComposePullSettings(), services); + DockerComposePull(context, new DockerComposePullSettings(), null, services); } /// @@ -25,11 +25,14 @@ public static void DockerComposePull(this ICakeContext context, params string[] /// The list of services. /// The settings. [CakeMethodAlias] - public static void DockerComposePull(this ICakeContext context, DockerComposePullSettings settings, params string[] services) + public static void DockerComposePull(this ICakeContext context, DockerComposePullSettings settings, + DockerComposeSettings? composeSettings = null, params string[] services) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose pull", settings ?? new DockerComposePullSettings(), services); + runner.Run("compose", composeSettings ?? new(), + "pull", settings ?? new(), + services); } } diff --git a/src/Cake.Docker/Compose/Pull/DockerComposePullSettings.cs b/src/Cake.Docker/Compose/Pull/DockerComposePullSettings.cs index b9d9b5d..a33f8b5 100644 --- a/src/Cake.Docker/Compose/Pull/DockerComposePullSettings.cs +++ b/src/Cake.Docker/Compose/Pull/DockerComposePullSettings.cs @@ -1,30 +1,28 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose pull. +/// +public sealed class DockerComposePullSettings : AutoToolSettings { - /// - /// Settings for docker compose pull. - /// - public sealed class DockerComposePullSettings : DockerComposeSettings - { - /// - /// Ignore images that can be built. - /// - public bool? IgnoreBuildable { get; set; } - /// - /// Pull what it can and ignores images with - /// pull failures. - /// - public bool? IgnorePullFailures { get; set; } - /// - /// Also pull services declared as dependencies. - /// - public bool? IncludeDeps { get; set; } - /// - /// Apply pull policy ("missing"|"always"). - /// - public string? Policy { get; set; } - /// - /// Pull without printing progress information. - /// - public bool? Quiet { get; set; } - } -} \ No newline at end of file + /// + /// Ignore images that can be built. + /// + public bool? IgnoreBuildable { get; set; } + /// + /// Pull what it can and ignores images with + /// pull failures. + /// + public bool? IgnorePullFailures { get; set; } + /// + /// Also pull services declared as dependencies. + /// + public bool? IncludeDeps { get; set; } + /// + /// Apply pull policy ("missing"|"always"). + /// + public string? Policy { get; set; } + /// + /// Pull without printing progress information. + /// + public bool? Quiet { get; set; } +} diff --git a/src/Cake.Docker/Compose/Push/Docker.Aliases.ComposePush.cs b/src/Cake.Docker/Compose/Push/Docker.Aliases.ComposePush.cs index 43dbfc8..fdf015c 100644 --- a/src/Cake.Docker/Compose/Push/Docker.Aliases.ComposePush.cs +++ b/src/Cake.Docker/Compose/Push/Docker.Aliases.ComposePush.cs @@ -15,7 +15,7 @@ partial class DockerAliases [CakeMethodAlias] public static void DockerComposePush(this ICakeContext context, params string[] services) { - DockerComposePush(context, new DockerComposePushSettings(), services); + DockerComposePush(context, new DockerComposePushSettings(), null, services); } /// @@ -25,11 +25,14 @@ public static void DockerComposePush(this ICakeContext context, params string[] /// The list of services. /// The settings. [CakeMethodAlias] - public static void DockerComposePush(this ICakeContext context, DockerComposePushSettings settings, params string[] services) + public static void DockerComposePush(this ICakeContext context, DockerComposePushSettings settings, + DockerComposeSettings? composeSettings = null, params string[] services) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose push", settings ?? new DockerComposePushSettings(), services); + runner.Run( + "compose", composeSettings ?? new(), + "push", settings ?? new (), services); } } diff --git a/src/Cake.Docker/Compose/Push/DockerComposePushSettings.cs b/src/Cake.Docker/Compose/Push/DockerComposePushSettings.cs index ceec379..934b99c 100644 --- a/src/Cake.Docker/Compose/Push/DockerComposePushSettings.cs +++ b/src/Cake.Docker/Compose/Push/DockerComposePushSettings.cs @@ -1,23 +1,21 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose push. +/// +public sealed class DockerComposePushSettings : AutoToolSettings { - /// - /// Settings for docker compose push. - /// - public sealed class DockerComposePushSettings : DockerComposeSettings - { - /// - /// Push what it can and ignores images with - /// push failures - /// - public bool? IgnorePushFailures { get; set; } - /// - /// Also push images of services declared as - /// dependencies - /// - public bool? IncludeDeps { get; set; } - /// - /// Push without printing progress information - /// - public bool? Quiet { get; set; } - } -} \ No newline at end of file + /// + /// Push what it can and ignores images with + /// push failures + /// + public bool? IgnorePushFailures { get; set; } + /// + /// Also push images of services declared as + /// dependencies + /// + public bool? IncludeDeps { get; set; } + /// + /// Push without printing progress information + /// + public bool? Quiet { get; set; } +} diff --git a/src/Cake.Docker/Compose/Restart/Docker.Aliases.ComposeRestart.cs b/src/Cake.Docker/Compose/Restart/Docker.Aliases.ComposeRestart.cs index 4b0ea21..5f70ddf 100644 --- a/src/Cake.Docker/Compose/Restart/Docker.Aliases.ComposeRestart.cs +++ b/src/Cake.Docker/Compose/Restart/Docker.Aliases.ComposeRestart.cs @@ -15,7 +15,7 @@ partial class DockerAliases [CakeMethodAlias] public static void DockerComposeRestart(this ICakeContext context, params string[] services) { - DockerComposeRestart(context, new DockerComposeRestartSettings(), services); + DockerComposeRestart(context, new DockerComposeRestartSettings(), null, services); } /// @@ -25,11 +25,15 @@ public static void DockerComposeRestart(this ICakeContext context, params string /// The list of services. /// The settings. [CakeMethodAlias] - public static void DockerComposeRestart(this ICakeContext context, DockerComposeRestartSettings settings, params string[] services) + public static void DockerComposeRestart(this ICakeContext context, DockerComposeRestartSettings settings, + DockerComposeSettings? composeSettings = null, + params string[] services) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose restart", settings ?? new DockerComposeRestartSettings(), services); + runner.Run( + "compose", composeSettings ?? new(), + "restart", settings ?? new (), services); } } diff --git a/src/Cake.Docker/Compose/Restart/DockerComposeRestartSettings.cs b/src/Cake.Docker/Compose/Restart/DockerComposeRestartSettings.cs index 8bf8182..998143d 100644 --- a/src/Cake.Docker/Compose/Restart/DockerComposeRestartSettings.cs +++ b/src/Cake.Docker/Compose/Restart/DockerComposeRestartSettings.cs @@ -1,17 +1,15 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose restart. +/// +public sealed class DockerComposeRestartSettings : AutoToolSettings { - /// - /// Settings for docker compose restart. - /// - public sealed class DockerComposeRestartSettings : DockerComposeSettings - { - /// - /// Don't restart dependent services. - /// - public bool? NoDeps { get; set; } - /// - /// Specify a shutdown timeout in seconds - /// - public int? Timeout { get; set; } - } -} \ No newline at end of file + /// + /// Don't restart dependent services. + /// + public bool? NoDeps { get; set; } + /// + /// Specify a shutdown timeout in seconds + /// + public int? Timeout { get; set; } +} diff --git a/src/Cake.Docker/Compose/Rm/Docker.Aliases.ComposeRm.cs b/src/Cake.Docker/Compose/Rm/Docker.Aliases.ComposeRm.cs index 5584208..3fe3b7d 100644 --- a/src/Cake.Docker/Compose/Rm/Docker.Aliases.ComposeRm.cs +++ b/src/Cake.Docker/Compose/Rm/Docker.Aliases.ComposeRm.cs @@ -15,7 +15,7 @@ partial class DockerAliases [CakeMethodAlias] public static void DockerComposeRm(this ICakeContext context, params string[] services) { - DockerComposeRm(context, new DockerComposeRmSettings(), services); + DockerComposeRm(context, new DockerComposeRmSettings(), null, services); } /// @@ -25,11 +25,16 @@ public static void DockerComposeRm(this ICakeContext context, params string[] se /// The list of services. /// The settings. [CakeMethodAlias] - public static void DockerComposeRm(this ICakeContext context, DockerComposeRmSettings settings, params string[] services) + public static void DockerComposeRm(this ICakeContext context, DockerComposeRmSettings settings, + DockerComposeSettings? composeSettings = null, + params string[] services) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose rm", settings ?? new DockerComposeRmSettings(), services); + runner.Run( + "compose", composeSettings ?? new(), + "rm", settings ?? new(), + services); } } diff --git a/src/Cake.Docker/Compose/Rm/DockerComposeRmSettings.cs b/src/Cake.Docker/Compose/Rm/DockerComposeRmSettings.cs index 14c6758..908affe 100644 --- a/src/Cake.Docker/Compose/Rm/DockerComposeRmSettings.cs +++ b/src/Cake.Docker/Compose/Rm/DockerComposeRmSettings.cs @@ -1,21 +1,19 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose rm. +/// +public sealed class DockerComposeRmSettings : AutoToolSettings { - /// - /// Settings for docker compose rm. - /// - public sealed class DockerComposeRmSettings : DockerComposeSettings - { - /// - /// Don't ask to confirm removal - /// - public bool? Force { get; set; } - /// - /// Stop the containers, if required, before removing - /// - public bool? Stop { get; set; } - /// - /// Remove any anonymous volumes attached to containers - /// - public bool? Volumes { get; set; } - } -} \ No newline at end of file + /// + /// Don't ask to confirm removal + /// + public bool? Force { get; set; } + /// + /// Stop the containers, if required, before removing + /// + public bool? Stop { get; set; } + /// + /// Remove any anonymous volumes attached to containers + /// + public bool? Volumes { get; set; } +} diff --git a/src/Cake.Docker/Compose/Run/Docker.Aliases.ComposeRun.cs b/src/Cake.Docker/Compose/Run/Docker.Aliases.ComposeRun.cs index 913c7ea..9618a4a 100644 --- a/src/Cake.Docker/Compose/Run/Docker.Aliases.ComposeRun.cs +++ b/src/Cake.Docker/Compose/Run/Docker.Aliases.ComposeRun.cs @@ -17,7 +17,7 @@ partial class DockerAliases [CakeMethodAlias] public static void DockerComposeRun(this ICakeContext context, string service, params string[] args) { - DockerComposeRun(context, new DockerComposeRunSettings(), service, null, args); + DockerComposeRun(context, new DockerComposeRunSettings(), service, null, composeSettings: null, args); } /// /// Runs docker-compose run with default settings. @@ -29,7 +29,7 @@ public static void DockerComposeRun(this ICakeContext context, string service, p [CakeMethodAlias] public static void DockerComposeRun(this ICakeContext context, string service, string command, params string[] args) { - DockerComposeRun(context, new DockerComposeRunSettings(), service, command, args); + DockerComposeRun(context, new DockerComposeRunSettings(), service, command, composeSettings: null, args); } /// @@ -40,9 +40,10 @@ public static void DockerComposeRun(this ICakeContext context, string service, s /// The arguments. /// The settings. [CakeMethodAlias] - public static void DockerComposeRun(this ICakeContext context, DockerComposeRunSettings settings, string service, params string[] args) + public static void DockerComposeRun(this ICakeContext context, DockerComposeRunSettings settings, string service, + DockerComposeSettings? composeSettings = null, params string[] args) { - DockerComposeRun(context, settings, service, command: null, args: args); + DockerComposeRun(context, settings, service, command: null, args: args, composeSettings: composeSettings); } /// @@ -54,7 +55,9 @@ public static void DockerComposeRun(this ICakeContext context, DockerComposeRunS /// The arguments. /// The settings. [CakeMethodAlias] - public static void DockerComposeRun(this ICakeContext context, DockerComposeRunSettings settings, string service, string command, params string[] args) + public static void DockerComposeRun(this ICakeContext context, DockerComposeRunSettings settings, string service, string command, + DockerComposeSettings? composeSettings = null, + params string[] args) { ArgumentNullException.ThrowIfNull(context); if (string.IsNullOrEmpty(service)) @@ -69,7 +72,10 @@ public static void DockerComposeRun(this ICakeContext context, DockerComposeRunS arguments.Add(command); } arguments.AddRange(args); - runner.Run("compose run", settings ?? new DockerComposeRunSettings(), arguments.ToArray()); + runner.Run( + "compose", composeSettings ?? new(), + "run", settings ?? new (), + arguments.ToArray()); } } diff --git a/src/Cake.Docker/Compose/Run/DockerComposeRunSettings.cs b/src/Cake.Docker/Compose/Run/DockerComposeRunSettings.cs index 36b583e..66199f9 100644 --- a/src/Cake.Docker/Compose/Run/DockerComposeRunSettings.cs +++ b/src/Cake.Docker/Compose/Run/DockerComposeRunSettings.cs @@ -1,99 +1,97 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose run. +/// +public sealed class DockerComposeRunSettings : AutoToolSettings { - /// - /// Settings for docker compose run. - /// - public sealed class DockerComposeRunSettings : DockerComposeSettings - { - /// - /// Build image before starting container. - /// - public bool? Build { get; set; } - /// - /// Add Linux capabilities - /// - public bool? CapAdd { get; set; } - /// - /// Drop Linux capabilities - /// - public bool? CapDrop { get; set; } - /// - /// Run container in background and print - /// container ID - /// - public bool? Detach { get; set; } - /// - /// Override the entrypoint of the image - /// - public string? Entrypoint { get; set; } - /// - /// Set environment variables - /// - [AutoProperty(AutoArrayType = AutoArrayType.List)] - public string[]? Env { get; set; } - /// - /// Keep STDIN open even if not attached. - /// (default true) - /// - public bool? Interactive { get; set; } - /// - /// Add or override a label - /// - [AutoProperty(AutoArrayType = AutoArrayType.List)] - public string[]? Label { get; set; } - /// - /// Assign a name to the container - /// - public string? Name { get; set; } - /// - /// Disable pseudo-TTY allocation (default: - /// auto-detected). - /// - public bool? NoTTY { get; set; } - /// - /// Don't start linked services. - /// - public bool? NoDeps { get; set; } - /// - /// Publish a container's port(s) to the host. - /// - [AutoProperty(AutoArrayType = AutoArrayType.List)] - public string[]? Publish { get; set; } - /// - /// Pull without printing progress information. - /// - public bool? QuietPull { get; set; } - /// - /// Remove containers for services not defined - /// in the Compose file. - /// - public bool? RemoveOrphans { get; set; } - /// - /// Automatically remove the container when it exits - /// - public bool? Rm { get; set; } - /// - /// Run command with all service's ports - /// enabled and mapped to the host. - /// - public bool? ServicePorts { get; set; } - /// - /// Use the service's network useAliases in the - /// network(s) the container connects to. - /// - public bool? UseAliases { get; set; } - /// - /// Run as specified username or uid - /// - public string? User { get; set; } - /// - /// Bind mount a volume. - /// - [AutoProperty(AutoArrayType = AutoArrayType.List)] - public string[]? Volume { get; set; } - /// - /// Working directory inside the container - /// - public string? Workdir { get; set; } - } -} \ No newline at end of file + /// + /// Build image before starting container. + /// + public bool? Build { get; set; } + /// + /// Add Linux capabilities + /// + public bool? CapAdd { get; set; } + /// + /// Drop Linux capabilities + /// + public bool? CapDrop { get; set; } + /// + /// Run container in background and print + /// container ID + /// + public bool? Detach { get; set; } + /// + /// Override the entrypoint of the image + /// + public string? Entrypoint { get; set; } + /// + /// Set environment variables + /// + [AutoProperty(AutoArrayType=AutoArrayType.List)] + public string[]? Env { get; set; } + /// + /// Keep STDIN open even if not attached. + /// (default true) + /// + public bool? Interactive { get; set; } + /// + /// Add or override a label + /// + [AutoProperty(AutoArrayType=AutoArrayType.List)] + public string[]? Label { get; set; } + /// + /// Assign a name to the container + /// + public string? Name { get; set; } + /// + /// Disable pseudo-TTY allocation (default: + /// auto-detected). + /// + public bool? NoTTY { get; set; } + /// + /// Don't start linked services. + /// + public bool? NoDeps { get; set; } + /// + /// Publish a container's port(s) to the host. + /// + [AutoProperty(AutoArrayType=AutoArrayType.List)] + public string[]? Publish { get; set; } + /// + /// Pull without printing progress information. + /// + public bool? QuietPull { get; set; } + /// + /// Remove containers for services not defined + /// in the Compose file. + /// + public bool? RemoveOrphans { get; set; } + /// + /// Automatically remove the container when it exits + /// + public bool? Rm { get; set; } + /// + /// Run command with all service's ports + /// enabled and mapped to the host. + /// + public bool? ServicePorts { get; set; } + /// + /// Use the service's network useAliases in the + /// network(s) the container connects to. + /// + public bool? UseAliases { get; set; } + /// + /// Run as specified username or uid + /// + public string? User { get; set; } + /// + /// Bind mount a volume. + /// + [AutoProperty(AutoArrayType=AutoArrayType.List)] + public string[]? Volume { get; set; } + /// + /// Working directory inside the container + /// + public string? Workdir { get; set; } +} diff --git a/src/Cake.Docker/Compose/Scale/Docker.Aliases.ComposeScale.cs b/src/Cake.Docker/Compose/Scale/Docker.Aliases.ComposeScale.cs index 749f7c7..07845b8 100644 --- a/src/Cake.Docker/Compose/Scale/Docker.Aliases.ComposeScale.cs +++ b/src/Cake.Docker/Compose/Scale/Docker.Aliases.ComposeScale.cs @@ -15,7 +15,7 @@ partial class DockerAliases [CakeMethodAlias] public static void DockerComposeScale(this ICakeContext context, params string[] services) { - DockerComposeScale(context, new DockerComposeScaleSettings(), services); + DockerComposeScale(context, new DockerComposeScaleSettings(), null, services); } /// /// Runs docker-compose scale. @@ -24,11 +24,15 @@ public static void DockerComposeScale(this ICakeContext context, params string[] /// The settings. /// The list of services. [CakeMethodAlias] - public static void DockerComposeScale(this ICakeContext context, DockerComposeScaleSettings settings, params string[] services) + public static void DockerComposeScale(this ICakeContext context, DockerComposeScaleSettings settings, + DockerComposeSettings? composeSettings = null, + params string[] services) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose scale", settings, services); + runner.Run( + "compose", composeSettings ?? new(), + "scale", settings, services); } } } \ No newline at end of file diff --git a/src/Cake.Docker/Compose/Scale/DockerComposeScaleSettings.cs b/src/Cake.Docker/Compose/Scale/DockerComposeScaleSettings.cs index 8fb95a2..607b744 100644 --- a/src/Cake.Docker/Compose/Scale/DockerComposeScaleSettings.cs +++ b/src/Cake.Docker/Compose/Scale/DockerComposeScaleSettings.cs @@ -1,13 +1,11 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose scale. +/// +public sealed class DockerComposeScaleSettings : AutoToolSettings { - /// - /// Settings for docker compose scale. - /// - public sealed class DockerComposeScaleSettings : DockerComposeSettings - { - /// - /// Don't start linked services. - /// - public bool? NoDeps { get; set; } - } -} \ No newline at end of file + /// + /// Don't start linked services. + /// + public bool? NoDeps { get; set; } +} diff --git a/src/Cake.Docker/Compose/Start/Docker.Aliases.ComposeStart.cs b/src/Cake.Docker/Compose/Start/Docker.Aliases.ComposeStart.cs index 14eb748..392f7c7 100644 --- a/src/Cake.Docker/Compose/Start/Docker.Aliases.ComposeStart.cs +++ b/src/Cake.Docker/Compose/Start/Docker.Aliases.ComposeStart.cs @@ -15,7 +15,7 @@ partial class DockerAliases [CakeMethodAlias] public static void DockerComposeStart(this ICakeContext context, params string[] services) { - DockerComposeStart(context, new DockerComposeSettings(), services); + DockerComposeStart(context, new DockerComposeSettings(), null, services); } /// /// Runs docker-compose start. @@ -24,11 +24,15 @@ public static void DockerComposeStart(this ICakeContext context, params string[] /// The settings. /// The list of services. [CakeMethodAlias] - public static void DockerComposeStart(this ICakeContext context, DockerComposeSettings settings, params string[] services) + public static void DockerComposeStart(this ICakeContext context, DockerComposeSettings settings, + DockerComposeSettings? composeSettings = null, + params string[] services) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose start", settings ?? new DockerComposeSettings(), services); + runner.Run( + "compose", composeSettings ?? new(), + "start", settings ?? new (), services); } } } \ No newline at end of file diff --git a/src/Cake.Docker/Compose/Stop/Docker.Aliases.ComposeStop.cs b/src/Cake.Docker/Compose/Stop/Docker.Aliases.ComposeStop.cs index 4247575..97e6f7c 100644 --- a/src/Cake.Docker/Compose/Stop/Docker.Aliases.ComposeStop.cs +++ b/src/Cake.Docker/Compose/Stop/Docker.Aliases.ComposeStop.cs @@ -15,7 +15,7 @@ partial class DockerAliases [CakeMethodAlias] public static void DockerComposeStop(this ICakeContext context, params string[] services) { - DockerComposeStop(context, new DockerComposeBuildSettings(), services); + DockerComposeStop(context, new DockerComposeBuildSettings(), null, services); } /// @@ -25,11 +25,16 @@ public static void DockerComposeStop(this ICakeContext context, params string[] /// The list of services. /// The settings. [CakeMethodAlias] - public static void DockerComposeStop(this ICakeContext context, DockerComposeBuildSettings settings, params string[] services) + public static void DockerComposeStop(this ICakeContext context, DockerComposeBuildSettings settings, + DockerComposeSettings? composeSettings = null, + params string[] services) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose stop", settings ?? new DockerComposeBuildSettings(), services); + runner.Run( + "compose", composeSettings ?? new(), + "stop", settings ?? new (), + services); } } diff --git a/src/Cake.Docker/Compose/Stop/DockerComposeSTopSettings.cs b/src/Cake.Docker/Compose/Stop/DockerComposeSTopSettings.cs index 3ea187e..ebcb791 100644 --- a/src/Cake.Docker/Compose/Stop/DockerComposeSTopSettings.cs +++ b/src/Cake.Docker/Compose/Stop/DockerComposeSTopSettings.cs @@ -1,13 +1,11 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose stop. +/// +public sealed class DockerComposeStopSettings : AutoToolSettings { - /// - /// Settings for docker compose stop. - /// - public sealed class DockerComposeStopSettings : DockerComposeSettings - { - /// - /// Specify a shutdown timeout in seconds - /// - public int? Timeout { get; set; } - } -} \ No newline at end of file + /// + /// Specify a shutdown timeout in seconds + /// + public int? Timeout { get; set; } +} diff --git a/src/Cake.Docker/Compose/Unpause/Docker.Aliases.ComposeUnpause.cs b/src/Cake.Docker/Compose/Unpause/Docker.Aliases.ComposeUnpause.cs index 46f6593..5efe946 100644 --- a/src/Cake.Docker/Compose/Unpause/Docker.Aliases.ComposeUnpause.cs +++ b/src/Cake.Docker/Compose/Unpause/Docker.Aliases.ComposeUnpause.cs @@ -15,7 +15,7 @@ partial class DockerAliases [CakeMethodAlias] public static void DockerComposeUnpause(this ICakeContext context, params string[] services) { - DockerComposeUnpause(context, new DockerComposeSettings(), services); + DockerComposeUnpause(context, new DockerComposeSettings(), null, services); } /// /// Runs docker-compose unpause. @@ -24,11 +24,16 @@ public static void DockerComposeUnpause(this ICakeContext context, params string /// The settings. /// The list of services. [CakeMethodAlias] - public static void DockerComposeUnpause(this ICakeContext context, DockerComposeSettings settings, params string[] services) + public static void DockerComposeUnpause(this ICakeContext context, DockerComposeSettings settings, + DockerComposeSettings? composeSettings = null, + params string[] services) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose unpause", settings ?? new DockerComposeSettings(), services); + runner.Run( + "compose", composeSettings ?? new(), + "unpause", settings ?? new (), + services); } } } \ No newline at end of file diff --git a/src/Cake.Docker/Compose/Up/Docker.Aliases.ComposeUp.cs b/src/Cake.Docker/Compose/Up/Docker.Aliases.ComposeUp.cs index 5746f72..ea04d88 100644 --- a/src/Cake.Docker/Compose/Up/Docker.Aliases.ComposeUp.cs +++ b/src/Cake.Docker/Compose/Up/Docker.Aliases.ComposeUp.cs @@ -15,7 +15,7 @@ partial class DockerAliases [CakeMethodAlias] public static void DockerComposeUp(this ICakeContext context, params string[] services) { - DockerComposeUp(context, new DockerComposeUpSettings(), services); + DockerComposeUp(context, new DockerComposeUpSettings(), null, services); } /// @@ -25,11 +25,15 @@ public static void DockerComposeUp(this ICakeContext context, params string[] se /// The list of services. /// The settings. [CakeMethodAlias] - public static void DockerComposeUp(this ICakeContext context, DockerComposeUpSettings settings, params string[] services) + public static void DockerComposeUp(this ICakeContext context, DockerComposeUpSettings settings, + DockerComposeSettings? composeSettings = null, + params string[] services) { ArgumentNullException.ThrowIfNull(context); var runner = new GenericDockerRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - runner.Run("compose up", settings ?? new DockerComposeUpSettings(), services); + runner.Run( + "compose", composeSettings ?? new(), + "up", settings ?? new (), services); } } diff --git a/src/Cake.Docker/Compose/Up/DockerComposeUpSettings.cs b/src/Cake.Docker/Compose/Up/DockerComposeUpSettings.cs index 2188222..a7a6eef 100644 --- a/src/Cake.Docker/Compose/Up/DockerComposeUpSettings.cs +++ b/src/Cake.Docker/Compose/Up/DockerComposeUpSettings.cs @@ -1,128 +1,129 @@ -namespace Cake.Docker +namespace Cake.Docker; +/// +/// Settings for docker compose up. +/// +public sealed class DockerComposeUpSettings : AutoToolSettings { - /// - /// Settings for docker compose up. - /// - public sealed class DockerComposeUpSettings : DockerComposeSettings - { - /// - /// Stops all containers if any container - /// was stopped. Incompatible with -d - /// - public bool? AbortOnContainerExit { get; set; } - /// - /// Recreate dependent containers. - /// Incompatible with --no-recreate. - /// - public bool? AlwaysRecreateDeps { get; set; } - /// - /// Restrict attaching to the specified - /// services. Incompatible with - /// - [AutoProperty(AutoArrayType = AutoArrayType.List)] - public string[]? Attach { get; set; } - /// - /// Automatically attach to log output of - /// dependent services. - /// - public bool? AttachDependencies { get; set; } - /// - /// Build images before starting containers. - /// - public bool? Build { get; set; } - /// - /// Detached mode: Run containers in the - /// background - /// - public bool? Detach { get; set; } - /// - /// Return the exit code of the selected - /// service container. Implies - /// - public string? ExitCodeFrom { get; set; } - /// - /// Recreate containers even if their - /// configuration and image haven't changed. - /// - public bool? ForceRecreate { get; set; } - /// - /// Do not attach (stream logs) to the - /// specified services. - /// - [AutoProperty(AutoArrayType = AutoArrayType.List)] - public string[]? NoAttach { get; set; } - /// - /// Don't build an image, even if it's policy. - /// - public bool? NoBuild { get; set; } - /// - /// Produce monochrome output. - /// - public bool? NoColor { get; set; } - /// - /// Don't start linked services. - /// - public bool? NoDeps { get; set; } - /// - /// Don't print prefix in logs. - /// - public bool? NoLogPrefix { get; set; } - /// - /// If containers already exist, don't - /// recreate them. Incompatible with - /// - public bool? NoRecreate { get; set; } - /// - /// Don't start the services after creating - /// them. - /// - public bool? NoStart { get; set; } - /// - /// Pull image before running - /// ("always"|"missing"|"never") (default - /// "policy") - /// - public string? Pull { get; set; } - /// - /// Pull without printing progress information. - /// - public bool? QuietPull { get; set; } - /// - /// Remove containers for services not - /// defined in the Compose file. - /// - public bool? RemoveOrphans { get; set; } - /// - /// Recreate anonymous volumes instead of - /// retrieving data from the previous - /// containers. - /// - public bool? RenewAnonVolumes { get; set; } - /// - /// Scale SERVICE to NUM instances. - /// Overrides the scale setting in the - /// Compose file if present. - /// - public bool? Scale { get; set; } - /// - /// Use this timeout in seconds for - /// container shutdown when attached or - /// when containers are already running. - /// - public int? Timeout { get; set; } - /// - /// Show timestamps. - /// - public bool? Timestamps { get; set; } - /// - /// Wait for services to be - /// running|healthy. Implies detached mode. - /// - public bool? Wait { get; set; } - /// - /// Maximum duration to wait for the - /// project to be running|healthy. - /// - public int? WaitTimeout { get; set; } - } -} \ No newline at end of file + /// + /// Stops all containers if any container + /// was stopped. Incompatible with -d + /// + public bool? AbortOnContainerExit { get; set; } + /// + /// Recreate dependent containers. + /// Incompatible with --no-recreate. + /// + public bool? AlwaysRecreateDeps { get; set; } + /// + /// Restrict attaching to the specified + /// services. Incompatible with + /// --attach-dependencies. + /// + [AutoProperty(AutoArrayType=AutoArrayType.List)] + public string[]? Attach { get; set; } + /// + /// Automatically attach to log output of + /// dependent services. + /// + public bool? AttachDependencies { get; set; } + /// + /// Build images before starting containers. + /// + public bool? Build { get; set; } + /// + /// Detached mode: Run containers in the + /// background + /// + public bool? Detach { get; set; } + /// + /// Return the exit code of the selected + /// service container. Implies + /// --abort-on-container-exit + /// + public string? ExitCodeFrom { get; set; } + /// + /// Recreate containers even if their + /// configuration and image haven't changed. + /// + public bool? ForceRecreate { get; set; } + /// + /// Do not attach (stream logs) to the + /// specified services. + /// + [AutoProperty(AutoArrayType=AutoArrayType.List)] + public string[]? NoAttach { get; set; } + /// + /// Don't build an image, even if it's policy. + /// + public bool? NoBuild { get; set; } + /// + /// Produce monochrome output. + /// + public bool? NoColor { get; set; } + /// + /// Don't start linked services. + /// + public bool? NoDeps { get; set; } + /// + /// Don't print prefix in logs. + /// + public bool? NoLogPrefix { get; set; } + /// + /// If containers already exist, don't + /// recreate them. Incompatible with + /// --force-recreate. + /// + public bool? NoRecreate { get; set; } + /// + /// Don't start the services after creating + /// them. + /// + public bool? NoStart { get; set; } + /// + /// Pull image before running + /// ("always"|"missing"|"never") (default + /// "policy") + /// + public string? Pull { get; set; } + /// + /// Pull without printing progress information. + /// + public bool? QuietPull { get; set; } + /// + /// Remove containers for services not + /// defined in the Compose file. + /// + public bool? RemoveOrphans { get; set; } + /// + /// Recreate anonymous volumes instead of + /// retrieving data from the previous + /// containers. + /// + public bool? RenewAnonVolumes { get; set; } + /// + /// Scale SERVICE to NUM instances. + /// Overrides the scale setting in the + /// Compose file if present. + /// + public bool? Scale { get; set; } + /// + /// Use this timeout in seconds for + /// container shutdown when attached or + /// when containers are already running. + /// + public int? Timeout { get; set; } + /// + /// Show timestamps. + /// + public bool? Timestamps { get; set; } + /// + /// Wait for services to be + /// running|healthy. Implies detached mode. + /// + public bool? Wait { get; set; } + /// + /// Maximum duration to wait for the + /// project to be running|healthy. + /// + public int? WaitTimeout { get; set; } +} diff --git a/src/Cake.Docker/GenericDockerRunner.cs b/src/Cake.Docker/GenericDockerRunner.cs index dc6986b..34022c7 100644 --- a/src/Cake.Docker/GenericDockerRunner.cs +++ b/src/Cake.Docker/GenericDockerRunner.cs @@ -57,6 +57,33 @@ public void Run(string command, TSettings settings, string[] additional) Run(settings, GetArguments(command, settings, additional)); } } + public void Run(string coreCommand, TCoreSettings coreSettings, string command, TSettings settings, string[] additional) + where TCoreSettings : AutoToolSettings, new() + { + if (string.IsNullOrEmpty(command)) + { + throw new ArgumentNullException(nameof(command)); + } + if (settings == null) + { + throw new ArgumentNullException(nameof(settings)); + } + if (additional == null) + { + throw new ArgumentNullException(nameof(additional)); + } + // checks whether method is experimental based on ExperimentalAttribute decoration + if (IsExperimental) + { + // when experimental, applies proper environmental variable to runner process + var processSettings = CreateExperimentalProcessSettings(); + Run(settings, GetArguments(coreCommand, coreSettings, command, settings, additional), processSettings, postAction: null); + } + else + { + Run(settings, GetArguments(coreCommand, coreSettings, command, settings, additional)); + } + } static bool IsExperimental => typeof(TSettings).GetCustomAttributes(typeof(ExperimentalAttribute), inherit: true)?.Length > 0; static ProcessSettings CreateExperimentalProcessSettings() { @@ -71,6 +98,16 @@ private ProcessArgumentBuilder GetArguments(string command, TSettings settings, return builder; } + private ProcessArgumentBuilder GetArguments(string coreCommand, TCoreSettings coreSetings, string command, TSettings settings, + string[] additional) + where TCoreSettings : AutoToolSettings, new() + { + var builder = new ProcessArgumentBuilder(); + builder.AppendAll(coreCommand, coreSetings, Array.Empty()); + builder.AppendAll(command, settings, additional); + return builder; + } + /// /// Runs a command and returns a result based on processed output. /// @@ -107,5 +144,35 @@ public T[] RunWithResult(string command, TSettings settings, }); return result; } + public T[] RunWithResult( + string coreCommand, TCoreSettings coreSettings, + string command, TSettings settings, + Func, T[]> processOutput, + params string[] arguments) + where TCoreSettings : AutoToolSettings, new() + { + if (string.IsNullOrEmpty(command)) + { + throw new ArgumentNullException(nameof(command)); + } + if (settings == null) + { + throw new ArgumentNullException(nameof(settings)); + } + if (processOutput == null) + { + throw new ArgumentNullException(nameof(processOutput)); + } + T[] result = Array.Empty(); + ProcessSettings processSettings = IsExperimental ? CreateExperimentalProcessSettings() : new ProcessSettings(); + processSettings.RedirectStandardOutput = true; + Run(settings, GetArguments(coreCommand, coreSettings, command, settings, arguments), + processSettings, + proc => + { + result = processOutput(proc.GetStandardOutput()); + }); + return result; + } } }