Skip to content

Commit 8a8aa21

Browse files
committed
embed static
1 parent 4c65d65 commit 8a8aa21

File tree

6 files changed

+40
-19
lines changed

6 files changed

+40
-19
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ _testmain.go
3636
device.json
3737
Go-Mirai-Client
3838
device-*.json
39-
static/
39+
static/static
4040
gmc-*.zip
4141
captcha.jpg
4242
/video

Dockerfile

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
FROM node:latest AS ui_builder
2+
3+
WORKDIR /build
4+
5+
RUN cd /build \
6+
&& git clone https://github.com/ProtobufBot/pbbot-react-ui.git \
7+
&& cd /build/pbbot-react-ui \
8+
&& npm install \
9+
&& npm run build
10+
111
FROM golang:1.16-alpine AS gmc_builder
212

313
RUN go env -w GO111MODULE=auto \
@@ -9,19 +19,10 @@ WORKDIR /build
919

1020
COPY ./ .
1121

12-
RUN cd /build \
13-
&& go build -ldflags "-s -w -extldflags '-static'" -o gmc
14-
15-
16-
FROM node:latest AS ui_builder
17-
18-
WORKDIR /build
22+
COPY --from=ui_builder /build/pbbot-react-ui/build ./static/static
1923

2024
RUN cd /build \
21-
&& git clone https://github.com/ProtobufBot/pbbot-react-ui.git \
22-
&& cd /build/pbbot-react-ui \
23-
&& yarn install \
24-
&& yarn build
25+
&& go build -ldflags "-s -w -extldflags '-static'" -o gmc
2526

2627
FROM alpine:latest
2728

@@ -30,8 +31,6 @@ WORKDIR /data
3031
COPY --from=gmc_builder /build/gmc /usr/bin/gmc
3132
RUN chmod +x /usr/bin/gmc
3233

33-
COPY --from=ui_builder /build/pbbot-react-ui/build /data/static
34-
3534
ADD ./scripts/env_run.sh /data/
3635

3736
RUN chmod +x /data/env_run.sh

build.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ done
4545
#done
4646

4747
#cp application.yml "${OUTPUT_DIR}/application.yml"
48-
cp -r static "${OUTPUT_DIR}/static" # https://github.com/ProtobufBot/Client-UI 前端编译产物dist
4948
cp ./scripts/* "${OUTPUT_DIR}/" # 复制运行脚本
5049

5150
echo "可以把不要的系统删掉">"${OUTPUT_DIR}/可以把不要的系统删掉"

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"github.com/ProtobufBot/Go-Mirai-Client/config"
1414
"github.com/ProtobufBot/Go-Mirai-Client/pkg/util"
1515
"github.com/ProtobufBot/Go-Mirai-Client/service/handler"
16+
"github.com/ProtobufBot/Go-Mirai-Client/static"
17+
1618
"github.com/gin-gonic/gin"
1719
log "github.com/sirupsen/logrus"
1820
)
@@ -130,7 +132,7 @@ func InitGin() {
130132
}
131133

132134
router.Use(handler.CORSMiddleware())
133-
router.Static("/", "./static")
135+
router.StaticFS("/", http.FS(static.MustGetStatic()))
134136
router.POST("/bot/create/v1", handler.CreateBot)
135137
router.POST("/bot/delete/v1", handler.DeleteBot)
136138
router.POST("/bot/list/v1", handler.ListBot)

service/bot/api_handler.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import (
66
"strconv"
77
_ "unsafe"
88

9-
"github.com/Mrs4s/MiraiGo/client"
10-
"github.com/Mrs4s/MiraiGo/message"
11-
"github.com/Mrs4s/MiraiGo/utils"
9+
1210
"github.com/ProtobufBot/Go-Mirai-Client/config"
1311
"github.com/ProtobufBot/Go-Mirai-Client/pkg/clz"
1412
"github.com/ProtobufBot/Go-Mirai-Client/proto_gen/onebot"
1513
"github.com/ProtobufBot/Go-Mirai-Client/service/cache"
14+
15+
"github.com/Mrs4s/MiraiGo/client"
16+
"github.com/Mrs4s/MiraiGo/message"
17+
"github.com/Mrs4s/MiraiGo/utils"
1618
log "github.com/sirupsen/logrus"
1719
)
1820

static/static.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package static
2+
3+
import (
4+
"embed"
5+
"io/fs"
6+
)
7+
8+
// 需要把前端文件放在static文件夹
9+
10+
//go:embed static
11+
var staticFs embed.FS
12+
13+
func MustGetStatic() fs.FS {
14+
f, err := fs.Sub(staticFs, "static")
15+
if err != nil {
16+
panic(err)
17+
}
18+
return f
19+
}

0 commit comments

Comments
 (0)