英文:
run GO111MODULE=on go install . ./cmd/... in cloud init
问题
我有一个使用cloud init部署的bash脚本,我的bash脚本包含以下代码部分:
GO111MODULE=on go install . ./cmd/...
当我直接在部署的服务器终端中运行我的bash脚本时,它按预期工作。但是当我在cloud config中使用runcmd运行它时,脚本的这部分代码:
GO111MODULE=on go install . ./cmd/...
没有被执行,有人知道为什么吗?
runcmd:
- [ bash, /usr/local/bin/myscript.sh ]
英文:
I have a bash script which is deployed with cloud init, my bash script contains the following part of code
GO111MODULE=on go install . ./cmd/...
when running my bash script directly in the terminal of the deplyed server, it works as expected. But when i run it with runcmd in the cloud config, this part of the script:
GO111MODULE=on go install . ./cmd/...
does not get executed, anyone knows why?
runcmd:
- [ bash, /usr/local/bin/myscript.sh ]
答案1
得分: 2
在runcmd
中正确的shell执行方式如下(在Cloud config examples中可见):
- [ bash, -c, /usr/local/bin/myscript.sh ]
或者:
- [ /usr/local/bin/myscript.sh ]
假设你的脚本以shebang #!/bin/bash
开始。
此外,你需要在脚本中添加任何环境变量,因为Cloud config examples中没有明显的设置环境变量的方法。
#!/bin/bash
export GO111MODULE=on
export ...
英文:
A proper shell execution in runcmd
would be (as seen in Cloud config examples):
- [ bash, -c, /usr/local/bin/myscript.sh ]
or:
- [ /usr/local/bin/myscript.sh ]
Assuming your script starts with a shebang #!/bin/bash
Plus, you need to add any environment variable inside the script, as Cloud config examples do not include any obvious way to set them.
#!/bin/bash
export GO111MODULE=on
export ...
答案2
得分: 1
感谢VonC的提示,我成功解决了问题。我在myscript.sh中添加了以下内容:
GOCACHE=/root/.cache/go-build
export GOCACHE
export GO111MODULE=on
go install . ./cmd/...
runcmd:
- [ bash, -c, /usr/local/bin/myscript.sh ]
现在脚本可以从cloud-init部署和运行了。
英文:
Thanks to the tip from VonC, i was able to fix the issue. i added the following to myscript.sh
GOCACHE=/root/.cache/go-build
export GOCACHE
export GO111MODULE=on
go install . ./cmd/...
runcmd:
- [ bash, -c, /usr/local/bin/myscript.sh ]
the script now deploys and runs from cloud-init.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论