feat: 将web打包到执行文件里

This commit is contained in:
tangtaoit
2023-06-18 15:49:06 +08:00
parent b68c81a1b2
commit 425aac327d
12 changed files with 107 additions and 7 deletions

View File

@@ -44,5 +44,4 @@ COPY --from=build /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
WORKDIR /home
COPY --from=build /go/release/app /home
COPY --from=build /go/release/web/dist /home/web/dist
ENTRYPOINT ["/home/app"]

View File

@@ -50,7 +50,7 @@ TODO
- [x] Supports Datasoure, seamless integration with your own business system data source
- [x] Supports WebSocket connections
- [x] Supports TLS 1.3
- [ ] Development of monitoring system
- [x] Development of monitoring system
- [ ] Support for Windows system deployment

View File

@@ -60,7 +60,7 @@
- [x] 支持Websocket连接
- [x] 支持TLS 1.3
- [x] 支持Prometheus监控
- [ ] 监控系统开发
- [x] 监控系统开发
- [ ] 支持Windows系统部署

View File

@@ -2,6 +2,7 @@ package server
import (
"fmt"
"io/fs"
"net/http"
"strconv"
"strings"
@@ -10,6 +11,7 @@ import (
"github.com/WuKongIM/WuKongIM/pkg/wklog"
"github.com/WuKongIM/WuKongIM/pkg/wkstore"
"github.com/WuKongIM/WuKongIM/pkg/wkutil"
"github.com/WuKongIM/WuKongIM/version"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
@@ -33,14 +35,16 @@ func (m *MonitorAPI) Route(r *wkhttp.WKHttp) {
r.GetGinRoute().Use(gzip.Gzip(gzip.DefaultCompression))
st, _ := fs.Sub(version.StaticFs, "web/dist")
r.GetGinRoute().NoRoute(func(c *gin.Context) {
if strings.HasPrefix(c.Request.URL.Path, "/web") {
c.File("./web/dist/index.html")
fmt.Println("----------->", c.Request.URL.Path)
c.FileFromFS("./index.html", http.FS(st))
return
}
})
r.Static("/web", "./web/dist")
r.GetGinRoute().StaticFS("/web", http.FS(st))
varz := NewVarzAPI(m.s)
connz := NewConnzAPI(m.s)

View File

@@ -1,10 +1,15 @@
package main
import (
"embed"
"github.com/WuKongIM/WuKongIM/cmd"
"github.com/WuKongIM/WuKongIM/version"
)
//go:embed web/dist
var f embed.FS
// go ldflags
var Version string // version
var Commit string // git commit id
@@ -17,6 +22,7 @@ func main() {
version.Commit = Commit
version.CommitDate = CommitDate
version.TreeState = TreeState
version.StaticFs = f
// logFile, err := os.OpenFile("./fatal.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0660)
// if err != nil {

View File

@@ -1,6 +1,10 @@
package version
import "embed"
var Version string // version
var Commit string // git commit id
var CommitDate string // git commit date
var TreeState string // git tree state
var StaticFs embed.FS // 静态资源

4
web/.gitignore vendored
View File

@@ -9,8 +9,8 @@ lerna-debug.log*
node_modules
.DS_Store
dist
dist-ssr
# dist
# dist-ssr
coverage
*.local

71
web/dist/assets/index-1ec75a8c.js vendored Normal file

File diff suppressed because one or more lines are too long

1
web/dist/assets/index-2deaa4fc.css vendored Normal file

File diff suppressed because one or more lines are too long

BIN
web/dist/assets/logo-9c3a9007.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

15
web/dist/index.html vendored Normal file
View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/web/logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>悟空IM</title>
<script type="module" crossorigin src="/web/assets/index-1ec75a8c.js"></script>
<link rel="stylesheet" href="/web/assets/index-2deaa4fc.css">
</head>
<body>
<div id="app"></div>
</body>
</html>

BIN
web/dist/logo.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB