gpt4 book ai didi

amazon-web-services - 运行代码部署 Hook 时找不到 Go 命令

转载 作者:数据小太阳 更新时间:2023-10-29 03:19:44 24 4
gpt4 key购买 nike

您好,我正在尝试为我的 golang 应用程序创建一个 CodeDeploy 部署。我有一个自动缩放组,它使用我创建的 AMI,它安装了我需要的所有库。当我尝试运行 CodeDeploy 时,它在我的 after_install 中存在错误:

LifecycleEvent - AfterInstall
Script - scripts/after_install.sh
[stderr]/opt/codedeploy-agent/deployment-root/a65d9a2e-fddd-471c-8ea1-c018792d00bd/d-4IKP3PP4Y/deployment-archive/scripts/after_install.sh:
line 4: go: command not found

我知道 go 安装在服务器上,我可以通过 sshing 进入服务器并运行 go 命令来验证。最初我让我的 after_install Hook 以 root 身份运行,这就是为什么我认为它提示没有安装 go 的原因。

我将其更新为以 ubuntu 运行,这里是 appspec 文件

version: 0.0
os: linux
files:
- source: ./
destination: ./home/ubuntu/code
hooks:
AfterInstall:
- location: scripts/after_install.sh
timeout: 180
runas: ubuntu
ApplicationStart:
- location: scripts/application_start.sh
timeout: 180
runas: root

但我仍然得到 go command not found 的错误。我以 ubuntu 用户身份通过​​ SSH 连接到服务器,我可以清楚地看到 go 已安装。

我更进一步并运行了 after_install.sh 文件,它没有任何错误。我在这里做错了什么?

只是为了更好奇,这里是我的 after_install.sh 文件

#!/bin/bash

cd /home/ubuntu/code/vibeify/cmd/vibeify
go build

最佳答案

如果只在交互式 shell 中可以使用没有完整安装路径的 go 命令,请检查 $HOME/.bashrc

这可能取决于操作系统的默认设置,但某些操作系统默认的 bashrc 文件包含不在非交互式 shell 中加载配置文件的脚本。

# open $HOME/.bashrc file
# and comment out these lines
case $- in
*i*) ;;
*) return;;
esac

关于amazon-web-services - 运行代码部署 Hook 时找不到 Go 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55858480/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com