mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 03:26:37 +08:00
add docker hot update management
This commit is contained in:
@@ -79,6 +79,9 @@ func registerAdminDownloadClientRoutes(admin *gin.RouterGroup, svc *service.Cont
|
||||
|
||||
func registerAdminSystemRoutes(admin *gin.RouterGroup, svc *service.Container) {
|
||||
admin.POST("/system/scheduler/:name/trigger", schedulerTriggerHandler(svc))
|
||||
admin.GET("/system/update", systemUpdateStatusHandler(svc))
|
||||
admin.POST("/system/update/check", systemUpdateCheckHandler(svc))
|
||||
admin.POST("/system/update/apply", systemUpdateApplyHandler(svc))
|
||||
}
|
||||
|
||||
func registerAdminBackupRoutes(admin *gin.RouterGroup, svc *service.Container) {
|
||||
|
||||
@@ -131,6 +131,15 @@ func schemaHandler(_ *service.Container) gin.HandlerFunc {
|
||||
{"key": "license.hmac_secret", "type": "text", "label": "HMAC 签名密钥(旧版兼容)"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"key": "system-update",
|
||||
"label": "系统更新",
|
||||
"items": []gin.H{
|
||||
{"key": "system.update.image", "type": "text", "label": "应用镜像"},
|
||||
{"key": "system.update.watchtower_image", "type": "text", "label": "Watchtower 镜像"},
|
||||
{"key": "system.update.command", "type": "textarea", "label": "自定义更新命令"},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/ShukeBta/MediaStationGo/internal/service"
|
||||
)
|
||||
|
||||
func systemUpdateStatusHandler(svc *service.Container) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if svc.SystemUpdate == nil {
|
||||
c.JSON(http.StatusServiceUnavailable, gin.H{"error": "system update service unavailable"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, svc.SystemUpdate.Status(c.Request.Context()))
|
||||
}
|
||||
}
|
||||
|
||||
func systemUpdateCheckHandler(svc *service.Container) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if svc.SystemUpdate == nil {
|
||||
c.JSON(http.StatusServiceUnavailable, gin.H{"error": "system update service unavailable"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, svc.SystemUpdate.Check(c.Request.Context()))
|
||||
}
|
||||
}
|
||||
|
||||
func systemUpdateApplyHandler(svc *service.Container) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if svc.SystemUpdate == nil {
|
||||
c.JSON(http.StatusServiceUnavailable, gin.H{"error": "system update service unavailable"})
|
||||
return
|
||||
}
|
||||
status, err := svc.SystemUpdate.Apply(c.Request.Context())
|
||||
if err != nil {
|
||||
if errors.Is(err, service.ErrSystemUpdateRunning) {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": err.Error(), "status": status})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "status": status})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusAccepted, status)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user