Skip to content

Commit

Permalink
Dockerfile (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Dec 20, 2023
1 parent 73287d3 commit 1e94d14
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 30 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 18
- name: Set up buf
uses: bufbuild/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Backend
run: go build -v ./...
run: |
go generate ./...
go build -v ./...
- name: Test Backend
run: go test -v -coverprofile=coverage.cov -coverpkg ./... -covermode=atomic ./...
- name: Upload coverage reports to Codecov
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM golang as builder

WORKDIR /build

RUN apt update && apt install -y nodejs npm

ADD go.mod .
ADD go.sum .

RUN go install github.com/bufbuild/buf/cmd/buf@latest

ADD . .

RUN go generate ./...
RUN go build ./cmd/moneyd

FROM debian:stable-slim

COPY --from=builder /build/moneyd /

ENTRYPOINT [ "./moneyd"]
2 changes: 2 additions & 0 deletions cmd/moneyd/moneyd.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/oxisto/money-gopher/persistence"
"github.com/oxisto/money-gopher/service/portfolio"
"github.com/oxisto/money-gopher/service/securities"
"github.com/oxisto/money-gopher/ui"
)

var cmd moneydCmd
Expand Down Expand Up @@ -85,6 +86,7 @@ func (cmd *moneydCmd) Run() error {
},
)))
mux.Handle(portfoliov1connect.NewSecuritiesServiceHandler(securities.NewService(db)))
mux.Handle("/", ui.SvelteKitHandler("/"))

err = http.ListenAndServe(
"localhost:8080",
Expand Down
34 changes: 34 additions & 0 deletions ui/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ui

import (
"embed"
"errors"
"io/fs"
"log"
"net/http"
"os"
"strings"
)

//go:generate npm i
//go:generate npm run build
//go:embed all:build
var files embed.FS

func SvelteKitHandler(path string) http.Handler {
fsys, err := fs.Sub(files, "build")
if err != nil {
log.Fatal(err)
}
filesystem := http.FS(fsys)

return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
path := strings.TrimPrefix(r.URL.Path, path)
_, err := filesystem.Open(path)
if errors.Is(err, os.ErrNotExist) {
path = "index.html"
}
r.URL.Path = path
http.FileServer(filesystem).ServeHTTP(w, r)
})
}
23 changes: 0 additions & 23 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"@connectrpc/connect-web": "^1.1.3",
"@steeze-ui/heroicons": "^2.2.3",
"@steeze-ui/svelte-icon": "^1.5.0",
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/kit": "^1.20.4",
"@tailwindcss/forms": "^0.5.4",
Expand Down
9 changes: 4 additions & 5 deletions ui/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import adapter from '@sveltejs/adapter-auto';
import adapter from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/kit/vite';

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

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

Expand Down

0 comments on commit 1e94d14

Please sign in to comment.