make deployment container-ready

This commit is contained in:
Joerg Lehmann 2022-07-02 10:45:51 +02:00
parent 695df00ebd
commit 56fa4ab05f
5 changed files with 25 additions and 3 deletions

13
Dockerfile Normal file
View File

@ -0,0 +1,13 @@
FROM golang:alpine AS builder
WORKDIR /build
ADD go.mod .
COPY . .
RUN go build
FROM alpine
WORKDIR /build
COPY --from=builder /build/wo-bisch-web /build/wo-bisch-web
COPY snippets snippets
COPY templates templates
COPY static static
CMD ["./wo-bisch-web"]
EXPOSE 4000

View File

@ -2,6 +2,7 @@ package main
import (
"log"
"os"
)
// Contains tells whether a contains x.
@ -18,3 +19,11 @@ func Contains(a []string, x string) bool {
}
return false
}
func getenv(key, fallback string) string {
value := os.Getenv(key)
if len(value) == 0 {
return fallback
}
return value
}

View File

@ -136,6 +136,6 @@ func main() {
http.HandleFunc("/stripewebhook", stripeWebhookHandler)
logit("Starting Web Application...")
http.ListenAndServe("127.0.0.1:4000", nil)
http.ListenAndServe(":4000", nil)
logit("Terminating Web Application...")
}

View File

@ -112,7 +112,7 @@ func metricsHandler(response http.ResponseWriter, request *http.Request) {
mystart = start[0]
}
url := "http://localhost:8086/api/v2/query?org=wobischorg"
url := getenv("INFLUX_URL", "http://localhost:8086/api/v2/query?org=wobischorg")
data := []byte(fmt.Sprintf(`from(bucket:"wobischbucket")
|> range(start: %s, stop: %s)
|> filter(fn: (r) => r._measurement == "measurement")

View File

@ -26,7 +26,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())
}