Skip to content
Merged
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ type SwarmNode struct {
}

type State struct {
Running bool
Running bool
Health Health
}

type Health struct {
Status string
}

// Accessible from the root in templates as .Docker
Expand Down
5 changes: 5 additions & 0 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ type Volume struct {

type State struct {
Running bool
Health Health
}

type Health struct {
Status string
}

type RuntimeContainer struct {
Expand Down
5 changes: 4 additions & 1 deletion internal/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (g *generator) generateFromEvents() {
time.Sleep(10 * time.Second)
break
}
if event.Status == "start" || event.Status == "stop" || event.Status == "die" {
if event.Status == "start" || event.Status == "stop" || event.Status == "die" || strings.Index(event.Status, "health_status:") != -1 {
log.Printf("Received event %s for container %s", event.Status, event.ID[:12])
// fanout event to all watchers
for _, watcher := range watchers {
Expand Down Expand Up @@ -401,6 +401,9 @@ func (g *generator) getContainers() ([]*context.RuntimeContainer, error) {
},
State: context.State{
Running: container.State.Running,
Health: context.Health{
Status: container.State.Health.Status,
},
},
Name: strings.TrimLeft(container.Name, "/"),
Hostname: container.Config.Hostname,
Expand Down
5 changes: 5 additions & 0 deletions internal/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func TestGenerateFromEvents(t *testing.T) {
Pid: 400,
ExitCode: 0,
StartedAt: time.Now(),
Health: docker.Health{
Status: "healthy",
FailingStreak: 5,
Log: []docker.HealthCheck{},
},
},
Image: "0ff407d5a7d9ed36acdf3e75de8cc127afecc9af234d05486be2981cdc01a38d",
NetworkSettings: &docker.NetworkSettings{
Expand Down
6 changes: 6 additions & 0 deletions templates/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ upstream {{ $host }} {
{{ $addrLen := len $value.Addresses }}
{{ $network := index $value.Networks 0 }}

{{ if $value.State.Health.Status }}
{{ if ne $value.State.Health.Status "healthy" }}
{{ continue }}
{{ end }}
{{ end }}

{{/* If only 1 port exposed, use that */}}
{{ if eq $addrLen 1 }}
{{ with $address := index $value.Addresses 0 }}
Expand Down