正在从代码部署代理dir运行AWS CodeDeploy AfterInstall脚本 [英] AWS CodeDeploy AfterInstall script is being run from code-deploy agent dir

查看:97
本文介绍了正在从代码部署代理dir运行AWS CodeDeploy AfterInstall脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to run AfterInstall script in AWS code deploy, but it is being run from the /opt/codedeploy-agent/ dir instead of my app directory.

appspec.yml文件的外观如下:

This is how appspec.yml file looks like:

version: 0.0

os: linux

files:
  - source: /
    destination: /tmp/epub

hooks:
  AfterInstall:
    - location: server/install-packages.sh
      runas: root

如您所见,这是一个基本示例.

As you can see it's a basic example.

现在,bash脚本如下所示:

Now, the bash script looks like this:

#!/bin/bash
npm install

我只想npm安装即可.

I just want to npm install and that's it.

不幸的是我遇到了错误:

Unfortunately I'm getting the error:

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/目录运行.

I was trying different appspec.yml configs like adding runas or adding "/" at the beginning of the location path. All the time it's trying to run from /opt/codedeoploy-agent/ directory.

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

In desperation, I've set absolute path to the script, but then I got :

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

当我根据文档进行所有操作时,这确实很烦人,但可能我错过了一些非常小的东西!

It's really annoying as I'm doing everything according to docs, but probably I'm missing something very very small !

谢谢

推荐答案

好,

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

So I've found out, that codedeoloy-agent is running AfterInstall (and probably all the other steps) from the temporary directory created by the agent on deploy instance, so in my case I had to modify the bash script by cd-ing to the proper directory:

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

这篇关于正在从代码部署代理dir运行AWS CodeDeploy AfterInstall脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆