Skip to content

Commit 1e94d14

Browse files
authored
Dockerfile (#261)
1 parent 73287d3 commit 1e94d14

File tree

7 files changed

+68
-30
lines changed

7 files changed

+68
-30
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ jobs:
1919
uses: actions/setup-node@v4
2020
with:
2121
node-version: 18
22+
- name: Set up buf
23+
uses: bufbuild/buf-setup-action@v1.28.1
24+
with:
25+
github_token: ${{ secrets.GITHUB_TOKEN }}
2226
- name: Build Backend
23-
run: go build -v ./...
27+
run: |
28+
go generate ./...
29+
go build -v ./...
2430
- name: Test Backend
2531
run: go test -v -coverprofile=coverage.cov -coverpkg ./... -covermode=atomic ./...
2632
- name: Upload coverage reports to Codecov

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM golang as builder
2+
3+
WORKDIR /build
4+
5+
RUN apt update && apt install -y nodejs npm
6+
7+
ADD go.mod .
8+
ADD go.sum .
9+
10+
RUN go install github.com/bufbuild/buf/cmd/buf@latest
11+
12+
ADD . .
13+
14+
RUN go generate ./...
15+
RUN go build ./cmd/moneyd
16+
17+
FROM debian:stable-slim
18+
19+
COPY --from=builder /build/moneyd /
20+
21+
ENTRYPOINT [ "./moneyd"]

cmd/moneyd/moneyd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/oxisto/money-gopher/persistence"
3535
"github.com/oxisto/money-gopher/service/portfolio"
3636
"github.com/oxisto/money-gopher/service/securities"
37+
"github.com/oxisto/money-gopher/ui"
3738
)
3839

3940
var cmd moneydCmd
@@ -85,6 +86,7 @@ func (cmd *moneydCmd) Run() error {
8586
},
8687
)))
8788
mux.Handle(portfoliov1connect.NewSecuritiesServiceHandler(securities.NewService(db)))
89+
mux.Handle("/", ui.SvelteKitHandler("/"))
8890

8991
err = http.ListenAndServe(
9092
"localhost:8080",

ui/embed.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ui
2+
3+
import (
4+
"embed"
5+
"errors"
6+
"io/fs"
7+
"log"
8+
"net/http"
9+
"os"
10+
"strings"
11+
)
12+
13+
//go:generate npm i
14+
//go:generate npm run build
15+
//go:embed all:build
16+
var files embed.FS
17+
18+
func SvelteKitHandler(path string) http.Handler {
19+
fsys, err := fs.Sub(files, "build")
20+
if err != nil {
21+
log.Fatal(err)
22+
}
23+
filesystem := http.FS(fsys)
24+
25+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
26+
path := strings.TrimPrefix(r.URL.Path, path)
27+
_, err := filesystem.Open(path)
28+
if errors.Is(err, os.ErrNotExist) {
29+
path = "index.html"
30+
}
31+
r.URL.Path = path
32+
http.FileServer(filesystem).ServeHTTP(w, r)
33+
})
34+
}

ui/package-lock.json

Lines changed: 0 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"@connectrpc/connect-web": "^1.1.3",
1717
"@steeze-ui/heroicons": "^2.2.3",
1818
"@steeze-ui/svelte-icon": "^1.5.0",
19-
"@sveltejs/adapter-auto": "^2.0.0",
2019
"@sveltejs/adapter-static": "^2.0.3",
2120
"@sveltejs/kit": "^1.20.4",
2221
"@tailwindcss/forms": "^0.5.4",

ui/svelte.config.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import adapter from '@sveltejs/adapter-auto';
1+
import adapter from '@sveltejs/adapter-static';
22
import { vitePreprocess } from '@sveltejs/kit/vite';
33

44
/** @type {import('@sveltejs/kit').Config} */
@@ -8,10 +8,9 @@ const config = {
88
preprocess: vitePreprocess(),
99

1010
kit: {
11-
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
12-
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
13-
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
14-
adapter: adapter()
11+
adapter: adapter({
12+
fallback: 'index.html'
13+
})
1514
}
1615
};
1716

0 commit comments

Comments
 (0)