Skip to content

Commit

Permalink
✨ v0.15.13 generate release
Browse files Browse the repository at this point in the history
  • Loading branch information
naiba committed Nov 28, 2023
1 parent 7a77431 commit dc94259
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 13 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/dashboard.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: Dashboard image
name: Release

on:
workflow_run:
workflows: ["Run Tests"]
branches: [master]
types:
- completed
tags:
- "v*"
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
21 changes: 18 additions & 3 deletions cmd/dashboard/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"fmt"
"html/template"
"io/fs"
"net/http"
"strconv"
"strings"
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions cmd/dashboard/controller/member_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -863,15 +864,15 @@ 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),
})
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),
Expand Down
19 changes: 19 additions & 0 deletions resource/resource.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 3 additions & 2 deletions service/singleton/l10n.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"golang.org/x/text/language"

"github.com/naiba/nezha/model"
"github.com/naiba/nezha/resource"
)

var Localizer *i18n.Localizer
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion service/singleton/singleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dc94259

Please sign in to comment.