v0.15.13 generate release

This commit is contained in:
naiba 2023-11-28 23:01:37 +08:00
parent 7a774319dd
commit dc94259a56
8 changed files with 65 additions and 13 deletions

View File

@ -1,11 +1,12 @@
name: Dashboard image
name: Release
on:
workflow_run:
workflows: ["Run Tests"]
branches: [master]
types:
- completed
tags:
- "v*"
workflow_dispatch:
jobs:
@ -37,7 +38,7 @@ jobs:
v: true
x: false
race: false
ldflags: -s -w
ldflags: -s -w -X github.com/naiba/nezha/service/singleton.Version=${{ steps.extract_branch.outputs.tag }}
buildmode: default
- name: fix dist
@ -83,9 +84,25 @@ jobs:
platforms: linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/riscv64 # linux/386,
push: true
tags: |
${{ steps.image-name.outputs.GHRC_IMAGE_NAME }}:latest
${{ steps.image-name.outputs.GHRC_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:latest
${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
- name: Compress dist files
run: |
for file in dist/*; do
if [ -f "$file" ]; then
zip -r "$file.zip" "$file"
fi
done
- name: Release
- uses: ncipollo/release-action@v1
with:
artifacts: "dist/*.zip"
generateReleaseNotes: true
- name: Purge jsdelivr cache
run: |
curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/install.sh

View File

@ -15,7 +15,6 @@ RUN export DEBIAN_FRONTEND="noninteractive" && \
chmod +x /entrypoint.sh
WORKDIR /dashboard
COPY ./resource ./resource
COPY dist/dashboard-${TARGETOS}-${TARGETARCH} ./app
VOLUME ["/dashboard/data"]

View File

@ -4,7 +4,7 @@
<br>
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
<br><br>
<img src="https://img.shields.io/github/actions/workflow/status/naiba/nezha/dashboard.yml?label=Dash%20v0.15.13&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/github/v/release/nezhahq/agent?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/actions/workflow/status/nezhahq/agent/agent.yml?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.15.0-brightgreen?style=for-the-badge&logo=linux">
<img alt="GitHub release (with filter)" src="https://img.shields.io/github/v/release/naiba/nezha?style=for-the-badge&label=Dashboard">&nbsp;<img src="https://img.shields.io/github/v/release/nezhahq/agent?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/actions/workflow/status/nezhahq/agent/agent.yml?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.15.0-brightgreen?style=for-the-badge&logo=linux">
<br>
<br>
<p>:trollface: <b>Nezha Monitoring: Self-hostable, lightweight, servers and websites monitoring and O&M tool.</b></p>

View File

@ -3,6 +3,7 @@ package controller
import (
"fmt"
"html/template"
"io/fs"
"net/http"
"strconv"
"strings"
@ -15,20 +16,34 @@ import (
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/naiba/nezha/pkg/mygin"
"github.com/naiba/nezha/resource"
"github.com/naiba/nezha/service/singleton"
)
func ServeWeb(port uint) *http.Server {
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
tmpl := template.New("").Funcs(funcMap)
var err error
tmpl, err = tmpl.ParseFS(resource.TemplateFS, "template/**/*.html")
if err != nil {
panic(err)
}
tmpl, err = tmpl.ParseGlob("resource/template/**/*.html")
if err != nil {
panic(err)
}
r.SetHTMLTemplate(tmpl)
if singleton.Conf.Debug {
gin.SetMode(gin.DebugMode)
pprof.Register(r)
}
r.Use(mygin.RecordPath)
r.SetFuncMap(funcMap)
r.Static("/static", "resource/static")
r.LoadHTMLGlob("resource/template/**/*.html")
staticFs, err := fs.Sub(resource.StaticFS, "static")
if err != nil {
panic(err)
}
r.StaticFS("/static", http.FS(staticFs))
routers(r)
page404 := func(c *gin.Context) {

View File

@ -16,6 +16,7 @@ import (
"github.com/naiba/nezha/pkg/mygin"
"github.com/naiba/nezha/pkg/utils"
"github.com/naiba/nezha/proto"
"github.com/naiba/nezha/resource"
"github.com/naiba/nezha/service/singleton"
)
@ -863,7 +864,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
return
}
if !utils.IsFileExists("resource/template/theme-" + sf.Theme + "/home.html") {
if !utils.IsFileExists("resource/template/theme-"+sf.Theme+"/home.html") && !resource.IsTemplateFileExist("template/theme-"+sf.Theme+"/home.html") {
c.JSON(http.StatusOK, model.Response{
Code: http.StatusBadRequest,
Message: fmt.Sprintf("前台主题文件异常:%s", sf.Theme),
@ -871,7 +872,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
return
}
if !utils.IsFileExists("resource/template/dashboard-" + sf.DashboardTheme + "/setting.html") {
if !utils.IsFileExists("resource/template/dashboard-"+sf.DashboardTheme+"/setting.html") && !resource.IsTemplateFileExist("template/dashboard-"+sf.DashboardTheme+"/setting.html") {
c.JSON(http.StatusOK, model.Response{
Code: http.StatusBadRequest,
Message: fmt.Sprintf("后台主题文件异常:%s", sf.DashboardTheme),

19
resource/resource.go vendored Normal file
View File

@ -0,0 +1,19 @@
package resource
import (
"embed"
)
//go:embed static
var StaticFS embed.FS
//go:embed template
var TemplateFS embed.FS
//go:embed l10n
var I18nFS embed.FS
func IsTemplateFileExist(name string) bool {
_, err := TemplateFS.Open(name)
return err == nil
}

View File

@ -8,6 +8,7 @@ import (
"golang.org/x/text/language"
"github.com/naiba/nezha/model"
"github.com/naiba/nezha/resource"
)
var Localizer *i18n.Localizer
@ -20,13 +21,13 @@ func InitLocalizer() {
log.Println("NEZHA>> language not exists:", Conf.Language)
Conf.Language = "zh-CN"
} else {
_, err := bundle.LoadMessageFile("resource/l10n/" + Conf.Language + ".toml")
_, err := bundle.LoadMessageFileFS(resource.I18nFS, "l10n/"+Conf.Language+".toml")
if err != nil {
panic(err)
}
}
if _, err := bundle.LoadMessageFile("resource/l10n/zh-CN.toml"); err != nil {
if _, err := bundle.LoadMessageFileFS(resource.I18nFS, "l10n/zh-CN.toml"); err != nil {
panic(err)
}
Localizer = i18n.NewLocalizer(bundle, Conf.Language)

View File

@ -12,7 +12,7 @@ import (
"github.com/naiba/nezha/pkg/utils"
)
var Version = "v0.15.13" // !!记得修改 README 中的 badge 版本!!
var Version = "debug"
var (
Conf *model.Config