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 {
|
||||
return item.State == "running"
|
||||
return item.State != "exited"
|
||||
})
|
||||
|
||||
sem := semaphore.NewWeighted(maxFetchParallelism)
|
||||
|
||||
@@ -71,7 +71,7 @@ func Test_createRoutes_version(t *testing.T) {
|
||||
fs := afero.NewMemMapFs()
|
||||
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}})
|
||||
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.")
|
||||
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
|
||||
|
||||
func createRouter(h *handler) *chi.Mux {
|
||||
fileServer = http.FileServer(http.FS(h.content))
|
||||
base := h.config.Base
|
||||
r := chi.NewRouter()
|
||||
|
||||
@@ -82,51 +83,54 @@ func createRouter(h *handler) *chi.Mux {
|
||||
if h.config.Authorization.Provider != NONE {
|
||||
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) {
|
||||
if h.config.Authorization.Provider != NONE {
|
||||
r.Use(auth.RequireAuthentication)
|
||||
}
|
||||
r.Get("/api/hosts/{host}/containers/{id}/logs/stream", h.streamContainerLogs)
|
||||
r.Get("/api/hosts/{host}/containers/{id}/logs/download", h.downloadLogs)
|
||||
r.Get("/api/hosts/{host}/containers/{id}/logs", h.fetchLogsBetweenDates)
|
||||
r.Get("/api/hosts/{host}/logs/mergedStream/{ids}", h.streamLogsMerged)
|
||||
r.Get("/api/stacks/{stack}/logs/stream", h.streamStackLogs)
|
||||
r.Get("/api/services/{service}/logs/stream", h.streamServiceLogs)
|
||||
r.Get("/api/groups/{group}/logs/stream", h.streamGroupedLogs)
|
||||
r.Get("/api/events/stream", h.streamEvents)
|
||||
r.Get("/hosts/{host}/containers/{id}/logs/stream", h.streamContainerLogs)
|
||||
r.Get("/hosts/{host}/containers/{id}/logs/download", h.downloadLogs)
|
||||
r.Get("/hosts/{host}/containers/{id}/logs", h.fetchLogsBetweenDates)
|
||||
r.Get("/hosts/{host}/logs/mergedStream/{ids}", h.streamLogsMerged)
|
||||
r.Get("/stacks/{stack}/logs/stream", h.streamStackLogs)
|
||||
r.Get("/services/{service}/logs/stream", h.streamServiceLogs)
|
||||
r.Get("/groups/{group}/logs/stream", h.streamGroupedLogs)
|
||||
r.Get("/events/stream", h.streamEvents)
|
||||
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("/api/profile/avatar", h.avatar)
|
||||
r.Patch("/api/profile", h.updateProfile)
|
||||
r.Get("/releases", h.releases)
|
||||
r.Get("/profile/avatar", h.avatar)
|
||||
r.Patch("/profile", h.updateProfile)
|
||||
r.Get("/version", h.version)
|
||||
if log.Debug().Enabled() {
|
||||
r.Get("/debug/store", h.debugStore)
|
||||
}
|
||||
})
|
||||
|
||||
// Public API routes
|
||||
if h.config.Authorization.Provider == SIMPLE {
|
||||
r.Post("/token", h.createToken)
|
||||
r.Delete("/token", h.deleteToken)
|
||||
}
|
||||
})
|
||||
|
||||
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 h.config.Authorization.Provider == SIMPLE {
|
||||
r.Post("/api/token", h.createToken)
|
||||
r.Delete("/api/token", h.deleteToken)
|
||||
}
|
||||
|
||||
r.Get("/healthcheck", h.healthcheck)
|
||||
|
||||
})
|
||||
|
||||
if base != "/" {
|
||||
r.Get(base, func(w http.ResponseWriter, req *http.Request) {
|
||||
http.Redirect(w, req, base+"/", http.StatusMovedPermanently)
|
||||
})
|
||||
}
|
||||
|
||||
fileServer = http.FileServer(http.FS(h.content))
|
||||
|
||||
// r.Mount("/debug", middleware.Profiler())
|
||||
|
||||
return r
|
||||
|
||||
Reference in New Issue
Block a user