diff --git a/.dockerignore b/.dockerignore index 16380d1..87b418e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -38,4 +38,3 @@ go.work oko-server *.sqlite* .vscode -.git diff --git a/Dockerfile b/Dockerfile index 81a538e..d206b54 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,9 @@ FROM alpine:3.15.0 AS build VOLUME ["/data"] COPY . /oko-server/git -RUN apk add --no-cache go && \ +RUN apk add --no-cache go git && \ cd /oko-server/git && \ - go build + go build -ldflags "-X \"main.sha1ver=$(git rev-parse HEAD)\" -X \"main.buildTime=$(date -Iseconds)\"" FROM alpine:3.15.0 WORKDIR /oko-server diff --git a/main.go b/main.go index d65b120..150ab8b 100644 --- a/main.go +++ b/main.go @@ -7,12 +7,18 @@ import ( "os" "os/signal" "syscall" + "time" "cernobor.cz/oko-server/models" "cernobor.cz/oko-server/server" "github.com/sirupsen/logrus" ) +var ( + sha1ver string + buildTime string +) + func main() { tilepackFileArg := flag.String("tilepack", "", "File that will be sent to clients when they request a tile pack, also used to serve tiles in online mode. Required.") portArg := flag.Int("port", 8080, "Port where the server will listen to. Default is 8080.") @@ -31,7 +37,14 @@ func main() { os.Exit(1) } + t, err := time.Parse(time.RFC3339, buildTime) + if err != nil { + t = time.Now() + } + s := server.New(server.ServerConfig{ + VersionHash: sha1ver, + BuildTime: &t, Port: *portArg, DbPath: *dbFileArg, TilepackPath: *tilepackFileArg, diff --git a/models/models.go b/models/models.go index 7b6955d..bcc1715 100644 --- a/models/models.go +++ b/models/models.go @@ -33,6 +33,11 @@ type Feature struct { PhotoIDs []FeaturePhotoID `json:"photo_ids"` } +type BuildInfo struct { + VersionHash string `json:"version_hash"` + BuildTime *time.Time `json:"build_time"` +} + // transport objects type Coords struct { diff --git a/server/constants.go b/server/constants.go index cde890c..f6dead3 100644 --- a/server/constants.go +++ b/server/constants.go @@ -2,6 +2,7 @@ package server const ( URIPing = "/ping" + URIBuildInfo = "/build-info" URIHardFail = "/hard-fail" URISoftFail = "/soft-fail" URIReinit = "/reinit" diff --git a/server/handling.go b/server/handling.go index c8511d2..e83224b 100644 --- a/server/handling.go +++ b/server/handling.go @@ -81,6 +81,12 @@ func (s *Server) setupRouter() *gin.Engine { router.GET(URIPing, func(gc *gin.Context) { gc.Status(http.StatusNoContent) }) + router.GET(URIBuildInfo, func(gc *gin.Context) { + gc.JSON(http.StatusOK, models.BuildInfo{ + VersionHash: s.config.VersionHash, + BuildTime: s.config.BuildTime, + }) + }) router.GET(URIHardFail, func(gc *gin.Context) { gc.Status(http.StatusNotImplemented) }) diff --git a/server/server.go b/server/server.go index d9e0bf1..32e1d16 100644 --- a/server/server.go +++ b/server/server.go @@ -35,6 +35,8 @@ type Server struct { } type ServerConfig struct { + VersionHash string + BuildTime *time.Time Port int DbPath string TilepackPath string