feat: add auto update
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/containarr/server/internal/broker"
|
||||
agentv1 "github.com/containarr/server/internal/proto/agentv1"
|
||||
@ -125,11 +126,21 @@ func (g *Gateway) Tunnel(stream agentv1.AgentGateway_TunnelServer) error {
|
||||
})
|
||||
|
||||
case *agentv1.AgentMessage_Result:
|
||||
res := p.Result
|
||||
g.broker.Publish(broker.Event{
|
||||
Type: "command.result",
|
||||
AgentID: agentID,
|
||||
Payload: p.Result,
|
||||
Payload: res,
|
||||
})
|
||||
if containerID, found := g.registry.ResolvePendingUpdate(agentID, res.CommandId); found {
|
||||
now := time.Now()
|
||||
_ = g.store.UpdateAutoUpdateChecked(agentID, containerID, now)
|
||||
if res.Success {
|
||||
_ = g.store.UpdateAutoUpdateDone(agentID, containerID, now)
|
||||
} else {
|
||||
slog.Warn("update container failed", "agent_id", agentID, "container_id", containerID, "error", res.Error)
|
||||
}
|
||||
}
|
||||
|
||||
case *agentv1.AgentMessage_LogChunk:
|
||||
g.broker.Publish(broker.Event{
|
||||
@ -137,6 +148,29 @@ func (g *Gateway) Tunnel(stream agentv1.AgentGateway_TunnelServer) error {
|
||||
AgentID: agentID,
|
||||
Payload: p.LogChunk,
|
||||
})
|
||||
|
||||
case *agentv1.AgentMessage_FileResult:
|
||||
g.registry.ResolvePending(agentID, p.FileResult.CommandId, p.FileResult)
|
||||
|
||||
case *agentv1.AgentMessage_UpdateCheckResult:
|
||||
res := p.UpdateCheckResult
|
||||
if res.Error != "" {
|
||||
slog.Warn("update check error", "agent_id", agentID, "container_id", res.ContainerId, "error", res.Error)
|
||||
}
|
||||
_ = g.store.UpdateAutoUpdateChecked(agentID, res.ContainerId, time.Now())
|
||||
if res.UpdateAvailable {
|
||||
cmdID := newCommandID()
|
||||
slog.Info("update available, triggering UpdateContainerCommand", "agent_id", agentID, "container_id", res.ContainerId, "command_id", cmdID)
|
||||
g.registry.Send(agentID, &agentv1.ServerMessage{
|
||||
Payload: &agentv1.ServerMessage_UpdateContainer{
|
||||
UpdateContainer: &agentv1.UpdateContainerCommand{
|
||||
CommandId: cmdID,
|
||||
ContainerId: res.ContainerId,
|
||||
},
|
||||
},
|
||||
})
|
||||
g.registry.RegisterPendingUpdate(agentID, cmdID, res.ContainerId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user