Dockerfile, settable port

* added Dockerfile
* server listenting port is configurable via CLI argument
This commit is contained in:
zegkljan 2022-02-11 08:02:27 +01:00
parent 859d9c93ed
commit e2aa0d1aea
3 changed files with 24 additions and 2 deletions

19
Dockerfile Normal file
View File

@ -0,0 +1,19 @@
FROM alpine:3.15.0
RUN apk add --no-cache git go && \
mkdir /oko-server && \
cd /oko-server && \
git clone https://github.com/Cernobor/oko-server.git /oko-server/git && \
cd /oko-server/git && \
go build && \
cp /oko-server/git/oko-server /oko-server/ && \
cd /oko-server && \
rm -rf /oko-server/git && \
mkdir /data && \
apk del git go && \
rm -rf /root/go && \
echo -e '#!/bin/sh\n/oko-server/oko-server "$@"' > /oko-server/entrypoint.sh && \
chmod +x /oko-server/entrypoint.sh
VOLUME ["/data"]
ENTRYPOINT ["/oko-server/entrypoint.sh"]

View File

@ -14,8 +14,9 @@ import (
)
func main() {
dbFileArg := flag.String("dbfile", "./data.sqlite3", "File that holds the server's sqlite3 database. Will be created if it does not exist. Default is \"./data.sqlite3\".")
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.")
dbFileArg := flag.String("dbfile", "./data.sqlite3", "File that holds the server's sqlite3 database. Will be created if it does not exist. Default is \"./data.sqlite3\".")
apkFileArg := flag.String("apk", "", "APK file with the client app. If not specified, no APK will be available (404).")
reinitDBArg := flag.Bool("reinit-db", false, "Reinitializes the DB, which means all the tables will be recreated, deleting all data.")
minZoomArg := flag.Int("min-zoom", 1, "Minimum zoom that will be sent to clients.")
@ -31,6 +32,7 @@ func main() {
}
s := server.New(server.ServerConfig{
Port: *portArg,
DbPath: *dbFileArg,
TilepackPath: *tilepackFileArg,
ApkPath: *apkFileArg,

View File

@ -34,6 +34,7 @@ type Server struct {
}
type ServerConfig struct {
Port int
DbPath string
TilepackPath string
ApkPath string
@ -59,7 +60,7 @@ func (s *Server) Run(ctx context.Context) {
router := s.setupRouter()
server := &http.Server{
Addr: fmt.Sprintf(":%d", 8080),
Addr: fmt.Sprintf(":%d", s.config.Port),
Handler: router,
}
s.log.Infof("Running on %s", server.Addr)