AWS CodeDeploy AfterInstall脚本正在从code-deploy代理目录运行



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

这就是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

我在尝试不同的应用程序。像添加runas或在位置路径的开头添加"/"这样的Yml配置。它总是试图从/opt/codedeploy -agent/目录运行。

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

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

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

谢谢

Ok,

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

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

最新更新