-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ablity to redirect process output and error #161
base: master
Are you sure you want to change the base?
Conversation
Thanks @gravypower for this nice PR! Could you please add the ability to at least all docker-compose commands (in same file)? (it would also be nice with the other docker commands of course :)) Cheers, |
Thanks for the feedback @mariotoffia. I will look into your suggestion and update this PR. |
I started to do this and it is turning into spaghetti code :(. I might abandon that approach I am taking and reconsider it. Will report back when I have something more. |
Hey @mariotoffia, I have introduced an Ambient Context to achieve this, but it makes me feel a bit dirty. So a consumer of FluentDocker who wants to redirect output from the docker/docker-compose call would do something like this var workingDockerCompose = Path.Combine(input.WorkingPath, "docker-compose.yml");
var builder = new Builder()
.UseContainer()
.UseCompose()
.FromFile(workingDockerCompose)
.RemoveOrphans();
var compositeService = builder.Build();
var p = new ProcessManager();
p.ErrorTextReceived += (sender, s) =>
{
if(sender.ProcessIdentifier != nameof(Compose.ComposeUp))
return;
if (!string.IsNullOrEmpty(s))
Console.Error.WriteAsync(s);
};
p.StandartTextReceived += (sender, s) =>
{
if(sender.ProcessIdentifier != nameof(Compose.ComposeUp))
return;
if (!string.IsNullOrEmpty(s))
Console.Write(s);
};
using (ProcessManagerContext.UseProcessManager(p))
{
compositeService.Start();
} What do you think? I feel its the best way without sweeping changes. Extra information: https://blog.ploeh.dk/2019/01/21/some-thoughts-on-anti-patterns/ |
I was stuffing around trying to remove a commit might have botched the tree 😟. Looking into why I have broken the build now. |
OK I am not sure what is going on with the build, I have run |
@gravypower Thanks for your work! :) - I'll have a look at your Hmm... I will also investigate why you get a merge conflict. Cheers |
Oh. I will check again I thought that I had merged in master, maybe I forgot to push that. AH yes the ProcessManager, had plans to be able to redirect input and output, I should simplify this for now. |
public class AmbientContext | ||
{ | ||
[TestMethod] | ||
public void Test1000000Nested() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be any asserts in order to ensure that it contains the correct content?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copied from the tests where I pulled the AmbientContext from. I can remove if you think that is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do
startInfo.EnvironmentVariables[key] = Env[key]; | ||
#endif | ||
} | ||
var pm = ProcessManagerContext.ProcessManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could'n we use a instance based approach for a ProcessManager
instead of a static one and thus avoid thread variables (? - haven't checked what you use them for).
like use(pm = ...) {
fd.UsePm(pm).
...
}
when the pm context exits, all commands for compse and docker services, etc. will fail (with e.g. missing pm (name xyz)). Or at-least a non static approach?
It will later on fit into the event model (v4.0.0) so the pm will send events and docker events is also emitted as events into a event dispatcher that one may register to one or more services.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have simplified what is going on here This is needed however its how you access the AmbientContext. If you look under the hood of that context its getting a thread variable. Like I said I feel a bit dirty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better approach is to skip the AmbientContext
and just pass the ProcessManager
into the commands instead - just use a static default if not provided?
@mariotoffia Hello Mario! Are there any plans to finish and merge this feature into the production branch? It would provide a great experience during CI pipelines |
Hi @jalbrzym - It needs heavy refactoring (as described above) since this is too static. I have no immediate plan to do this but I can up-prioritize this if this is a very much needed feature? Cheers, |
I wanted to display the output of a docker-compose call in a CLI I am building.