1
0
mirror of https://github.com/Damillora/phoebe.git synced 2025-04-15 19:33:12 +00:00

Compare commits

...

6 Commits

56 changed files with 86 additions and 86 deletions

@ -3,30 +3,72 @@ on:
push:
branches:
- main
tags:
- "v*"
env:
IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/') && 'true' || 'false' }}
jobs:
release:
build:
runs-on: ubuntu-latest
strategy:
matrix:
platform: [linux/amd64,linux/arm64]
env:
IS_LINUX: ${{ startsWith(matrix.platform, 'linux/') && 'true' || 'false' }}
GIT_TAG: ${{ needs.git-version.outputs.git_tag }}
steps:
-
name: Sanitize platform name
id: set_platform
run: |
PLATFORM=$(echo ${{ matrix.platform }} | tr '/' '_')
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
name: Build Binaries
id: docker_build_bin
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform }}
target: runtime
outputs: |
type=local,dest=./output/${{ env.PLATFORM }}
-
name: Upload Binaries
uses: actions/upload-artifact@v4
with:
name: shioriko-${{ env.PLATFORM }}
path: ./output
retention-days: 7
-
name: Build and push (No tag)
if: env.IS_LINUX == 'true' && env.IS_RELEASE == 'false'
id: docker_build_git
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64,linux/arm64
tags: damillora/shioriko:latest
platforms: ${{ matrix.platform }}
tags: damillora/shioriko:main
-
name: Build and push (Tagged)
if: env.IS_LINUX == 'true' && env.IS_RELEASE == 'true'
id: docker_build_release
uses: docker/build-push-action@v6
with:
push: true
platforms: ${{ matrix.platform }}
tags: damillora/shioriko:${{ env.GIT_TAG }}, damillora/shioriko:latest
-
name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

@ -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,15 @@ 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.NoRoute(func(c *gin.Context) {
//c.String(http.StatusOK, "AAA")
c.FileFromFS("./app.html", http.FS(webFS))
})
g.StaticFS("/_app", http.FS(webAssets))
g.Static("/data", config.CurrentConfig.DataDirectory)
g.Use(cors.Default())
InitializeRoutes(g)

@ -1,13 +0,0 @@
package app
import (
"github.com/gin-gonic/gin"
)
func InitializeFrontendRoutes(g *gin.Engine) {
g.NoRoute(frontendHome)
}
func frontendHome(c *gin.Context) {
c.File("./web/static/index.html")
}

@ -11,6 +11,4 @@ func InitializeRoutes(g *gin.Engine) {
InitializeTagRoutes(g)
InitializeBlobRoutes(g)
InitializePostRoutes(g)
InitializeFrontendRoutes(g)
}

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
})
},
};

@ -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" }}