1
0
forked from MTSR/mapserver

feat: added configuration options via Environment (#333)

This commit is contained in:
Nold 2023-09-18 06:47:45 +02:00 committed by GitHub
parent 2114ee5c32
commit 69b963ed6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View File

@ -1,4 +1,7 @@
FROM scratch FROM scratch
COPY mapserver /bin/mapserver COPY mapserver /bin/mapserver
ENV MT_CONFIG_PATH "/bin/mapserver.json"
ENV MT_LOGLEVEL "INFO"
ENV MT_READONLY "false"
EXPOSE 8080 EXPOSE 8080
ENTRYPOINT ["/bin/mapserver"] ENTRYPOINT ["/bin/mapserver"]

23
main.go
View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"os"
"mapserver/app" "mapserver/app"
"mapserver/mapobject" "mapserver/mapobject"
"mapserver/params" "mapserver/params"
@ -13,11 +14,19 @@ import (
) )
func main() { func main() {
//Parse command line //get Env or Default value
env := func(key string, defaultVal string) string {
val, ok := os.LookupEnv(key)
if !ok {
return defaultVal
}
return val
}
//Parse command line
p := params.Parse() p := params.Parse()
if p.Debug { if p.Debug || env("MT_LOGLEVEL", "INFO") == "DEBUG" {
logrus.SetLevel(logrus.DebugLevel) logrus.SetLevel(logrus.DebugLevel)
} else { } else {
logrus.SetLevel(logrus.InfoLevel) logrus.SetLevel(logrus.InfoLevel)
@ -39,15 +48,17 @@ func main() {
} }
//parse Config //parse Config
cfg, err := app.ParseConfig(app.ConfigFile) cfg, err := app.ParseConfig(env("MT_CONFIG_PATH", app.ConfigFile))
if err != nil { if err != nil {
panic(err) panic(err)
} }
//write back config with all values //write back config with all values
err = cfg.Save() if env("MT_READONLY", "false") != "true" {
if err != nil { err = cfg.Save()
panic(err) if err != nil {
panic(err)
}
} }
//exit after creating the config //exit after creating the config