部署AWS Beanstalk后执行命令

问题描述 投票:5回答:3

我有部署后执行命令的问题,我有一些node.js项目和脚本,这个脚本使用来自node_modules的一些bin,如果我在.ebextensions / .config中编写我的脚本命令,他在npm install之前执行并返回错误("node_modules/.bin/some": No such file or directory) )。如何在部署后执行命令。谢谢。

node.js amazon-web-services deployment npm elastic-beanstalk
3个回答
11
投票

我找到了以下解决方案

我添加到beanstalk config next命令:

commands:
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/some_job.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      cd /var/app/current
      export PATH=$PATH:$(ls -td /opt/elasticbeanstalk/node-install/node-* | head -1)/bin
      npm run some_script

此命令为post-hooks脚本创建(如果不存在)文件夹并添加bash脚本。此文件夹中的脚本仅在安装npm后执行,这对我的问题非常重要。

感谢这个家伙http://junkheap.net/blog/2013/05/20/elastic-beanstalk-post-deployment-scripts/


2
投票

创建一个名为.ebextensions/post_actions.config的文件:

container_commands:
 <name of container_command>:
    command: "<command to run>"

这将在提取代码之后但在启动之前执行。


-2
投票

如果您阅读AWS ebextensions documentation,他们会提到执行,特别是他们提到在部署应用程序版本之前执行所有命令。

“您可以使用container_commands键来执行容器的命令.container_commands中的命令按名称的字母顺序处理。它们在应用程序和Web服务器设置完毕后运行,并且应用程序版本文件已被提取,但在部署了应用程序版本。“

如果你第二次部署它应该工作;这是因为您的应用程序已经解压缩。然而,这不是一个有效的解决方案,因为每个生成的新实例都会出错。

© www.soinside.com 2019 - 2024. All rights reserved.