16

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

runas を追加したり、ロケーション パスの先頭に「/」を追加したりするなど、さまざまな appspec.yml 構成を試していました。常に /opt/codeeoploy-agent/ ディレクトリから実行しようとしています。

必死になって、スクリプトへの絶対パスを設定しましたが、次のようになりました。

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

ドキュメントに従ってすべてを行っているので、本当に面倒ですが、おそらく非常に小さなものが欠けています!

ありがとう

4

1 に答える 1

28

Ok、

そのため、codedeoloy-agent がデプロイ インスタンスのエージェントによって作成された一時ディレクトリから AfterInstall (およびおそらく他のすべての手順) を実行していることがわかりました。適切なディレクトリ:

#!/bin/bash
cd /tmp/epub/server/
npm install
于 2015-10-23T22:04:13.957 に答える