mirror of
https://github.com/amir20/dozzle.git
synced 2026-01-02 19:17:37 +01:00
feat: supports container rename (#3390)
This commit is contained in:
@@ -23,9 +23,9 @@ export class GroupedContainers {
|
||||
|
||||
export class Container {
|
||||
private _stat: Ref<Stat>;
|
||||
private _name: string;
|
||||
private readonly _statsHistory: Ref<Stat[]>;
|
||||
private readonly movingAverageStat: Ref<Stat>;
|
||||
private readonly _name: string;
|
||||
|
||||
constructor(
|
||||
public readonly id: string,
|
||||
@@ -76,6 +76,10 @@ export class Container {
|
||||
return this.group;
|
||||
}
|
||||
|
||||
set name(name: string) {
|
||||
this._name = name;
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this.isSwarm
|
||||
? this.labels["com.docker.swarm.task.name"]
|
||||
|
||||
@@ -124,6 +124,7 @@ export const useContainerStore = defineStore("container", () => {
|
||||
const existing = allContainersById.value[c.id];
|
||||
existing.state = c.state;
|
||||
existing.health = c.health;
|
||||
existing.name = c.name;
|
||||
});
|
||||
|
||||
containers.value = [
|
||||
|
||||
@@ -309,9 +309,10 @@ func (d *httpClient) ContainerEvents(ctx context.Context, messages chan<- Contai
|
||||
case message := <-dockerMessages:
|
||||
if message.Type == events.ContainerEventType && len(message.Actor.ID) > 0 {
|
||||
messages <- ContainerEvent{
|
||||
ActorID: message.Actor.ID[:12],
|
||||
Name: string(message.Action),
|
||||
Host: d.host.ID,
|
||||
ActorID: message.Actor.ID[:12],
|
||||
Name: string(message.Action),
|
||||
Host: d.host.ID,
|
||||
ActorAttributes: message.Actor.Attributes,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +230,17 @@ func (s *ContainerStore) init() {
|
||||
return c, true
|
||||
}
|
||||
})
|
||||
|
||||
case "rename":
|
||||
s.containers.Compute(event.ActorID, func(c *Container, loaded bool) (*Container, bool) {
|
||||
if loaded {
|
||||
log.Debug().Str("id", event.ActorID).Str("name", event.ActorAttributes["name"]).Msg("container renamed")
|
||||
c.Name = event.ActorAttributes["name"]
|
||||
return c, false
|
||||
} else {
|
||||
return c, true
|
||||
}
|
||||
})
|
||||
}
|
||||
s.subscribers.Range(func(c context.Context, events chan<- ContainerEvent) bool {
|
||||
select {
|
||||
|
||||
@@ -35,9 +35,10 @@ type ContainerStat struct {
|
||||
|
||||
// ContainerEvent represents events that are triggered
|
||||
type ContainerEvent struct {
|
||||
ActorID string `json:"actorId"`
|
||||
Name string `json:"name"`
|
||||
Host string `json:"host"`
|
||||
Name string `json:"name"`
|
||||
Host string `json:"host"`
|
||||
ActorID string `json:"actorId"`
|
||||
ActorAttributes map[string]string `json:"actorAttributes,omitempty"`
|
||||
}
|
||||
|
||||
type LogPosition string
|
||||
|
||||
@@ -145,7 +145,7 @@ data: []
|
||||
|
||||
|
||||
event: container-event
|
||||
data: {"actorId":"1234","name":"start","host":"localhost"}
|
||||
data: {"name":"start","host":"localhost","actorId":"1234"}
|
||||
|
||||
/* snapshot: Test_handler_streamLogs_error_finding_container */
|
||||
HTTP/1.1 404 Not Found
|
||||
@@ -189,7 +189,7 @@ data: {"m":"INFO Testing logs...","ts":0,"id":4256192898,"l":"info","s":"stdout"
|
||||
|
||||
|
||||
event: container-event
|
||||
data: {"actorId":"123456","name":"container-stopped","host":"localhost"}
|
||||
data: {"name":"container-stopped","host":"localhost","actorId":"123456"}
|
||||
|
||||
/* snapshot: Test_handler_streamLogs_happy_container_stopped */
|
||||
HTTP/1.1 200 OK
|
||||
@@ -202,7 +202,7 @@ Content-Type: text/event-stream
|
||||
X-Accel-Buffering: no
|
||||
|
||||
event: container-event
|
||||
data: {"actorId":"123456","name":"container-stopped","host":"localhost"}
|
||||
data: {"name":"container-stopped","host":"localhost","actorId":"123456"}
|
||||
|
||||
/* snapshot: Test_handler_streamLogs_happy_with_id */
|
||||
HTTP/1.1 200 OK
|
||||
@@ -219,4 +219,4 @@ id: 1589396137772
|
||||
|
||||
|
||||
event: container-event
|
||||
data: {"actorId":"123456","name":"container-stopped","host":"localhost"}
|
||||
data: {"name":"container-stopped","host":"localhost","actorId":"123456"}
|
||||
@@ -59,9 +59,9 @@ func (h *handler) streamEvents(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
switch event.Name {
|
||||
case "start", "die", "destroy":
|
||||
if event.Name == "start" {
|
||||
log.Debug().Str("container", event.ActorID).Msg("container started")
|
||||
case "start", "die", "destroy", "rename":
|
||||
if event.Name == "start" || event.Name == "rename" {
|
||||
log.Debug().Str("action", event.Name).Str("id", event.ActorID).Msg("container event")
|
||||
|
||||
if containers, err := h.multiHostService.ListContainersForHost(event.Host); err == nil {
|
||||
if err := sseWriter.Event("containers-changed", containers); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user