diff --git a/.github/workflows/dashboard.yml b/.github/workflows/release.yml
similarity index 86%
rename from .github/workflows/dashboard.yml
rename to .github/workflows/release.yml
index 450d9e0c50..4af958625b 100644
--- a/.github/workflows/dashboard.yml
+++ b/.github/workflows/release.yml
@@ -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
diff --git a/Dockerfile b/Dockerfile
index b277ee938d..a709f94ce4 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -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"]
diff --git a/README.md b/README.md
index 8b460456df..d6a1f1400f 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
LOGO designed by 熊大 .
-
+
:trollface: Nezha Monitoring: Self-hostable, lightweight, servers and websites monitoring and O&M tool.
diff --git a/cmd/dashboard/controller/controller.go b/cmd/dashboard/controller/controller.go index 7b596d00e5..dfe8c92968 100644 --- a/cmd/dashboard/controller/controller.go +++ b/cmd/dashboard/controller/controller.go @@ -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) { diff --git a/cmd/dashboard/controller/member_api.go b/cmd/dashboard/controller/member_api.go index 5fa08f8e20..671bc00fb2 100644 --- a/cmd/dashboard/controller/member_api.go +++ b/cmd/dashboard/controller/member_api.go @@ -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), diff --git a/resource/resource.go b/resource/resource.go new file mode 100644 index 0000000000..635b4bccd2 --- /dev/null +++ b/resource/resource.go @@ -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 +} diff --git a/service/singleton/l10n.go b/service/singleton/l10n.go index 0ede9f39ae..749d3ef84f 100644 --- a/service/singleton/l10n.go +++ b/service/singleton/l10n.go @@ -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) diff --git a/service/singleton/singleton.go b/service/singleton/singleton.go index 2e52f7da11..1c25556eb7 100644 --- a/service/singleton/singleton.go +++ b/service/singleton/singleton.go @@ -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