mirror of
https://github.com/Damillora/phoebe.git
synced 2025-03-10 05:57:22 +00:00
feat: succesfully embed shioriko this time
This commit is contained in:
parent
59f796331a
commit
51453a8e93
23
Dockerfile
23
Dockerfile
@ -1,23 +1,20 @@
|
||||
FROM golang:1.23-alpine AS build
|
||||
|
||||
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
|
||||
|
||||
# Web client
|
||||
FROM node:20-alpine AS node_build
|
||||
WORKDIR /src
|
||||
COPY . .
|
||||
WORKDIR /src/web/app
|
||||
WORKDIR /src/pkg/web
|
||||
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
|
||||
COPY --from=build /shioriko /app/
|
||||
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"]
|
||||
|
@ -1,35 +1,17 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/Damillora/Shioriko/pkg/config"
|
||||
"github.com/Damillora/Shioriko/pkg/database"
|
||||
"github.com/Damillora/Shioriko/pkg/web"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-contrib/static"
|
||||
"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() {
|
||||
config.InitializeConfig()
|
||||
|
||||
@ -49,10 +31,14 @@ func Initialize() {
|
||||
func Start() {
|
||||
g := gin.Default()
|
||||
|
||||
g.StaticFile("/", "./web/static/index.html")
|
||||
g.Static("/_app", "./web/static/_app")
|
||||
webFS := web.WebAssets()
|
||||
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.Use(cors.Default())
|
||||
|
||||
InitializeRoutes(g)
|
||||
|
0
web/app/.gitignore → pkg/web/.gitignore
vendored
0
web/app/.gitignore → pkg/web/.gitignore
vendored
14
pkg/web/embed.go
Normal file
14
pkg/web/embed.go
Normal 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
|
||||
}
|
@ -12,8 +12,7 @@ const config = {
|
||||
// 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({
|
||||
fallback: 'index.html', // may differ from host to host,
|
||||
pages: '../static',
|
||||
fallback: 'app.html', // may differ from host to host
|
||||
})
|
||||
},
|
||||
};
|
2
web/static/.gitignore
vendored
2
web/static/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
@ -1,4 +0,0 @@
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -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>
|
||||
|
@ -1,3 +0,0 @@
|
||||
{{ template "header.html" .}}
|
||||
|
||||
{{ template "footer.html" }}
|
Loading…
x
Reference in New Issue
Block a user