rake db:migrate在开发AWS Beanstalk中运行

时间:2021-02-01 23:21:53

I'm new to Beanstalk. I've created a Rails application and set the database production configuration to use the environment variables hopefully provided by AWS. I'm using Mysql (mysql2 gem), and want to use RDS and Passenger (I have no preference there).

我是Beanstalk的新手。我创建了一个Rails应用程序并设置数据库生产配置以使用AWS希望提供的环境变量。我正在使用Mysql(mysql2 gem),并希望使用RDS和Passenger(我没有偏好)。

On my development environment I can run the rails application with my local Mysql (it is just a basic application I've created for experimentation). I have added the passenger gem to Gemfile and bundled, but I'm using WEBBrick in development still.

在我的开发环境中,我可以使用我的本地Mysql运行rails应用程序(它只是我为实验创建的基本应用程序)。我已将乘客宝石添加到Gemfile并捆绑,但我仍然在开发中使用WEBBrick。

The only thing I did not do by the book is that I did not use 'eb' but rather tried from the console. My application/environment failed to run as while "rake db:migrate" it still thinks I wanted it to connect to the local Mysql (I guess from the logs that it is not aware of RACK_ENV and hence uses 'development').

这本书我唯一没做过的就是我没有使用'eb',而是从控制台尝试。我的应用程序/环境无法运行,因为“rake db:migrate”它仍然认为我希望它连接到本地Mysql(我想从日志中它不知道RACK_ENV因此使用'开发')。

Any tip? I can of course try next the 'eb', yet would prefer to work with the console.

有提示吗?我当然可以尝试下一个'eb',但更愿意使用控制台。

Regards, Oren

此致,奥伦

4 个解决方案

#1


3  

Have you tried to run

你试过跑吗?

    bin/rake db:migrate RAILS_ENV=development

? I got the same issue and that worked for me.

?我得到了同样的问题,这对我有用。

#2


2  

In Elastic Beanstalk (both the web console and the cli), you can pass environnement variables. If you pass the RAKE_ENV variable, you will change your environnement.

在Elastic Beanstalk(Web控制台和cli)中,您可以传递环境变量。如果您传递RAKE_ENV变量,您将更改您的环境。

After that you still need to pass your database parameters (db password, name, ...) which should not be hardcoded into the code.

之后,您仍然需要传递数据库参数(db password,name,...),这些参数不应该硬编码到代码中。

#3


1  

I recommend you enter to EC2 instance through this command "eb ssh" (The first time you need specified you .pem file, if you have not one you can create in IAM services) and check your logs for more information about yours error.

我建议您通过此命令“eb ssh”进入EC2实例(第一次需要指定.pem文件,如果没有可以在IAM服务中创建的文件)并检查日志以获取有关您的错误的更多信息。

If you have problems when you are uploading your code (eb deploy) you have the log in this file: "/var/log/eb-activity.log" (Remember this file is in your EC2 instance)

如果您在上传代码时遇到问题(eb deploy),则在此文件中记录日志:“/ var / log / eb-activity.log”(请记住此文件位于EC2实例中)

If you have a problems with your app, you can read the logs in this files: "/var/app/support/logs/production.log" or "/var/app/support/logs/passenger.log"

如果您的应用程序出现问题,可以阅读此文件中的日志:“/ var / app / support / logs / production.log”或“/var/app/support/logs/passenger.log”

Other recommedations is install EB CLI version 3. for manage your eb instance

其他建议是安装EB CLI版本3.用于管理您的eb实例

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html

#4


0  

I believed that Elastic Beanstalk will run 'rake db:migrate' by itself. Indeed it seems to try, but that is failing. I gave my bounty to 'Yahs Hef', even though I will only try this evening (UK). My disorientation with AWS caused me to forget this easy solution, of running the migration by myself. If this does not work by itself, I'll simplify the database configuration as possibile.

我相信Elastic Beanstalk会自行运行'rake db:migrate'。确实似乎尝试过,但那是失败的。我把我的赏金给了'Yahs Hef',尽管我今晚只会尝试(英国)。我对AWS的迷惑导致我忘记了这个简单的解决方案,即自己运行迁移。如果这本身不起作用,我将尽可能地简化数据库配置。

#1


3  

Have you tried to run

你试过跑吗?

    bin/rake db:migrate RAILS_ENV=development

? I got the same issue and that worked for me.

?我得到了同样的问题,这对我有用。

#2


2  

In Elastic Beanstalk (both the web console and the cli), you can pass environnement variables. If you pass the RAKE_ENV variable, you will change your environnement.

在Elastic Beanstalk(Web控制台和cli)中,您可以传递环境变量。如果您传递RAKE_ENV变量,您将更改您的环境。

After that you still need to pass your database parameters (db password, name, ...) which should not be hardcoded into the code.

之后,您仍然需要传递数据库参数(db password,name,...),这些参数不应该硬编码到代码中。

#3


1  

I recommend you enter to EC2 instance through this command "eb ssh" (The first time you need specified you .pem file, if you have not one you can create in IAM services) and check your logs for more information about yours error.

我建议您通过此命令“eb ssh”进入EC2实例(第一次需要指定.pem文件,如果没有可以在IAM服务中创建的文件)并检查日志以获取有关您的错误的更多信息。

If you have problems when you are uploading your code (eb deploy) you have the log in this file: "/var/log/eb-activity.log" (Remember this file is in your EC2 instance)

如果您在上传代码时遇到问题(eb deploy),则在此文件中记录日志:“/ var / log / eb-activity.log”(请记住此文件位于EC2实例中)

If you have a problems with your app, you can read the logs in this files: "/var/app/support/logs/production.log" or "/var/app/support/logs/passenger.log"

如果您的应用程序出现问题,可以阅读此文件中的日志:“/ var / app / support / logs / production.log”或“/var/app/support/logs/passenger.log”

Other recommedations is install EB CLI version 3. for manage your eb instance

其他建议是安装EB CLI版本3.用于管理您的eb实例

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html

#4


0  

I believed that Elastic Beanstalk will run 'rake db:migrate' by itself. Indeed it seems to try, but that is failing. I gave my bounty to 'Yahs Hef', even though I will only try this evening (UK). My disorientation with AWS caused me to forget this easy solution, of running the migration by myself. If this does not work by itself, I'll simplify the database configuration as possibile.

我相信Elastic Beanstalk会自行运行'rake db:migrate'。确实似乎尝试过,但那是失败的。我把我的赏金给了'Yahs Hef',尽管我今晚只会尝试(英国)。我对AWS的迷惑导致我忘记了这个简单的解决方案,即自己运行迁移。如果这本身不起作用,我将尽可能地简化数据库配置。