2015-10-23 47 views
10

我試圖在AWS代碼部署中運行AfterInstall腳本,但它正在從/ opt/codedeploy-agent/dir而不是我的應用程序目錄運行。AWS CodeDeploy AfterInstall腳本正在從代碼部署代理程序運行目錄

這是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安裝,僅此而已。

不幸的是,我發現了錯誤:

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 CONFIGS。它一直試圖從/ opt/codedeoploy-agent /目錄運行。

無奈之下,我設置絕對路徑的腳本,但是後來我:

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

這真是煩人,因爲我按照文檔做的一切,但也許我失去了一些東西很很小 !

感謝

回答

20

好吧,

所以,我已經發現了,那codedeoloy劑是由上部署實例代理創建的臨時目錄運行AfterInstall(也許所有的其他步驟),因此在我的情況下,我不得不通過cd到正確的目錄修改bash腳本:

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

你從哪裏找到了這個? – artburkart

+2

我不記得是否我從這裏得出結論:http://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html#app-spec-ref-hooks - 也許有一句話暗示 - 我記得它花了我很長一段時間 - 或更可能通過試驗和錯誤,或兩者結合:) – matewilk

+0

@matewilk - 超級有用! – Ben