Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Ductus.FluentDocker/Commands/Compose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public static CommandResponse<IList<string>> ComposeUpCommand(this DockerUri hos

if (!string.IsNullOrEmpty(ca.ProjectDirectory))
{
composeArgs += $" --project-directory {ca.ProjectDirectory.Rendered}";
composeArgs += $" --project-directory \"{ca.ProjectDirectory.Rendered}\"";
}

var options = ca.NoStart ? "--no-start" : "--detach";
Expand Down Expand Up @@ -603,7 +603,7 @@ public static CommandResponse<IList<string>> ComposeRm(this DockerUri host, stri
args += $" -f \"{cf}\"";

if (!string.IsNullOrEmpty(altProjectName))
args += $" -p {altProjectName}";
args += $" -p \"{altProjectName}\"";

var options = string.Empty;
options += " -f"; // Don't ask to confirm removal
Expand Down Expand Up @@ -639,7 +639,7 @@ public static CommandResponse<IList<string>> ComposePs(this DockerUri host, stri
args += $" -f \"{cf}\"";

if (!string.IsNullOrEmpty(altProjectName))
args += $" -p {altProjectName}";
args += $" -p \"{altProjectName}\"";

var options = string.Empty;
if (null != services && 0 != services.Length)
Expand Down Expand Up @@ -676,7 +676,7 @@ public static CommandResponse<IList<string>> ComposePull(this DockerUri host, Co
args += $" -f \"{cf}\"";

if (!string.IsNullOrEmpty(commandArgs.AltProjectName))
args += $" -p {commandArgs.AltProjectName}";
args += $" -p \"{commandArgs.AltProjectName}\"";

var options = string.Empty;
if (commandArgs.DownloadAllTagged)
Expand Down
4 changes: 3 additions & 1 deletion Ductus.FluentDocker/Executors/AsyncProcessExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Diagnostics;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Ductus.FluentDocker.Common;
using Ductus.FluentDocker.Extensions;
using Ductus.FluentDocker.Model.Containers;

namespace Ductus.FluentDocker.Executors
Expand All @@ -18,6 +19,7 @@ public AsyncProcessExecutor(string command, string arguments, string workingdir
_command = command;
_arguments = arguments;
_workingdir = workingdir;
CommandExtensions.FixSudoCommand(command, arguments, out _command, out _arguments);
}

public Task<CommandResponse<TE>> Execute(CancellationToken cancellationToken = default(CancellationToken))
Expand Down
9 changes: 1 addition & 8 deletions Ductus.FluentDocker/Executors/ProcessExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@ namespace Ductus.FluentDocker.Executors
public ProcessExecutor(string command, string arguments, string workingdir = null)
{
_workingdir = workingdir;
if (command.StartsWith("echo") || command.StartsWith("sudo"))
{
_command = CommandExtensions.DefaultShell;
_arguments = $"-c \"{command} {arguments}\"";

return;
}

_command = command;
_arguments = arguments;
CommandExtensions.FixSudoCommand(command, arguments, out _command, out _arguments);
}

public IDictionary<string, string> Env { get; } = new Dictionary<string, string>();
Expand Down
6 changes: 5 additions & 1 deletion Ductus.FluentDocker/Executors/StreamProcessExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics;
using System.Threading;
using Ductus.FluentDocker.Common;
using Ductus.FluentDocker.Extensions;

namespace Ductus.FluentDocker.Executors
{
Expand All @@ -16,6 +17,7 @@ public StreamProcessExecutor(string command, string arguments, string workingdir
_command = command;
_arguments = arguments;
_workingdir = workingdir;
CommandExtensions.FixSudoCommand(command, arguments, out _command, out _arguments);
}

public ConsoleStream<TE> Execute(CancellationToken token = default)
Expand All @@ -30,7 +32,9 @@ public ConsoleStream<TE> Execute(CancellationToken token = default)
UseShellExecute = false,
Arguments = _arguments,
FileName = _command,
WorkingDirectory = _workingdir
WorkingDirectory = _workingdir,
StandardErrorEncoding = System.Text.Encoding.UTF8,
StandardOutputEncoding = System.Text.Encoding.UTF8,
}, new T(), token);
}
}
Expand Down
15 changes: 15 additions & 0 deletions Ductus.FluentDocker/Extensions/CommandExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ public static void SetSudo(this SudoMechanism sudo, string password = null)
_binaryResolver = new DockerBinariesResolver(_sudoMechanism, _sudoPassword);
}

public static void FixSudoCommand(string command, string arguments, out string fixedCommand, out string fixedArguments)
{
if (command.StartsWith("echo") || command.StartsWith("sudo"))
{
fixedCommand = CommandExtensions.DefaultShell;
string escapedArguments = arguments.Replace("\"", "\"\\\"\"");
fixedArguments = $"-c \"{command} {escapedArguments}\"";
}
else
{
fixedCommand = command;
fixedArguments = arguments;
}
}

public static string ResolveBinary(this string dockerCommand, bool preferMachine = false, bool forceResolve = false)
{
if (forceResolve || null == _binaryResolver)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public static class ContainerExtensions
/// <param name="follow">If continuous logs is wanted.</param>
/// <param name="token">The cancellation token for logs, especially needed when <paramref name="follow" /> is set to true.</param>
/// <returns>A console stream to consume.</returns>
public static ConsoleStream<string> Logs(this IContainerService service, bool follow = false,
public static ConsoleStream<string> Logs(this IContainerService service, bool follow = false, bool showTimeStamps = false,
CancellationToken token = default)
{
return service.DockerHost.Logs(service.Id, token, follow);
return service.DockerHost.Logs(service.Id, token, follow, showTimeStamps);
}

/// <summary>
Expand Down