Skip to content

Commit d0dee4c

Browse files
committed
chore: added dockerfile
1 parent bfe2aa5 commit d0dee4c

3 files changed

Lines changed: 58 additions & 7 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- name: Test
4040
run: go test ./... || exit 0
4141
build:
42-
if: github.ref == 'refs/heads/master'
42+
if: github.ref == 'refs/heads/main'
4343
needs:
4444
- test
4545
strategy:
@@ -104,7 +104,7 @@ jobs:
104104

105105
merge:
106106
runs-on: ubuntu-latest
107-
if: github.ref == 'refs/heads/master'
107+
if: github.ref == 'refs/heads/main'
108108
needs:
109109
- build
110110
steps:

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM alpine AS cache
2+
3+
RUN apk add -U --no-cache ca-certificates
4+
5+
6+
FROM node:latest as frontend
7+
WORKDIR /app
8+
9+
COPY ./ui/package.json .
10+
COPY ./ui/package-lock.json .
11+
RUN npm install
12+
COPY ./ui .
13+
RUN npm run build
14+
15+
FROM golang:alpine as backend
16+
WORKDIR /app
17+
COPY ./api_go/go.mod ./api_go/go.sum ./
18+
RUN go mod download
19+
COPY . .
20+
COPY --from=frontend /assets/js/pad /assets/js/pad
21+
RUN go install github.com/a-h/templ/cmd/templ@latest
22+
23+
RUN templ generate
24+
RUN go build -o app .
25+
26+
27+
FROM scratch as runtime
28+
EXPOSE 3000
29+
COPY --from=backend /app/app /app
30+
COPY --from=cache /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
31+
ENTRYPOINT ["/app"]
32+
33+

main.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package main
22

33
import (
44
"context"
5+
"embed"
56
"fmt"
67
_ "fmt"
8+
"io/fs"
79
"net/http"
810
"path"
911
"strings"
@@ -53,6 +55,22 @@ func sessionMiddleware(h http.HandlerFunc) http.HandlerFunc {
5355
}
5456
}
5557

58+
//go:embed assets
59+
var content embed.FS
60+
61+
// Hilfsfunktion: registriert eine Fiber-Route, die Dateien aus dem eingebetteten
62+
// Unterverzeichnis `subPath` (z.B. `assets/css`) unter `route` (z.B. /css/) ausliefert.
63+
func registerEmbeddedStatic(app *fiber.App, route string, subPath string) {
64+
prefix := strings.TrimSuffix(route, "/")
65+
sub, err := fs.Sub(content, subPath)
66+
if err != nil {
67+
panic(err)
68+
}
69+
handler := http.StripPrefix(prefix+"/", http.FileServer(http.FS(sub)))
70+
// Matcht /css/* etc.
71+
app.Get(prefix+"/*", adaptor.HTTPHandler(handler))
72+
}
73+
5674
// @title Fiber Example API
5775
// @version 1.0
5876
// @description This is a sample swagger for Fiber
@@ -97,11 +115,11 @@ func main() {
97115
})
98116
app.Get("/swagger/*", swagger.HandlerDefault)
99117

100-
app.Static("/css/", "./assets/css")
101-
app.Static("/static/css/", "./assets/css/static/")
102-
app.Static("/static/skins/colibris/", "./assets/css/skin/")
103-
app.Static("/html/", "./assets/html")
104-
app.Static("/font/", "./assets/font")
118+
registerEmbeddedStatic(app, "/css/", "assets/css")
119+
registerEmbeddedStatic(app, "/static/css/", "assets/css/static")
120+
registerEmbeddedStatic(app, "/static/skins/colibris/", "assets/css/skin")
121+
registerEmbeddedStatic(app, "/html/", "assets/html")
122+
registerEmbeddedStatic(app, "/font/", "assets/font")
105123

106124
relativePath := "./src/js"
107125

0 commit comments

Comments
 (0)