From 4e0aa64d93ebb98d640d5375ca63c797ed8555ff Mon Sep 17 00:00:00 2001 From: Phil Date: Tue, 7 Dec 2021 19:10:53 +0100 Subject: [PATCH] Added Scratch Build with goembed FS --- Dockerfile | 10 +++++++--- main.go | 11 +++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index bdf22d4..3f0137c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:alpine +FROM golang:alpine as builder RUN apk add --no-cache gcc libgo @@ -6,6 +6,10 @@ WORKDIR /go/src/git.ucode.space/goshorly COPY . . RUN go get -d -v ./... -RUN go build -o app . +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . -CMD ["./app"] + +FROM scratch as production +WORKDIR /goshorly +copy --from=builder /go/src/git.ucode.space/goshorly/app /goshorly/app +CMD ["./app"] \ No newline at end of file diff --git a/main.go b/main.go index e8d583e..44ff297 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "embed" "log" "net/http" "regexp" @@ -14,10 +15,16 @@ import ( ) func main() { - engine := html.NewFileSystem(http.Dir("./views"), ".html") + + //go:embed views/* + var viewsfs embed.FS + + engine := html.NewFileSystem(http.FS(viewsfs), ".html") app := fiber.New(fiber.Config{ - Views: engine, + CaseSensitive: true, + ServerHeader: "goshorly", + Views: engine, }) client := redis.NewClient(&redis.Options{