feat: succesfully embed shioriko this time

This commit is contained in:
Damillora 2025-02-23 18:50:12 +00:00
parent 59f796331a
commit 51453a8e93
53 changed files with 34 additions and 62 deletions

View File

@ -1,23 +1,20 @@
FROM golang:1.23-alpine AS build # Web client
WORKDIR /go/src/shioriko
COPY . .
RUN go get -d -v ./...
RUN CGO_ENABLED=0 GOOS=linux go build -o /shioriko -ldflags '-extldflags "-static"' -tags timetzdata
RUN mkdir -p /web && cp -r web/static /web
FROM node:20-alpine AS node_build FROM node:20-alpine AS node_build
WORKDIR /src WORKDIR /src
COPY . . COPY . .
WORKDIR /src/web/app WORKDIR /src/pkg/web
RUN npm ci && npm run build RUN npm ci && npm run build
FROM scratch AS runtime # Go application
FROM golang:1.23-alpine AS build
WORKDIR /go/src/shioriko
COPY . .
COPY --from=node_build /src/pkg/web/build/ /go/src/shioriko/pkg/web/build/
RUN go get -d -v ./...
RUN CGO_ENABLED=0 GOOS=linux go build -o /shioriko -ldflags '-extldflags "-static"' -tags timetzdata
FROM scratch AS runtime
WORKDIR /app WORKDIR /app
COPY --from=build /shioriko /app/ COPY --from=build /shioriko /app/
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=node_build /src/web/static/ /app/web/static/
ENTRYPOINT ["/app/shioriko"] ENTRYPOINT ["/app/shioriko"]

View File

@ -1,35 +1,17 @@
package app package app
import ( import (
"embed" "io/fs"
"net/http" "net/http"
"os" "os"
"github.com/Damillora/Shioriko/pkg/config" "github.com/Damillora/Shioriko/pkg/config"
"github.com/Damillora/Shioriko/pkg/database" "github.com/Damillora/Shioriko/pkg/database"
"github.com/Damillora/Shioriko/pkg/web"
"github.com/gin-contrib/cors" "github.com/gin-contrib/cors"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
type embedFileSystem struct {
http.FileSystem
}
func (e embedFileSystem) Exists(prefix string, path string) bool {
_, err := e.Open(path)
if err != nil {
return false
}
return true
}
func EmbedFolder(fsEmbed embed.FS) static.ServeFileSystem {
return embedFileSystem{
FileSystem: http.FS(fsEmbed),
}
}
func Initialize() { func Initialize() {
config.InitializeConfig() config.InitializeConfig()
@ -49,8 +31,12 @@ func Initialize() {
func Start() { func Start() {
g := gin.Default() g := gin.Default()
g.StaticFile("/", "./web/static/index.html") webFS := web.WebAssets()
g.Static("/_app", "./web/static/_app") webAssets, _ := fs.Sub(webFS, "_app")
g.StaticFileFS("/", "./app.html", http.FS(webFS))
// g.StaticFile("/", "./pkg/web/build/index.html")
g.StaticFS("/_app", http.FS(webAssets))
g.Static("/data", config.CurrentConfig.DataDirectory) g.Static("/data", config.CurrentConfig.DataDirectory)
g.Use(cors.Default()) g.Use(cors.Default())

14
pkg/web/embed.go Normal file
View File

@ -0,0 +1,14 @@
package web
import (
"embed"
"io/fs"
)
//go:embed build/*
var webFS embed.FS
func WebAssets() fs.FS {
build, _ := fs.Sub(webFS, "build")
return build
}

View File

@ -12,8 +12,7 @@ const config = {
// If your environment is not supported or you settled on a specific environment, switch out the adapter. // 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. // See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter({ adapter: adapter({
fallback: 'index.html', // may differ from host to host, fallback: 'app.html', // may differ from host to host
pages: '../static',
}) })
}, },
}; };

View File

@ -1,2 +0,0 @@
*
!.gitignore

View File

@ -1,4 +0,0 @@
</body>
</html>

View File

@ -1,15 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<!--Use the title variable to set the title of the page-->
<title>{{ .title }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="UTF-8" />
<script defer src="/static/bundle.js"></script>
<link rel="stylesheet" href="/static/bundle.css">
<script>
window.BASE_URL = {{ .base_url }}
</script>
</head>
<body>

View File

@ -1,3 +0,0 @@
{{ template "header.html" .}}
{{ template "footer.html" }}