diff --git a/router/router.go b/router/router.go index 3fe2ad7db..64dd99684 100644 --- a/router/router.go +++ b/router/router.go @@ -169,6 +169,9 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl ) } + e.GET("/version", server.Version) + e.GET("/healthz", server.Health) + return e } diff --git a/server/z.go b/server/z.go new file mode 100644 index 000000000..69df93ada --- /dev/null +++ b/server/z.go @@ -0,0 +1,24 @@ +package server + +import ( + "github.com/drone/drone/store" + "github.com/drone/drone/version" + "github.com/gin-gonic/gin" +) + +// Health endpoint returns a 500 if the server state is unhealthy. +func Health(c *gin.Context) { + if err := store.FromContext(c).Ping(); err != nil { + c.String(500, err.Error()) + return + } + c.String(200, "") +} + +// Version endpoint returns the server version and build information. +func Version(c *gin.Context) { + c.JSON(200, gin.H{ + "source": "https://github.com/drone/drone", + "version": version.Version.String(), + }) +} diff --git a/store/store.go b/store/store.go index 4ee187d1c..ccfd635fe 100644 --- a/store/store.go +++ b/store/store.go @@ -139,6 +139,8 @@ type Store interface { TaskList() ([]*model.Task, error) TaskInsert(*model.Task) error TaskDelete(string) error + + Ping() error } // GetUser gets a user by unique ID.