fix: move embed to repo root; make build sequential
- Move embed_prod.go/embed_dev.go out of cmd/wotra/ into root-level assets_prod.go / assets_dev.go (package assets). go:embed paths must be relative to the source file; cmd/wotra/ cannot reach ../../web/build. - Update cmd/wotra/main.go to import the root assets package. - Change mise.toml build task from parallel depends to sequential shell commands (build:web then build:go) so the frontend is always compiled before the Go embed runs.
This commit is contained in:
9
assets_dev.go
Normal file
9
assets_dev.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// assets_dev.go — used in non-production builds (no web/build required)
|
||||||
|
//go:build !production
|
||||||
|
|
||||||
|
package assets
|
||||||
|
|
||||||
|
import "io/fs"
|
||||||
|
|
||||||
|
// FS is nil in dev mode; the router skips static file serving.
|
||||||
|
var FS fs.FS
|
||||||
21
assets_prod.go
Normal file
21
assets_prod.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// assets_prod.go — used in production builds (requires web/build to exist)
|
||||||
|
//go:build production
|
||||||
|
|
||||||
|
package assets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"io/fs"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed all:web/build
|
||||||
|
var embeddedWeb embed.FS
|
||||||
|
|
||||||
|
// FS is the sub-filesystem rooted at web/build.
|
||||||
|
var FS fs.FS = func() fs.FS {
|
||||||
|
sub, err := fs.Sub(embeddedWeb, "web/build")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return sub
|
||||||
|
}()
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
// embed_dev.go — used in non-production builds (no web/build directory required)
|
|
||||||
//go:build !production
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import "io/fs"
|
|
||||||
|
|
||||||
// webFS is nil in dev mode; the router will skip static file serving.
|
|
||||||
var webFS fs.FS
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
// embed_prod.go — used in production builds (requires web/build to exist)
|
|
||||||
//go:build production
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"embed"
|
|
||||||
"io/fs"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:embed all:../../web/build
|
|
||||||
var embeddedWeb embed.FS
|
|
||||||
|
|
||||||
var webFS fs.FS = func() fs.FS {
|
|
||||||
sub, err := fs.Sub(embeddedWeb, "web/build")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return sub
|
|
||||||
}()
|
|
||||||
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/fs"
|
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -10,6 +9,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
assets "github.com/wotra/wotra"
|
||||||
"github.com/wotra/wotra/internal/config"
|
"github.com/wotra/wotra/internal/config"
|
||||||
"github.com/wotra/wotra/internal/handler"
|
"github.com/wotra/wotra/internal/handler"
|
||||||
"github.com/wotra/wotra/internal/service"
|
"github.com/wotra/wotra/internal/service"
|
||||||
@@ -56,13 +56,8 @@ func main() {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
go runMidnightGuard(ctx, entrySvc)
|
go runMidnightGuard(ctx, entrySvc)
|
||||||
|
|
||||||
// Static SPA files (embedded or from disk for dev)
|
// Static SPA files (embedded or nil for dev)
|
||||||
var staticFS fs.FS
|
router := handler.NewRouter(cfg.AuthToken, entrySvc, daySvc, settingsSvc, weekSvc, syncStore, entryStore, adjustmentStore, settingsStore, assets.FS)
|
||||||
if webFS != nil {
|
|
||||||
staticFS = webFS
|
|
||||||
}
|
|
||||||
|
|
||||||
router := handler.NewRouter(cfg.AuthToken, entrySvc, daySvc, settingsSvc, weekSvc, syncStore, entryStore, adjustmentStore, settingsStore, staticFS)
|
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: ":" + cfg.Port,
|
Addr: ":" + cfg.Port,
|
||||||
|
|||||||
@@ -10,8 +10,11 @@ DB_PATH = "wotra.db"
|
|||||||
TZ = "UTC"
|
TZ = "UTC"
|
||||||
|
|
||||||
[tasks.build]
|
[tasks.build]
|
||||||
description = "Build production single binary (web + Go)"
|
description = "Build production single binary (web + Go, sequential)"
|
||||||
depends = ["build:web", "build:go"]
|
run = """
|
||||||
|
mise run build:web
|
||||||
|
mise run build:go
|
||||||
|
"""
|
||||||
|
|
||||||
[tasks."build:web"]
|
[tasks."build:web"]
|
||||||
description = "Build Svelte frontend"
|
description = "Build Svelte frontend"
|
||||||
|
|||||||
Reference in New Issue
Block a user