mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-24 06:28:42 +01:00
fix: fixes an edge case where a container might get stuck in created state (#3338)
This commit is contained in:
@@ -72,7 +72,7 @@ func (s *ContainerStore) checkConnectivity() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
running := lo.Filter(containers, func(item Container, index int) bool {
|
running := lo.Filter(containers, func(item Container, index int) bool {
|
||||||
return item.State == "running"
|
return item.State != "exited"
|
||||||
})
|
})
|
||||||
|
|
||||||
sem := semaphore.NewWeighted(maxFetchParallelism)
|
sem := semaphore.NewWeighted(maxFetchParallelism)
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ func Test_createRoutes_version(t *testing.T) {
|
|||||||
fs := afero.NewMemMapFs()
|
fs := afero.NewMemMapFs()
|
||||||
require.NoError(t, afero.WriteFile(fs, "index.html", []byte("index page"), 0644), "WriteFile should have no error.")
|
require.NoError(t, afero.WriteFile(fs, "index.html", []byte("index page"), 0644), "WriteFile should have no error.")
|
||||||
handler := createHandler(nil, afero.NewIOFS(fs), Config{Base: "/", Version: "dev", Authorization: Authorization{Provider: NONE}})
|
handler := createHandler(nil, afero.NewIOFS(fs), Config{Base: "/", Version: "dev", Authorization: Authorization{Provider: NONE}})
|
||||||
req, err := http.NewRequest("GET", "/version", nil)
|
req, err := http.NewRequest("GET", "/api/version", nil)
|
||||||
require.NoError(t, err, "NewRequest should not return an error.")
|
require.NoError(t, err, "NewRequest should not return an error.")
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
|
|||||||
18
internal/web/debug.go
Normal file
18
internal/web/debug.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *handler) debugStore(w http.ResponseWriter, r *http.Request) {
|
||||||
|
respone := make(map[string]interface{})
|
||||||
|
respone["hosts"] = h.multiHostService.Hosts()
|
||||||
|
containers, errors := h.multiHostService.ListAllContainers()
|
||||||
|
respone["containers"] = containers
|
||||||
|
respone["errors"] = errors
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
json.NewEncoder(w).Encode(respone)
|
||||||
|
}
|
||||||
@@ -67,6 +67,7 @@ func CreateServer(multiHostService *MultiHostService, content fs.FS, config Conf
|
|||||||
var fileServer http.Handler
|
var fileServer http.Handler
|
||||||
|
|
||||||
func createRouter(h *handler) *chi.Mux {
|
func createRouter(h *handler) *chi.Mux {
|
||||||
|
fileServer = http.FileServer(http.FS(h.content))
|
||||||
base := h.config.Base
|
base := h.config.Base
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
|
|
||||||
@@ -82,41 +83,46 @@ func createRouter(h *handler) *chi.Mux {
|
|||||||
if h.config.Authorization.Provider != NONE {
|
if h.config.Authorization.Provider != NONE {
|
||||||
r.Use(h.config.Authorization.Authorizer.AuthMiddleware)
|
r.Use(h.config.Authorization.Authorizer.AuthMiddleware)
|
||||||
}
|
}
|
||||||
r.Group(func(r chi.Router) {
|
|
||||||
|
r.Route("/api", func(r chi.Router) {
|
||||||
|
// Authenticated routes
|
||||||
r.Group(func(r chi.Router) {
|
r.Group(func(r chi.Router) {
|
||||||
if h.config.Authorization.Provider != NONE {
|
if h.config.Authorization.Provider != NONE {
|
||||||
r.Use(auth.RequireAuthentication)
|
r.Use(auth.RequireAuthentication)
|
||||||
}
|
}
|
||||||
r.Get("/api/hosts/{host}/containers/{id}/logs/stream", h.streamContainerLogs)
|
r.Get("/hosts/{host}/containers/{id}/logs/stream", h.streamContainerLogs)
|
||||||
r.Get("/api/hosts/{host}/containers/{id}/logs/download", h.downloadLogs)
|
r.Get("/hosts/{host}/containers/{id}/logs/download", h.downloadLogs)
|
||||||
r.Get("/api/hosts/{host}/containers/{id}/logs", h.fetchLogsBetweenDates)
|
r.Get("/hosts/{host}/containers/{id}/logs", h.fetchLogsBetweenDates)
|
||||||
r.Get("/api/hosts/{host}/logs/mergedStream/{ids}", h.streamLogsMerged)
|
r.Get("/hosts/{host}/logs/mergedStream/{ids}", h.streamLogsMerged)
|
||||||
r.Get("/api/stacks/{stack}/logs/stream", h.streamStackLogs)
|
r.Get("/stacks/{stack}/logs/stream", h.streamStackLogs)
|
||||||
r.Get("/api/services/{service}/logs/stream", h.streamServiceLogs)
|
r.Get("/services/{service}/logs/stream", h.streamServiceLogs)
|
||||||
r.Get("/api/groups/{group}/logs/stream", h.streamGroupedLogs)
|
r.Get("/groups/{group}/logs/stream", h.streamGroupedLogs)
|
||||||
r.Get("/api/events/stream", h.streamEvents)
|
r.Get("/events/stream", h.streamEvents)
|
||||||
if h.config.EnableActions {
|
if h.config.EnableActions {
|
||||||
r.Post("/api/hosts/{host}/containers/{id}/actions/{action}", h.containerActions)
|
r.Post("/hosts/{host}/containers/{id}/actions/{action}", h.containerActions)
|
||||||
}
|
}
|
||||||
r.Get("/api/releases", h.releases)
|
r.Get("/releases", h.releases)
|
||||||
r.Get("/api/profile/avatar", h.avatar)
|
r.Get("/profile/avatar", h.avatar)
|
||||||
r.Patch("/api/profile", h.updateProfile)
|
r.Patch("/profile", h.updateProfile)
|
||||||
r.Get("/version", h.version)
|
r.Get("/version", h.version)
|
||||||
|
if log.Debug().Enabled() {
|
||||||
|
r.Get("/debug/store", h.debugStore)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
defaultHandler := http.StripPrefix(strings.Replace(base+"/", "//", "/", 1), http.HandlerFunc(h.index))
|
// Public API routes
|
||||||
r.Get("/*", func(w http.ResponseWriter, req *http.Request) {
|
if h.config.Authorization.Provider == SIMPLE {
|
||||||
defaultHandler.ServeHTTP(w, req)
|
r.Post("/token", h.createToken)
|
||||||
})
|
r.Delete("/token", h.deleteToken)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if h.config.Authorization.Provider == SIMPLE {
|
|
||||||
r.Post("/api/token", h.createToken)
|
|
||||||
r.Delete("/api/token", h.deleteToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
r.Get("/healthcheck", h.healthcheck)
|
r.Get("/healthcheck", h.healthcheck)
|
||||||
|
|
||||||
|
defaultHandler := http.StripPrefix(strings.Replace(base+"/", "//", "/", 1), http.HandlerFunc(h.index))
|
||||||
|
r.Get("/*", func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
defaultHandler.ServeHTTP(w, req)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
if base != "/" {
|
if base != "/" {
|
||||||
@@ -125,8 +131,6 @@ func createRouter(h *handler) *chi.Mux {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fileServer = http.FileServer(http.FS(h.content))
|
|
||||||
|
|
||||||
// r.Mount("/debug", middleware.Profiler())
|
// r.Mount("/debug", middleware.Profiler())
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|||||||
Reference in New Issue
Block a user