Elastic Beanstalk运行部署后脚本 [英] Elastic Beanstalk run post deploy script
问题描述
我的node.js应用程序由两部分组成,一个是后端,一个是前端.
My node.js app consists of two things, an express backend and a react frontend.
我在此结构中有两个package.json文件
I have two package.json files in this structure
package.json
/app/package.json
我想做的是在前端文件夹app中运行一个脚本,以构建我的代码.
What I want to do is run a script in my frontend folder, app, that builds my code.
我要运行的脚本是npm install
和npm run build
部署完成后如何运行此脚本?
the script I want to run is npm install
and npm run build
How do I run this script after a deploy have happened?
commands:
01_app_npm_install:
command: npm install
cwd: app/
02_app_npm_build:
command: npm run build
cwd: app/
但是它返回一个错误,指出没有这样的文件或目录 tory:"app/"."
But it returns an error saying that "No such file or direc tory: 'app/'."
这可以对aws弹性beantalk进行吗?
Is this possible to do on aws elastic beanstalk?
推荐答案
由于@gustaf和其他一些站点,我设法将解决方案组合在一起.它不漂亮,但是可以用.
Thanks to @gustaf and some other sites I managed to pull a solution together. It's not pretty but it works.
我在.ebextensions/01_build.config
commands:
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_build_app.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
cd /var/app/current/app/
sudo /opt/elasticbeanstalk/node-install/node-v6.2.2-linux-x64/bin/npm install
sudo /opt/elasticbeanstalk/node-install/node-v6.2.2-linux-x64/bin/npm run build
对节点版本进行硬编码不是完美的方法,但目前可以使用.
hard coding the node-version is not perfect but it works for now.
这篇关于Elastic Beanstalk运行部署后脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!