Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GO 编译时在此[golang:1.20-alpine]docker镜像内编译失败? #136

Open
admininfon opened this issue Apr 1, 2023 · 1 comment
Open

Comments

@admininfon
Copy link

admininfon commented Apr 1, 2023

shell: GOARCH=amd64 go build -o bin/hawk-grpc -ldflags "-s -w" .
  • Error:
package command-line-arguments
	imports hawk-rpc-go/config/viper
	imports hawk-rpc-go/config/qconf: build constraints exclude all Go files in /Users/kanghuixin/go/src/hawk-rpc-go/config/qconf

获取Qconf配置加载到viper组件内.

  • File:
    hawk-rpc-go/config/qconf/index.godriver/go/src/infra/go_qconf/go_qconf.go内容一致, 拷贝过来.

请查找下问题, 为啥忽略呢?

找到问题:

  1. 没有在该镜像编译安装QConf
  2. 没有加载cgo编译参数, 文件go_qconf.go import "C" 部分有注释说明, 添加 -L qconf -L m 参数

下面有追加镜像编译打包汇总.

@admininfon
Copy link
Author

  • Golang 编译步骤与问题汇总:
  1. centos:latest 镜像编译安装QConf
  2. 更新DNF与yum, LInk:https://haydenjames.io/fix-error-failed-to-download-metadata-for-repo-appstream-centos-8/
dnf --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos
dnf distro-sync
  1. 建立软链接: ln -s /usr/local/qconf/lib/libqconf.so /usr/lib64/libqconf.so 未找到libqconf.so解决方案
  2. go代理链接失败: go env -w GOPROXY=https://goproxy.cn,direct 解决方案
  3. 编译报错[build constraints exclude all Go files]: go build -o main-cli -ldflags "-L qconf -L m -s -w" . 添加cgo编译参数解决
  4. 感觉镜像比较大, 可以使用FROM ... AS build, COPY --from=build $DIST_DIR/bin $RPC_DIR/bin 压缩进新镜像减小体积

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant