Skip to content

Commit

Permalink
embed static
Browse files Browse the repository at this point in the history
  • Loading branch information
lz1998 committed Jul 23, 2021
1 parent 4c65d65 commit 8a8aa21
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ _testmain.go
device.json
Go-Mirai-Client
device-*.json
static/
static/static
gmc-*.zip
captcha.jpg
/video
Expand Down
25 changes: 12 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
FROM node:latest AS ui_builder

WORKDIR /build

RUN cd /build \
&& git clone https://github.com/ProtobufBot/pbbot-react-ui.git \
&& cd /build/pbbot-react-ui \
&& npm install \
&& npm run build

FROM golang:1.16-alpine AS gmc_builder

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

COPY ./ .

RUN cd /build \
&& go build -ldflags "-s -w -extldflags '-static'" -o gmc


FROM node:latest AS ui_builder

WORKDIR /build
COPY --from=ui_builder /build/pbbot-react-ui/build ./static/static

RUN cd /build \
&& git clone https://github.com/ProtobufBot/pbbot-react-ui.git \
&& cd /build/pbbot-react-ui \
&& yarn install \
&& yarn build
&& go build -ldflags "-s -w -extldflags '-static'" -o gmc

FROM alpine:latest

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

COPY --from=ui_builder /build/pbbot-react-ui/build /data/static

ADD ./scripts/env_run.sh /data/

RUN chmod +x /data/env_run.sh
Expand Down
1 change: 0 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ done
#done

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

echo "可以把不要的系统删掉">"${OUTPUT_DIR}/可以把不要的系统删掉"
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/ProtobufBot/Go-Mirai-Client/config"
"github.com/ProtobufBot/Go-Mirai-Client/pkg/util"
"github.com/ProtobufBot/Go-Mirai-Client/service/handler"
"github.com/ProtobufBot/Go-Mirai-Client/static"

"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -130,7 +132,7 @@ func InitGin() {
}

router.Use(handler.CORSMiddleware())
router.Static("/", "./static")
router.StaticFS("/", http.FS(static.MustGetStatic()))
router.POST("/bot/create/v1", handler.CreateBot)
router.POST("/bot/delete/v1", handler.DeleteBot)
router.POST("/bot/list/v1", handler.ListBot)
Expand Down
8 changes: 5 additions & 3 deletions service/bot/api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"strconv"
_ "unsafe"

"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/utils"

"github.com/ProtobufBot/Go-Mirai-Client/config"
"github.com/ProtobufBot/Go-Mirai-Client/pkg/clz"
"github.com/ProtobufBot/Go-Mirai-Client/proto_gen/onebot"
"github.com/ProtobufBot/Go-Mirai-Client/service/cache"

"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/utils"
log "github.com/sirupsen/logrus"
)

Expand Down
19 changes: 19 additions & 0 deletions static/static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package static

import (
"embed"
"io/fs"
)

// 需要把前端文件放在static文件夹

//go:embed static
var staticFs embed.FS

func MustGetStatic() fs.FS {
f, err := fs.Sub(staticFs, "static")
if err != nil {
panic(err)
}
return f
}

0 comments on commit 8a8aa21

Please sign in to comment.