亚马逊网络服务> CodeDeploy> BitBucket>我的nodejs Appspec.yml坏了

时间:2016-10-03 18:44:11

标签: node.js amazon-web-services aws-code-deploy

我正在尝试使用非常简单的nodejs应用程序来完成我的设置(BitBucket到AWS),我可以使用默认示例:

https://github.com/awslabs/aws-codedeploy-samples/tree/master/applications/SampleApp_Linux

但是这个例子是在apache,httpd中,所以当我尝试更改nodejs的appspec.yml时,设置会刹车。这是我的appspec.yml:

version: 0.0
os: linux
files:
  - source: /
    destination: /var/www/app
hooks:
  BeforeInstall:
    - location: scripts/install_dependencies
      timeout: 300
      runas: root
    - location: scripts/start_server
      timeout: 300
      runas: root

install_dependencies:

#!/bin/bash
yum install -y nodejs npm
npm install

START_SERVER:

#!/bin/bash
node server.js

2 个答案:

答案 0 :(得分:2)

我从ec2事件日志和其他地方想出来了。这就是我所拥有的:

appspec.yml

version: 0.0
os: linux
files:
  - source: /
    destination: /tmp/
hooks:
  AfterInstall:
    - location: scripts/install_dependencies
      timeout: 100
      runas: root
  ApplicationStart:
    - location: scripts/start_server
      timeout: 100
      runas: root

install_dependencies:

#!/bin/bash
cd /tmp/

curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum install -y gcc-c++ make
yum install -y nodejs npm

npm install -g pm2
npm install

对于start_server,停止并删除httpd。然后从pm2开始。那么“node server.js”的问题在于它永远无法解析。

START_SERVER:

#!/bin/bash
cd /tmp/

isExistApp = `pgrep httpd`
if [[ -n  $isExistApp ]]; then
    service httpd stop
fi

yum remove -y httpd

pm2 delete all
pm2 start server.js

答案 1 :(得分:0)

对于基于ubuntu / debian的发行版,herehere我发现了几个要点,它们确实帮助我实现了这一目标。

appspec.yml:

version: 0.0
os: linux
files:
  - source: /
    destination: /tmp/
hooks:
  AfterInstall:
    - location: scripts/install_dependencies
      timeout: 100
      runas: root
  ApplicationStart:
    - location: scripts/start_server
      timeout: 100
      runas: root
  ValidateService:
    - location: scripts/test
      timeout: 100
      runas: root

install_dependencies:

#!/bin/bash
cd /tmp/

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential

npm install -g pm2
npm install

启动服务器:

#!/bin/bash
cd /tmp/
# set any env variables
export NODE_ENV=staging

pm2 delete all
pm2 start dist/server/index.js --name MyAPI

测试:

#!/bin/bash
sleep 10
nc -zv 127.0.0.1 80