【问题标题】:AWS CodeDeploy AfterInstall script is being run from code-deploy agent dirAWS CodeDeploy AfterInstall 脚本正在从代码部署代理目录运行
【发布时间】:2016-01-23 13:16:05
【问题描述】:

我正在尝试在 AWS 代码部署中运行 AfterInstall 脚本,但它是从 /opt/codedeploy-agent/ 目录而不是我的应用程序目录运行的。

appspec.yml 文件如下所示:

version: 0.0

os: linux

files:
  - source: /
    destination: /tmp/epub

hooks:
  AfterInstall:
    - location: server/install-packages.sh
      runas: root

如您所见,这是一个基本示例。

现在,bash 脚本如下所示:

#!/bin/bash
npm install

我只想 npm install 就可以了。

不幸的是,我收到了错误:

LifecycleEvent - AfterInstall
Script - server/install-packages.sh
[stderr]npm ERR! install Couldn't read dependencies
[stderr]npm ERR! Linux 3.13.0-48-generic
[stderr]npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
[stderr]npm ERR! node v4.2.1
[stderr]npm ERR! npm  v2.14.7
[stderr]npm ERR! path /opt/codedeploy-agent/package.json
[stderr]npm ERR! code ENOPACKAGEJSON
[stderr]npm ERR! errno -2
[stderr]npm ERR! syscall open
[stderr]
[stderr]npm ERR! package.json ENOENT: no such file or directory, open '/opt/codedeploy-agent/package.json'
[stderr]npm ERR! package.json This is most likely not a problem with npm itself.
[stderr]npm ERR! package.json npm can't find a package.json file in your current directory.
[stderr]
[stderr]npm ERR! Please include the following file with any support request:
[stderr]npm ERR!     /opt/codedeploy-agent/npm-debug.log

我尝试了不同的 appspec.yml 配置,例如在位置路径的开头添加 runas 或添加“/”。它一直试图从 /opt/codedeoploy-agent/ 目录运行。

无奈之下,我设置了脚本的绝对路径,但后来我得到了:

Script does not exist at specified location: /tmp/epub/server/install-packages.sh

这真的很烦人,因为我根据文档做所有事情,但可能我错过了一些非常非常小的东西!

谢谢

【问题讨论】:

    标签: node.js bash amazon-web-services aws-code-deploy


    【解决方案1】:

    好的,

    所以我发现,codedeoloy-agent 正在从代理在部署实例上创建的临时目录中运行 AfterInstall(可能还有所有其他步骤),所以在我的情况下,我必须通过 cd 修改 bash 脚本-ing 到正确的目录:

    #!/bin/bash
    cd /tmp/epub/server/
    npm install
    

    【讨论】:

    • 你在哪里找到的?
    • 我不记得我是否从这里得出结论:docs.aws.amazon.com/codedeploy/latest/userguide/… - 也许有一句话暗示 - 我记得我花了很长时间 - 或者更有可能是通过反复试验,或者两者的结合:)
    • @matewilk - 超级有帮助!
    • 谢谢,实际上这个问题被否决了,说“这个问题没有显示任何研究工作;它不清楚或没有用”。非常感谢,很高兴为您提供帮助!
    • 这是正确的,在测试过程中得到了同样的认识。另外仅供参考,您可以在 bash 脚本中使用“(cd /your/path && npm install)”在子shell中进行目录更改,这样它就不会影响其他事情。
    猜你喜欢
    • 1970-01-01
    • 2019-07-10
    • 1970-01-01
    • 2018-12-05
    • 1970-01-01
    • 2018-06-04
    • 2016-04-11
    • 2016-09-13
    • 2015-12-21
    相关资源
    最近更新 更多