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

Rails app fails to deploy on elastic beanstalk

我有一个使用 ruby 2.3 的 Rails 4 应用程序,我想使用 AWS Ebs 进行部署。我将数据库连接指向现有数据库,我正在使用 cli 进行初始化和创建。当我到达创建部分时,我不断收到一条错误消息:

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.

当然是迁移失败了。当我检查日志时它说表已经存在,我做了一些研究,发现你可以在 .ebextensions/ 中包含设置以指定不 运行 迁移或 运行 捆绑测试和开发。这是我的 .ebextensions/ruby-settings.config:

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

但是它仍然无法部署并给出相同的错误消息。问题是,我在这里做错了什么?我已经尝试根据我在 blog and the AWS docs page here.

上找到的教程以不同的方式重写这个配置文件

任何关于我做错了什么的想法都是有帮助的,因为我目前不知所措。

将您的 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"

我发现我的问题的答案是我已将 .ebextensions 添加到我的 .gitignore。在部署过程的早期,.elasticbeanstalk 已被添加到忽略中,我认为需要对 .ebextensions 执行相同的操作。一个小小的疏忽导致了很多挫折。

值得注意的是,当我的配置文件中确实存在间距问题时,ebcli 向我抛出一个错误。我相信 error2007s 发布的内容是有效的,但是其他格式也是可以接受的。例如,这是我的一个配置文件的当前格式:

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

等...

我还建议像我一样使用 .ebextensions 设置环境变量:

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

文件名: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

并且有一些错误,例如 -

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

进去 /opt/elasticbeanstalk/hooks/configdeploy/pre/<>_setup_envvars.sh

复制最后两行-

EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config容器-ksupport_dir) $EB_SUPPORT_DIR/export_envvars

并粘贴到 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