make deployment container-ready

This commit is contained in:
Joerg Lehmann 2022-07-02 10:46:42 +02:00
parent ee28065d0f
commit 6d7b0871ad
3 changed files with 21 additions and 2 deletions

10
Dockerfile Normal file
View File

@ -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

View File

@ -4,6 +4,7 @@ import (
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"log" "log"
"time" "time"
"os"
) )
var globalPool *redis.Pool var globalPool *redis.Pool
@ -11,6 +12,14 @@ var globalPool *redis.Pool
const alertsentPrefix string = "alertsent:" const alertsentPrefix string = "alertsent:"
const devPrefix string = "dev:" 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 { func newPool() *redis.Pool {
return &redis.Pool{ return &redis.Pool{
// Maximum number of idle connections in the 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 // Dial is an application supplied function for creating and
// configuring a connection. // configuring a connection.
Dial: func() (redis.Conn, error) { Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", ":6379") c, err := redis.Dial("tcp", getenv("REDIS_CONNECTION_STRING",":6379"))
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())
} }

View File

@ -17,7 +17,7 @@ import (
) )
const ( const (
outputfile = "/home/appuser/wo-bisch-lorahandler/wo-bisch-lorahandler.log" outputfile = "/data/wo-bisch-lorahandler.log"
) )
type MessageProperties struct { type MessageProperties struct {