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
COPY mapserver /bin/mapserver
ENV MT_CONFIG_PATH "/bin/mapserver.json"
ENV MT_LOGLEVEL "INFO"
ENV MT_READONLY "false"
EXPOSE 8080
ENTRYPOINT ["/bin/mapserver"]

23
main.go
View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"os"
"mapserver/app"
"mapserver/mapobject"
"mapserver/params"
@ -13,11 +14,19 @@ import (
)
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()
if p.Debug {
if p.Debug || env("MT_LOGLEVEL", "INFO") == "DEBUG" {
logrus.SetLevel(logrus.DebugLevel)
} else {
logrus.SetLevel(logrus.InfoLevel)
@ -39,15 +48,17 @@ func main() {
}
//parse Config
cfg, err := app.ParseConfig(app.ConfigFile)
cfg, err := app.ParseConfig(env("MT_CONFIG_PATH", app.ConfigFile))
if err != nil {
panic(err)
}
//write back config with all values
err = cfg.Save()
if err != nil {
panic(err)
if env("MT_READONLY", "false") != "true" {
err = cfg.Save()
if err != nil {
panic(err)
}
}
//exit after creating the config