我正在尝试在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/codedeploy-agent/目录中运行。
绝望之下,我将脚本设置为绝对路径,但是接下来我得到了:
Script does not exist at specified location: /tmp/epub/server/install-packages.sh
我正在按照文档进行操作,但可能我错过了非常微小的东西,这真的很烦人!
谢谢。
cd "$( dirname "${BASH_SOURCE[0]}" )"
。紧随其后的是source config.sh
,用于...嗯...配置。 - musicin3d