Added Scratch Build with goembed FS

This commit is contained in:
Phil 2021-12-07 19:10:53 +01:00
parent 73ec092eb2
commit 4e0aa64d93
2 changed files with 16 additions and 5 deletions

View file

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

11
main.go
View file

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