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

使用docker-walle编译go项目报错 #1180

Open
WxYoung opened this issue Nov 19, 2021 · 2 comments
Open

使用docker-walle编译go项目报错 #1180

WxYoung opened this issue Nov 19, 2021 · 2 comments
Assignees
Labels

Comments

@WxYoung
Copy link

WxYoung commented Nov 19, 2021

我宿主机安装了go,安装路径: /usr/local/go

在docker-compose.yml配置了对应的映射

volumes:
  - /opt/walle_home/plugins/:/opt/walle_home/plugins/
  - /opt/walle_home/codebase/:/opt/walle_home/codebase/
  - /opt/walle_home/logs/:/opt/walle_home/logs/
  - /root/.ssh:/root/.ssh/
  - /usr/bin/go:/usr/bin/go
  - /root/.cache/go-build:/root/.cache/go-build
  - /root/go:/root/go
  - /root/gocode:/root/gocode
  - /usr/lib/golang:/usr/lib/golang
  - /usr/lib/golang/pkg/tool/linux_amd64:/usr/lib/golang/pkg/tool/linux_amd64
  - /www/go:/www/go
  - /usr/local/go:/usr/local/go

当我用docker exec -i -t 356f96c5d45c /bin/bash命令进入docker中时,执行go build 是成功的,但是在walle部署时报如下错误

build cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined

我怀疑是环境变量的问题,于是在walle 的项目配置-Deploy后置任务中,添加 go env ,结果报错:

missing $GOPATH

我想咨询一下,当我用/bin/bash命令进入docker 和 使用walle 直接部署时,环境变量会有什么不同吗?
或者有什么方法在我的docker里安装go环境吗?

@fengqi
Copy link

fengqi commented Feb 8, 2022

以ubuntu运行walle为例,在项目设置的自定义全局变量里加上:

HOME=/home/ubuntu
GOPATH=/home/ubuntu/.go/

不管是直接安装还是docker安装,瓦力都是本地执行命名的,有编译环境要求的,比如go相关配置,需要进行相关的配置,以及如果是php,且执行composer,也需要满足composer.json的要求,其实这样不好。

@silenceWe
Copy link

silenceWe commented Feb 11, 2022

walle 使用了第三方库fabric2来执行本地和远程命令,这个库在执行命令的时候会新开一个shell,在这个shell中默认会清空所有环境变量,官方文档说这样做是为了安全起见。

比较方便的解决办法是改源码:
walle/service/waller.py:43
加一个参数:replace_env=False,这样会使fabric2在执行本地命令时不清空环境变量
result = super(Waller, self).local(command, pty=pty,replace_env=False, warn=True, watchers=[say_yes()], env=self.custom_global_env, **kwargs)

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

No branches or pull requests

7 participants