AWS CodeDeploy AfterInstall 脚本正在从代码部署代理目录运行

2024-03-10

我正在尝试在 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

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

Thanks


Ok,

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

#!/bin/bash
cd /tmp/epub/server/
npm install
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AWS CodeDeploy AfterInstall 脚本正在从代码部署代理目录运行 的相关文章

随机推荐