-
-
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
Docker Daemon Event Reception Support #129
Comments
Hi, Below taken from the ContainerBuilder.AddHooks(IService container) if (null != _config.CpToOnStart)
container.AddHook(ServiceRunningState.Starting,
service =>
{
Fd.DisposeOnException(svc =>
{
foreach (var copy in _config.CpToOnStart)
((IContainerService)service).CopyTo(copy.Item2, copy.Item1);
}, service, "Copy on start");
});
// Wait for port when started
if (null != _config.WaitForPort)
container.AddHook(ServiceRunningState.Running,
service =>
{
Fd.DisposeOnException(svc =>
((IContainerService)service).WaitForPort(_config.WaitForPort.Item1, _config.WaitForPort.Item3,
_config.WaitForPort.Item2),
service, "Wait for port");
});
// Wait for healthy when started
if (null != _config.WaitForHealthy)
container.AddHook(ServiceRunningState.Running,
service =>
{
Fd.DisposeOnException(svc =>
((IContainerService)service).WaitForHealthy(_config.WaitForHealthy.Item1),
service, "Wait for healthy");
}); As a side note I'm thinking on having a property on the What you describe later on will absolutely need to hook into the I've been loosely thinking of that one may put a It you're willing to experiment I'm really happy if you could share your code and thoughts! Cheers, |
Thanks this is something i will play with an share assuming i can get it to work how i want it to or if it atleast has something useful in it. |
I've merged a first round of event mapping so it is possible to listen on the event stream. A few events has been mapped, I need to do tests to have the runtime emit the different events (since not documented) and make them strongly typed. If it can't recognize a event it creates a Simple example to iterate a event stream until a using (var events = Fd.Native().Events())
{
using (
var container =
new Builder().UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.WaitForPort("5432/tcp", 30000 /*30s*/)
.Build()
.Start())
{
FdEvent e;
while ((e= events.TryRead(3000)) != null)
{
if (e.Type == EventType.Container && e.Action == EventAction.Start)
break;
}
}
} This is published as beta on nuget if you want to try it out. |
Thanks I will take a look
…On Wed, 13 Nov 2019, 8:25 am Mario Toffia, ***@***.***> wrote:
I've merged a first round of event mapping so it is possible to listen on
the event stream. A few events has been mapped, I need to do tests to have
the runtime emit the different events (since not documented) and make them
strongly typed. If it can't recognize a event it creates a UnknownEvent
with attributes that it does not know how to handle as a list of key values.
Simple example to iterate a event stream until a ContainerStartedEvent is
retrieved.
using (var events = Fd.Native().Events())
{
using (
var container =
new Builder().UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposePort(5432)
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.WaitForPort("5432/tcp", 30000 /*30s*/)
.Build()
.Start())
{
FdEvent e;
while ((e= events.TryRead(3000)) != null)
{
if (e.Type == EventType.Container && e.Action == EventAction.Start)
break;
}
}
}
This is published as beta on nuget if you want to try it out.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#129?email_source=notifications&email_token=AADB44LAIGW7YUJL4YOU463QTMNN7A5CNFSM4JKVSJU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOED37RUA#issuecomment-553122000>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADB44NCLQ66QT4GUQHM2WDQTMNN7ANCNFSM4JKVSJUQ>
.
|
To really take advantage of this i would need to use docker healthchecks vs your WaitForTcp etc right? I just realised docker compose atleast supports waiting for health check so mixing that with the events could be a good way to monitor and act on things. |
I'm closing this now since the event reception has been implemented. |
This is more a guidance question.
What i want to acheave is something like an enhanced docker compose file. I need to define multiple containters that have dependancies between them. I don't want to start a container that has a dependancy until all containers it has a dependancy on have successfully started including been healthy and passing the WaitForXXX checks on the instance start ups. Ideally i would love to be able to specify an action to happen on dependat containers so that if say a container you have a dependancy on is unhealthy, stops or does not pass the staryup checks then the containers dependant on it has the action called on them (stop, pause, remove.)
Sort of like a system where parts of them system comes and goes based on things they are dependant on being available or not and events or something triggering them to be distroyed or recreated as things change.
I thought of building most of it up in code but there is no event that i could see for when a container has passed all the "WaitForxxx" checks which you would need if you wanted this to work via an eventing system including when a container is auto restarted etc.
The text was updated successfully, but these errors were encountered: