Skip to content

Modern Docker Management, Designed for Everyone

refactor: move health check to dedicated api endpoint

Kyle Mendelld52c30820607
diff --git a/backend/internal/api/health_handler.go b/backend/internal/api/health_handler.go
new file mode 100644
index 000000000..f4a9d948f
--- /dev/null
+++ b/backend/internal/api/health_handler.go
@@ -0,0 +1,18 @@
+package api
+
+import (
+ "net/http"
+
+ "github.com/gin-gonic/gin"
+)
+
+func NewHealthHandler(group *gin.RouterGroup) {
+
+ group.GET("/health", func(c *gin.Context) {
+ c.JSON(http.StatusOK, gin.H{"status": "UP"})
+ })
+
+ group.HEAD("/health", func(c *gin.Context) {
+ c.Status(http.StatusOK)
+ })
+}
diff --git a/backend/internal/bootstrap/router_bootstrap.go b/backend/internal/bootstrap/router_bootstrap.go
index 7cb8f5e94..a220669ed 100644
--- a/backend/internal/bootstrap/router_bootstrap.go
+++ b/backend/internal/bootstrap/router_bootstrap.go
@@ -2,7 +2,6 @@ package bootstrap
import (
"log/slog"
- "net/http"
"path"
"strings"
@@ -34,8 +33,8 @@ func setupRouter(cfg *config.Config, appServices *Services) *gin.Engine {
"GET /img",
"GET /fonts",
"GET /api/system/stats",
- "GET /health",
- "HEAD /health",
+ "GET /api/health",
+ "HEAD /api/health",
}
router.Use(sloggin.NewWithConfig(slog.Default(), sloggin.Config{
@@ -62,11 +61,6 @@ func setupRouter(cfg *config.Config, appServices *Services) *gin.Engine {
corsMiddleware := middleware.NewCORSMiddleware(cfg).Add()
router.Use(corsMiddleware)
- // TODO :- Refactor to a api endpoint
- router.GET("/health", func(c *gin.Context) {
- c.JSON(http.StatusOK, gin.H{"status": "UP"})
- })
-
apiGroup := router.Group("/api")
if cfg.AgentMode {
@@ -74,6 +68,7 @@ func setupRouter(cfg *config.Config, appServices *Services) *gin.Engine {
return router
}
+ api.NewHealthHandler(apiGroup)
api.NewAuthHandler(apiGroup, appServices.User, appServices.Auth, appServices.Oidc, authMiddleware)
api.NewContainerHandler(apiGroup, appServices.Container, appServices.Image, authMiddleware)
api.NewContainerRegistryHandler(apiGroup, appServices.ContainerRegistry, authMiddleware)
diff --git a/docker-compose.yml b/docker-compose.yml
index 094a173d0..1177b4d9a 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -13,6 +13,12 @@ services:
- PGID=1000
- ENCRYPTION_KEY=xxxxxxxxxxxxxxxxxxxxxx
- JWT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxx
+ healthcheck:
+ test: ['CMD-SHELL', 'curl -fsS http://localhost:3552/api/health >/dev/null || exit 1']
+ interval: 10s
+ timeout: 3s
+ retries: 5
+ start_period: 15s
restart: unless-stopped
volumes: