简体   繁体   English

Rails 应用程序无法在弹性 beantalk 上部署

[英]Rails app fails to deploy on elastic beanstalk

I have a Rails 4 app using ruby 2.3 that I want to deploy using AWS Ebs.我有一个使用 ruby​​ 2.3 的 Rails 4 应用程序,我想使用 AWS Ebs 进行部署。 I'm pointing the db connection to an existing db, I'm using the cli to initialize and create.我将数据库连接指向现有数据库,我正在使用 cli 进行初始化和创建。 When I get to the create part i keep getting an error message that says:当我到达创建部分时,我不断收到一条错误消息,内容为:

Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.

Which of course means the migration failed.这当然意味着迁移失败。 When i checked the logs it says tables already exist, I did some research and found you can include settings in .ebextensions/ to specify not to run migrations or run bundle on test and dev.当我检查日志时,它说表已经存在,我做了一些研究,发现您可以在.ebextensions/包含设置以指定不在测试和开发上运行迁移或运行包。 Here is my .ebextensions/ruby-settings.config :这是我的.ebextensions/ruby-settings.config

option_settings: BUNDLE_WITHOUT: "test:development" RAILS_ENV: production RACK_ENV: production RAILS_SKIP_MIGRATIONS: true

However it still fails to deploy and gives the same error message.但是它仍然无法部署并给出相同的错误消息。 Question is, what am i doing wrong here?问题是,我在这里做错了什么? I've tried rewriting this config file different ways based on tutorials i found on this blog and the AWS docs page here .我试着重写基础上的教程我在此找到这个配置文件不同的方式博客和AWS文档页面在这里

Any thoughts on what I'm doing wrong are helpful as i am at a loss currently.关于我做错了什么的任何想法都是有帮助的,因为我目前不知所措。

Change your ruby-settings.config to below and then try the migration.将您的 ruby​​-settings.config 更改为以下,然后尝试迁移。

option_settings:
        - option_name: BUNDLE_WITHOUT
          value: "test:development"
        - option_name: RAILS_ENV
          value: "production"
        - option_name: RACK_ENV
          value: "production"
        - option_name: RAILS_SKIP_MIGRATIONS
          value: "true"

I found that the answer to my problem was that i had added .ebextensions to my .gitignore.我发现我的问题的答案是我在我的 .gitignore 中添加了 .ebextensions。 Early in the process of deployment .elasticbeanstalk had been added to ignore and I assumed the same needed to be done to .ebextensions.在部署过程的早期,.elasticbeanstalk 已被添加为忽略,我认为需要对 .ebextensions 做同样的事情。 A minor oversight that led to a lot of frustration.一个小小的疏忽导致了很多挫折。

It is worth noting that when I did have a spacing issue in my config files, the ebcli threw an error at me.值得注意的是,当我的配置文件中确实存在间距问题时,ebcli 向我抛出了一个错误。 I believe that what error2007s posted was valid, however other formats are acceptable.我相信 error2007s 发布的内容是有效的,但是其他格式是可以接受的。 For example, here is my current format for one of my config files:例如,这是我的配置文件之一的当前格式:

option_settings:
  aws:ec2:vpc:
    VPCId: vpc-xxxxxxxx
    Subnets: subnet-yyyyyyy,subnet-zzzzzzzz,subnet-wwwwwww,subnet-eeeeeeeee
  aws:autoscaling:launchconfiguration:
    SecurityGroups: sg-00000000

etc...等等...

I would also recommend using .ebextensions to set your environment variables, as I did:我还建议使用 .ebextensions 来设置您的环境变量,就像我所做的那样:

option_settings:
  aws:elasticbeanstalk:application:environment:
    RAILS_SKIP_MIGRATIONS: true
    RAILS_ENV: production

filename: 0000.config文件名:0000.config

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/02b_set_env_vars.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/bash
      EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)
      cd $EB_APP_STAGING_DIR
      ./set-env.sh

and there are some errors like -并且有一些错误,例如 -

  1. Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh failed挂钩 /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh 失败
  2. ./set-env.sh not found ./set-env.sh 未找到

go inside /opt/elasticbeanstalk/hooks/configdeploy/pre/<>_setup_envvars.sh进入/opt/elasticbeanstalk/hooks/configdeploy/pre/<>_setup_envvars.sh

Copy last two lines -复制最后两行 -

EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir) $EB_SUPPORT_DIR/export_envvars EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir) $EB_SUPPORT_DIR/export_envvars

and Paste into 0000.config - now the file look like-并粘贴到 0000.config - 现在文件看起来像 -

filename: 0000.config文件名:0000.config

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/02b_set_env_vars.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/bash
      EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
      $EB_SUPPORT_DIR/export_envvars

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM