如何使用环境变量在 Elastic Beanstalk EB 上运行 sequelize db:migrate?如何在容器命令中访问 .env 变量? [英] How to run sequelize db:migrate on Elastic Beanstalk EB with env vars? How to access .env vars in container commands?
本文介绍了如何使用环境变量在 Elastic Beanstalk EB 上运行 sequelize db:migrate?如何在容器命令中访问 .env 变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
How can I run sequelize db:migrate on ElasticBeanstalk with env vars?
Running sequelize migrate fails since it cannot find the .env
file.
{ Error: ENOENT: no such file or directory, open '.env'
my master.config looks like:
container_commands:
00_node_binary:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node"
00_npm_binary:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/npm /bin/npm"
01_migrations:
command: npm run migrate
leader_only: true
and my package.json contains
"migrate": "node_modules/sequelize-cli/bin/sequelize db:migrate"
解决方案
Don't forget to include the first two commands, the file migration.config that worked for me in .ebextensions looks like this
container_commands:
00_node_binary:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node"
00_npm_binary:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/npm /bin/npm"
50-run-database-migrations:
command: "./node_modules/.bin/sequelize db:migrate"
leader_only: true
It looks like the ./node_modules/.bin/sequelize uses /usr/bin/env/node and will give you the following error:
/usr/bin/env: node: No such file or directory
Because apparently node is called nodejs... the first two container commands will take care of that.
See https://github.com/nodejs/node-v0.x-archive/issues/3911 for further reference
这篇关于如何使用环境变量在 Elastic Beanstalk EB 上运行 sequelize db:migrate?如何在容器命令中访问 .env 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文