mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-08-30 12:07:45 +00:00
feat(docker): add /healthz endpoint and -healthcheck flag (#254)
Adds a Docker healthcheck and the small HTTP/CLI plumbing it needs. - Expose `GET /healthz` on the HTTP-mode server. - Add `-healthcheck` to dial `http://127.0.0.1:<port>/healthz` and exit with status. - Add a Dockerfile `HEALTHCHECK` instruction using `-healthcheck`. - Document HTTP-mode usage and stdio override guidance. Closes https://gitea.com/gitea/gitea-mcp/issues/146 Assisted by Codet. Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/254 Reviewed-by: silverwind <2021+silverwind@noreply.gitea.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// runHealthcheck dials the /healthz endpoint on 127.0.0.1:port and reports
|
||||
// success or failure. It returns true when the server responds with a 2xx
|
||||
// status.
|
||||
func runHealthcheck(client *http.Client, port int, stdout, stderr io.Writer) bool {
|
||||
url := fmt.Sprintf("http://127.0.0.1:%d/healthz", port)
|
||||
|
||||
resp, err := client.Get(url)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "healthcheck failed: %v\n", err)
|
||||
return false
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
|
||||
fmt.Fprintf(stderr, "healthcheck failed: unexpected status %s\n", resp.Status)
|
||||
return false
|
||||
}
|
||||
|
||||
fmt.Fprintln(stdout, "healthy")
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user