diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..adc1c9d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:alpine AS builder +WORKDIR /build +ADD go.mod . +COPY . . +RUN go build +FROM alpine +WORKDIR /build +COPY --from=builder /build/wo-bisch-lorahandler /build/wo-bisch-lorahandler +CMD ["./wo-bisch-lorahandler"] +EXPOSE 8080 diff --git a/persistence.go b/persistence.go index 173a653..b804ccf 100644 --- a/persistence.go +++ b/persistence.go @@ -4,6 +4,7 @@ import ( "github.com/gomodule/redigo/redis" "log" "time" + "os" ) var globalPool *redis.Pool @@ -11,6 +12,14 @@ var globalPool *redis.Pool const alertsentPrefix string = "alertsent:" const devPrefix string = "dev:" +func getenv(key, fallback string) string { + value := os.Getenv(key) + if len(value) == 0 { + return fallback + } + return value +} + func newPool() *redis.Pool { return &redis.Pool{ // Maximum number of idle connections in the pool. @@ -20,7 +29,7 @@ func newPool() *redis.Pool { // Dial is an application supplied function for creating and // configuring a connection. Dial: func() (redis.Conn, error) { - c, err := redis.Dial("tcp", ":6379") + c, err := redis.Dial("tcp", getenv("REDIS_CONNECTION_STRING",":6379")) if err != nil { panic(err.Error()) } diff --git a/wo-bisch-lorahandler.go b/wo-bisch-lorahandler.go index fc7416a..4dc9a93 100644 --- a/wo-bisch-lorahandler.go +++ b/wo-bisch-lorahandler.go @@ -17,7 +17,7 @@ import ( ) const ( - outputfile = "/home/appuser/wo-bisch-lorahandler/wo-bisch-lorahandler.log" + outputfile = "/data/wo-bisch-lorahandler.log" ) type MessageProperties struct {