mirror of
https://github.com/Cernobor/oko-server.git
synced 2025-02-24 08:27:17 +00:00
* API endpoint * dockerfile adds commit hash and build time during build
This commit is contained in:
parent
7deb7e3f39
commit
1cf44e3bfc
@ -38,4 +38,3 @@ go.work
|
|||||||
oko-server
|
oko-server
|
||||||
*.sqlite*
|
*.sqlite*
|
||||||
.vscode
|
.vscode
|
||||||
.git
|
|
||||||
|
@ -3,9 +3,9 @@ FROM alpine:3.15.0 AS build
|
|||||||
VOLUME ["/data"]
|
VOLUME ["/data"]
|
||||||
COPY . /oko-server/git
|
COPY . /oko-server/git
|
||||||
|
|
||||||
RUN apk add --no-cache go && \
|
RUN apk add --no-cache go git && \
|
||||||
cd /oko-server/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
|
FROM alpine:3.15.0
|
||||||
WORKDIR /oko-server
|
WORKDIR /oko-server
|
||||||
|
13
main.go
13
main.go
@ -7,12 +7,18 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"cernobor.cz/oko-server/models"
|
"cernobor.cz/oko-server/models"
|
||||||
"cernobor.cz/oko-server/server"
|
"cernobor.cz/oko-server/server"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
sha1ver string
|
||||||
|
buildTime string
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
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.")
|
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.")
|
portArg := flag.Int("port", 8080, "Port where the server will listen to. Default is 8080.")
|
||||||
@ -31,7 +37,14 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t, err := time.Parse(time.RFC3339, buildTime)
|
||||||
|
if err != nil {
|
||||||
|
t = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
s := server.New(server.ServerConfig{
|
s := server.New(server.ServerConfig{
|
||||||
|
VersionHash: sha1ver,
|
||||||
|
BuildTime: &t,
|
||||||
Port: *portArg,
|
Port: *portArg,
|
||||||
DbPath: *dbFileArg,
|
DbPath: *dbFileArg,
|
||||||
TilepackPath: *tilepackFileArg,
|
TilepackPath: *tilepackFileArg,
|
||||||
|
@ -33,6 +33,11 @@ type Feature struct {
|
|||||||
PhotoIDs []FeaturePhotoID `json:"photo_ids"`
|
PhotoIDs []FeaturePhotoID `json:"photo_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BuildInfo struct {
|
||||||
|
VersionHash string `json:"version_hash"`
|
||||||
|
BuildTime *time.Time `json:"build_time"`
|
||||||
|
}
|
||||||
|
|
||||||
// transport objects
|
// transport objects
|
||||||
|
|
||||||
type Coords struct {
|
type Coords struct {
|
||||||
|
@ -2,6 +2,7 @@ package server
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
URIPing = "/ping"
|
URIPing = "/ping"
|
||||||
|
URIBuildInfo = "/build-info"
|
||||||
URIHardFail = "/hard-fail"
|
URIHardFail = "/hard-fail"
|
||||||
URISoftFail = "/soft-fail"
|
URISoftFail = "/soft-fail"
|
||||||
URIReinit = "/reinit"
|
URIReinit = "/reinit"
|
||||||
|
@ -81,6 +81,12 @@ func (s *Server) setupRouter() *gin.Engine {
|
|||||||
router.GET(URIPing, func(gc *gin.Context) {
|
router.GET(URIPing, func(gc *gin.Context) {
|
||||||
gc.Status(http.StatusNoContent)
|
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) {
|
router.GET(URIHardFail, func(gc *gin.Context) {
|
||||||
gc.Status(http.StatusNotImplemented)
|
gc.Status(http.StatusNotImplemented)
|
||||||
})
|
})
|
||||||
|
@ -35,6 +35,8 @@ type Server struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ServerConfig struct {
|
type ServerConfig struct {
|
||||||
|
VersionHash string
|
||||||
|
BuildTime *time.Time
|
||||||
Port int
|
Port int
|
||||||
DbPath string
|
DbPath string
|
||||||
TilepackPath string
|
TilepackPath string
|
||||||
|
Loading…
Reference in New Issue
Block a user