Skip to content

Commit 1515a84

Browse files
markkrjttys3
authored andcommitted
Added /api/healthz to install routes.
This was needed for using /api/healthz endpoint in Docker healthchecks, otherwise, Docker would never become healthy if using healthz endpoint and users would not be able to complete the installation of Gitea.
1 parent d660e50 commit 1515a84

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

routers/install/routes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"code.gitea.io/gitea/modules/web"
1717
"code.gitea.io/gitea/modules/web/middleware"
1818
"code.gitea.io/gitea/routers/common"
19+
"code.gitea.io/gitea/routers/web/healthcheck"
1920
"code.gitea.io/gitea/services/forms"
2021

2122
"gitea.com/go-chi/session"
@@ -106,6 +107,7 @@ func Routes() *web.Route {
106107
r.Use(Init)
107108
r.Get("/", Install)
108109
r.Post("/", web.Bind(forms.InstallForm{}), SubmitInstall)
110+
r.Get("/api/healthz", healthcheck.CheckInstall)
109111

110112
r.NotFound(web.Wrap(installNotFound))
111113
return r

routers/web/healthcheck/check.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ type checks map[string][]componentStatus
5050
// response is the data returned by the health endpoint, which will be marshaled to JSON format
5151
type response struct {
5252
Status status `json:"status"`
53-
Description string `json:"description"` // a human-friendly description of the service
54-
Checks checks `json:"checks"` // The Checks Object
53+
Description string `json:"description"` // a human-friendly description of the service
54+
Checks checks `json:"checks,omitempty"` // The Checks Object, should be omitted on installation route
5555
}
5656

5757
// componentStatus presents one status of a single check object
@@ -88,6 +88,19 @@ func Check(w http.ResponseWriter, r *http.Request) {
8888
_, _ = w.Write(data)
8989
}
9090

91+
// CheckInstall always return pass. Should only be used in Install routes
92+
func CheckInstall(w http.ResponseWriter, r *http.Request) {
93+
rsp := response{
94+
Status: pass,
95+
Description: "Gitea: Installation stage",
96+
}
97+
98+
data, _ := json.MarshalIndent(rsp, "", " ")
99+
w.Header().Set("Content-Type", "application/json")
100+
w.WriteHeader(rsp.Status.ToHTTPStatus())
101+
_, _ = w.Write(data)
102+
}
103+
91104
// database checks gitea database status
92105
func checkDatabase(checks checks) status {
93106
st := componentStatus{}

0 commit comments

Comments
 (0)