Mise a jour automatique programmee (crontab) par stack
- planification crontab par stack (autoupdate.json), incompatible avec l'exclusion
- scheduler a la minute ; pull puis down + up -d seulement si une image a change (mode autoapply)
- API PUT .../targets/{t}/auto et GET /api/cron (apercu des prochaines executions)
- interface : option dans le detail, badge sarcelle, vue de suivi "Mises a jour auto"
- TZ dans docker-compose / .env.example (tzdata embarque)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LNfwm6UCYFyvNQNSF5i9Gy
This commit is contained in:
1 parent
54cbab17cb
commit
51691d7b8a
16 files changed
+1010
-7
No files matched your search
@@ -0,0 +1,58 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/vblogio/stackwatch/internal/fleet"
|
||||
)
|
||||
|
||||
// tzName : fuseau dans lequel les planifications sont evaluees.
|
||||
func tzName() string {
|
||||
if tz := os.Getenv("TZ"); tz != "" {
|
||||
return tz
|
||||
}
|
||||
name, _ := time.Now().Zone()
|
||||
return name
|
||||
}
|
||||
|
||||
// autoUpdate programme (schedule) ou desactive (schedule vide) la mise a jour
|
||||
// automatique d'une stack.
|
||||
func (h *Handler) autoUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
if !h.admin(w, r) {
|
||||
return
|
||||
}
|
||||
var req struct {
|
||||
Dir string `json:"dir"`
|
||||
Schedule string `json:"schedule"`
|
||||
}
|
||||
if !h.decode(w, r, &req) {
|
||||
return
|
||||
}
|
||||
if err := h.Fleet.SetAuto(r.PathValue("id"), r.PathValue("target"), req.Dir, req.Schedule, UserID(r)); err != nil {
|
||||
fail(w, err)
|
||||
return
|
||||
}
|
||||
slog.Info("mise a jour automatique", "server", r.PathValue("id"), "target", r.PathValue("target"), "dir", req.Dir, "schedule", req.Schedule, "by", UserID(r))
|
||||
writeJSON(w, http.StatusOK, map[string]string{"schedule": req.Schedule})
|
||||
}
|
||||
|
||||
// cronPreview valide une planification et renvoie ses prochaines executions.
|
||||
func (h *Handler) cronPreview(w http.ResponseWriter, r *http.Request) {
|
||||
c, err := fleet.ParseCron(r.URL.Query().Get("expr"))
|
||||
if err != nil {
|
||||
fail(w, err)
|
||||
return
|
||||
}
|
||||
next := []time.Time{}
|
||||
t := time.Now()
|
||||
for range 3 {
|
||||
if t = c.Next(t); t.IsZero() {
|
||||
break
|
||||
}
|
||||
next = append(next, t)
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"next": next, "tz": tzName()})
|
||||
}
|
||||
Reference in new issue
Block a user