[gogf/gf]2.1版本gf build命令没有进行pack打包

2024-06-25 165 views
0

2.1版本gf build命令没有进行pack打包

(1)gf build没有自动执行pack (2)手动pack文件到internal/packed/data.go,然后执行gf build,将编译后的可执行文件在同环境的新设备运行,结果无法运行,原因是manifest和resource的文件找不到。

config.yaml配置如下

gfcli:
  build:
    name: "gfCms"
    arch: "amd64"
    system: "linux"
    mod: "none"
    cgo: 0
    pack: "manifest/config,manifest/i18n,resource/public,resource/template"
    version: ""
    output: "./bin"
    extra: ""

回答

5

同问,项目没办法继续了...

2

看了下源码,原pack应改为如下两个配置,这样可以pack了,本地直接run的话,确实是读取的build_pack_data.go文件,但是build后的二进制文件运行仍然是找不到文件。

gfcli:
  build:
    packSrc: "manifest/config,resource/public,resource/template,resource/i18n"
    packDst: "internal/packed/build_pack_data.go"
7

@demozx 按照你的配置,并没有生效呢

GoFrame CLI Tool v2.1.4, https://goframe.org
GoFrame Version: v2.1.4 in current go.mod
CLI Installed At: /usr/local/sbin/gf
CLI Built Detail:
  Go Version:  go1.17.13
  GF Version:  v2.1.4
  Git Commit:  2022-08-26 15:45:41 a0619f7ff0e1d7766884e3062d1b3b0947c87da4
  Build Time:  2022-08-26 15:51:38

setting.toml配置文件如下

[gfcli]
    [gfcli.build]
        name=      "csdp-mgr"
        path=      "./bin"
        arch=      "amd64"
        system=    "linux"
        mod=       "none"
        cgo=       0
        packSrc=   "manifest/config,resource/i18n,resource/public"
        packDst=   "internal/packed/build_pack_data.go"
        version=   ""
        output=    ""
        extra=     ""

执行gf build 打包成功之后,把二进制文件放到另一个环境中执行报错:

root@xview:~# ./csdp-mgr
2022-09-20 18:16:34.903 [FATA] SetServerRoot failed: cannot find "/resource/public" in following paths:
1. /root
1. cannot find "/resource/public" in following paths:
1. /root
   1).  github.com/gogf/gf/v2/os/gfile.Search
        /root/go/pkg/mod/github.com/gogf/gf/v2@v2.1.4/os/gfile/gfile_search.go:55
   2).  github.com/gogf/gf/v2/net/ghttp.(*Server).SetServerRoot
        /root/go/pkg/mod/github.com/gogf/gf/v2@v2.1.4/net/ghttp/ghttp_server_config_static.go:57
   3).  github.com/gogf/gf/v2/net/ghttp.(*Server).SetConfig
        /root/go/pkg/mod/github.com/gogf/gf/v2@v2.1.4/net/ghttp/ghttp_server_config.go:355
   4).  github.com/gogf/gf/v2/net/ghttp.(*Server).SetConfigWithMap
        /root/go/pkg/mod/github.com/gogf/gf/v2@v2.1.4/net/ghttp/ghttp_server_config.go:336
   5).  github.com/gogf/gf/v2/frame/gins.Server.func1
        /root/go/pkg/mod/github.com/gogf/gf/v2@v2.1.4/frame/gins/gins_server.go:70
   6).  github.com/gogf/gf/v2/container/gmap.(*StrAnyMap).doSetWithLockCheck
        /root/go/pkg/mod/github.com/gogf/gf/v2@v2.1.4/container/gmap/gmap_hash_str_any_map.go:216
   7).  github.com/gogf/gf/v2/container/gmap.(*StrAnyMap).GetOrSetFuncLock
        /root/go/pkg/mod/github.com/gogf/gf/v2@v2.1.4/container/gmap/gmap_hash_str_any_map.go:253
   8).  github.com/gogf/gf/v2/frame/gins.Server
        /root/go/pkg/mod/github.com/gogf/gf/v2@v2.1.4/frame/gins/gins_server.go:37
   9).  github.com/gogf/gf/v2/frame/g.Server
        /root/go/pkg/mod/github.com/gogf/gf/v2@v2.1.4/frame/g/g_object.go:32
   10). csdp-mgr/internal/cmd.glob..func1
        /mnt/e/go-workspace/host-agent/csdp-mgr/internal/cmd/cmd.go:25
   11). github.com/gogf/gf/v2/os/gcmd.(*Command).doRun
        /root/go/pkg/mod/github.com/gogf/gf/v2@v2.1.4/os/gcmd/gcmd_command_run.go:148
   12). github.com/gogf/gf/v2/os/gcmd.(*Command).RunWithValueError
        /root/go/pkg/mod/github.com/gogf/gf/v2@v2.1.4/os/gcmd/gcmd_command_run.go:81
   13). github.com/gogf/gf/v2/os/gcmd.(*Command).RunWithValue
        /root/go/pkg/mod/github.com/gogf/gf/v2@v2.1.4/os/gcmd/gcmd_command_run.go:40
   14). github.com/gogf/gf/v2/os/gcmd.(*Command).Run
        /root/go/pkg/mod/github.com/gogf/gf/v2@v2.1.4/os/gcmd/gcmd_command_run.go:34
   15). main.main
        /mnt/e/go-workspace/host-agent/csdp-mgr/main.go:12

我姿势不对么?

6

@XiaobinZhao 确实有问题,resource/public无法被打包,可能是resource/public作为serverRoot的原因,继续等大佬修复吧

3

@stevenyangecho @XiaobinZhao @demozx 我看看呢。

1

@stevenyangecho @XiaobinZhao @demozx 不好意思各位,我check了一下,从某个版本开始,参数名称有调整,给大家一个示例的配置:

gfcli:
  # 工具编译配置
  build:
    name:     "focus"
    arch:     "amd64"
    system:   "darwin"
    packSrc:  "resource,manifest"
    mod:      ""
    cgo:      0

image

大家可以在代码中通过gres.Dump()方法查看打包的内存文件,我是这么来调试的: image 运行后,像这样的,这些文件都能被程序自动识别到,配置路径和开发时一样,程序代码不需要做额外设置: image

0

该issue关闭了哈,若还有问题请再提issue。

7

@gqcn 解决了。但是过程还是有点小曲折。

GoFrame CLI Tool v2.1.0-rc4, https://goframe.org
GoFrame Version: v2.1.4 in current go.mod
CLI Installed At: E:\go-workspace\bin\gf.exe
CLI Built Detail:
  Go Version:  go1.17.10
  GF Version:  v2.1.0-rc4
  Git Commit:  2022-06-01 16:36:40 0639becccc486fda179b81e7a685f67c91b173a4
  Build Time:  2022-06-01 16:34:52

我的配置文件config.toml

[server]
    address        = "0.0.0.0:8199"
    serverAgent    = "Csdp Mgr Server"
    openapiPath    = "/api.json"
    swaggerPath    = "/redoc"
    lang           = "zh-CN" 
    # serverRoot     = "/resource/public"   # 这个写法有点问题,要与gres 路径配合 
    serverRoot     = "resource/public"  

    errorLogPattern     = "error-{Y-m-d}.log"

[gfcli]
    [gfcli.build]
        name=      "csdp-mgr"
        path=      "./bin"
        arch=      "amd64"
        system=    "windows"
        mod=       "none"
        cgo=       0
        packSrc=   "manifest,resource"
        # packSrc=   ""manifest/config,resource/i18n,resource/public""  # 这种写法有点问题,需要与serverRoot进行配合
        version=   ""
        output=    ""
        extra=     ""

注意看我注释掉的2个配置语句。

以下是我的正常输出:

2022-10-12T02:52:29+00:00   0.00B manifest
2022-10-12T02:52:26+00:00   0.00B manifest/config
2022-10-12T02:52:26+00:00   1.78K manifest/config/config.toml
2022-07-14T08:35:51+00:00   1.89K manifest/config/config.toml.example
2022-07-14T08:35:51+00:00   0.00B manifest/docker
2022-07-14T08:35:51+00:00 922.00B manifest/docker/Dockerfile
2022-07-14T08:35:52+00:00  64.00B manifest/docker/docker.sh
2022-10-12T02:52:29+00:00   0.00B resource
2022-07-14T08:35:52+00:00   0.00B resource/i18n
2022-07-14T08:35:52+00:00   0.00B resource/i18n/.gitkeep
2022-07-14T08:35:52+00:00   0.00B resource/i18n/en
2022-07-14T08:35:52+00:00 579.00B resource/i18n/en/en.toml
2022-07-14T08:35:52+00:00   4.42K resource/i18n/en/validation.toml
2022-07-14T08:35:52+00:00   0.00B resource/i18n/zh-CN
2022-07-14T08:35:52+00:00   4.75K resource/i18n/zh-CN/validation.toml
2022-07-14T08:35:52+00:00 704.00B resource/i18n/zh-CN/zh-CN.toml
2022-07-14T08:35:52+00:00   0.00B resource/public
2022-07-14T08:35:52+00:00   0.00B resource/public/.gitkeep
2022-07-14T08:35:52+00:00   0.00B resource/public/swagger
2022-07-14T08:35:52+00:00 459.00B resource/public/swagger/favicon-16x16.png
2022-07-14T08:35:52+00:00 1006.00B resource/public/swagger/favicon-32x32.png
2022-07-14T08:35:52+00:00 202.00B resource/public/swagger/index.css
2022-07-14T08:35:52+00:00 799.00B resource/public/swagger/index.html
2022-07-14T08:35:52+00:00   2.63K resource/public/swagger/oauth2-redirect.html
2022-07-14T08:35:52+00:00 564.00B resource/public/swagger/swagger-initializer.js
2022-07-14T08:35:52+00:00   1.04M resource/public/swagger/swagger-ui-bundle.js
2022-07-14T08:35:52+00:00   1.47M resource/public/swagger/swagger-ui-bundle.js.map
2022-07-14T08:35:52+00:00 396.88K resource/public/swagger/swagger-ui-es-bundle-core.js
2022-07-14T08:35:52+00:00   1.21M resource/public/swagger/swagger-ui-es-bundle-core.js.map
2022-07-14T08:35:52+00:00   1.04M resource/public/swagger/swagger-ui-es-bundle.js
2022-07-14T08:35:52+00:00   1.46M resource/public/swagger/swagger-ui-es-bundle.js.map
2022-07-14T08:35:52+00:00 331.58K resource/public/swagger/swagger-ui-standalone-preset.js
2022-07-14T08:35:52+00:00 517.84K resource/public/swagger/swagger-ui-standalone-preset.js.map
2022-07-14T08:35:52+00:00 140.61K resource/public/swagger/swagger-ui.css
2022-07-14T08:35:52+00:00 269.83K resource/public/swagger/swagger-ui.css.map
2022-07-14T08:35:52+00:00 279.96K resource/public/swagger/swagger-ui.js
2022-07-14T08:35:52+00:00 295.72K resource/public/swagger/swagger-ui.js.map
2022-07-14T08:35:52+00:00   0.00B resource/scripts
2022-07-14T08:35:52+00:00   0.00B resource/scripts/.gitkeep
2022-07-14T08:35:52+00:00   0.00B resource/template
2022-07-14T08:35:52+00:00   0.00B resource/template/.gitkeep
TOTAL FILES: 41
2022-10-12 10:54:51.259 [DEBU] SetServerRoot path: resource/public
2022-10-12 10:54:51.311 [INFO] cmd.go:35: 全局设置当前语言为:zh-CN
2022-10-12 10:54:51.315 [INFO] swagger ui is serving at address: http://0.0.0.0:8199/redoc/
2022-10-12 10:54:51.315 [INFO] openapi specification is serving at address: http://0.0.0.0:8199/api.json
2022-10-12 10:54:51.319 [INFO] pid[470]: http server started listening on [0.0.0.0:8199]
... 省略...
3

@XiaobinZhao 我昨天又找郭大佬了,录了屏给大佬,看大佬怎么处理吧

4

@demozx 我解决了奥,你仔细看我的描述

1

@XiaobinZhao 我看到了,但是我觉得不能这样写是不应该的 packSrc: "manifest/config,resource/public,resource/template,resource/i18n"

2

@demozx 嗯嗯,这是个问题

9

这是个问题,后面我考虑下怎么改进