如何解决 AWS Elastic Beanstalk 部署的 Rails 5.2 应用程序捆绑程序问题

How to fix Rails 5.2 application bundler issue for AWS Elastic Beanstalk deployment

我正在尝试将 Rails 5.2 应用程序部署到 AWS Elastic Beanstalk,但出现此错误。

Creating application version archive "app-c6b5-190405_225348". Uploading example-rails52/app-c6b5-190405_225348.zip to S3. This may take a while. Upload Complete. Environment details for: example-eb-rails52-env Application name: example-rails52 Region: us-east-2 Deployed Version: app-c6b5-190405_225348 Environment ID: e-ehbkcfzrrt Platform: arn:aws:elasticbeanstalk:us-east-2::platform/Puma with Ruby 2.5 running on 64bit Amazon Linux/2.9.2 Tier: WebServer-Standard-1.0 CNAME: UNKNOWN Updated: 2019-04-05 16:53:59.311000+00:00 Printing Status: INFO: createEnvironment is starting. INFO: Using elasticbeanstalk-us-east-2-525254074082 as Amazon S3 storage bucket for environment data. INFO: Created security group named: sg-073de6677d8e02d77 INFO: Created load balancer named: awseb-e-e-AWSEBLoa-985TNPDWPYRI INFO: Created security group named: awseb-e-ehbkcfzrrt-stack-AWSEBSecurityGroup-1XWZBQC4TD76I INFO: Created Auto Scaling launch configuration named: awseb-e-ehbkcfzrrt-stack-AWSEBAutoScalingLaunchConfiguration-SAZWMJ3L0UV7 INFO: Created Auto Scaling group named: awseb-e-ehbkcfzrrt-stack-AWSEBAutoScalingGroup-1E8GGM4K5S26 INFO: Waiting for EC2 instances to launch. This may take a few minutes. INFO: Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-2:525254074082:scalingPolicy:bb866da3-dac2-47f0-81a2-ebc1c582d68a:autoScalingGroupName/awseb-e-ehbkcfzrrt-stack-AWSEBAutoScalingGroup-1E8GGM4K5S26:policyName/awseb-e-ehbkcfzrrt-stack-AWSEBAutoScalingScaleUpPolicy-ON6YTENHUIOE INFO: Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-2:525254074082:scalingPolicy:f13cedac-d71f-4b89-a0fd-dd2db97bb43a:autoScalingGroupName/awseb-e-ehbkcfzrrt-stack-AWSEBAutoScalingGroup-1E8GGM4K5S26:policyName/awseb-e-ehbkcfzrrt-stack-AWSEBAutoScalingScaleDownPolicy-3MK7B2H0O52F INFO: Created CloudWatch alarm named: awseb-e-ehbkcfzrrt-stack-AWSEBCloudwatchAlarmHigh-1R89A12TU33EK INFO: Created CloudWatch alarm named: awseb-e-ehbkcfzrrt-stack-AWSEBCloudwatchAlarmLow-1KHMKXF2A73T1 ERROR: [Instance: i-050185633c1ecb322] Command failed on instance. Return code: 1 Output: (TRUNCATED)...:infind_spec_for_exe': 找不到带有可执行包 (Gem::[=27) 的 gem 捆绑器 (>= 0.a) =]NotFoundException) 来自 /opt/rubies/ruby-2.5.5/lib/ruby/site_ruby/2.5.0/rubygems.rb:308:in activate_bin_path' from /opt/rubies/ruby-2.5.5/bin/bundle:23:in'。 挂钩 /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh 失败。有关更多详细信息,请使用控制台或 EB CLI 检查 /var/log/eb-activity.log。 信息:命令执行已在所有实例上完成。摘要:[成功:0,失败:1]。`

有人能给我解决方案吗?

在Rails 5.2 中,您必须安装 bundler 2.0.1 版本。要解决此问题,您可以按照以下步骤操作 -

第一步。您已添加 eb 扩展以将 bundler 2.0.1 版本安装到 AWS Elastic beanstalk -

# Go to your project root directory
$ mkdir .ebextensions
$ vim .ebextensions/bundler_install.config 

  files:
    # Runs before `./10_bundle_install.sh`:
    "/opt/elasticbeanstalk/hooks/appdeploy/pre/09_gem_install_bundler.sh" :
      mode: "000775"
      owner: root
      group: root
      content: |
        #! /bin/bash

        EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)
        EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
        # Source the application's ruby, i.e. 2.6. Otherwise it will be 2.3, which will give this error: `bundler requires Ruby version >= 2.3.0`
        . $EB_SCRIPT_DIR/use-app-ruby.sh

        cd $EB_APP_STAGING_DIR
        echo "Installing compatible bundler"
        gem install bundler -v 2.0.1

步骤#2。转到 AWS Elastic beanstalk All applications -> example-rails52 -> example-eb-rails52-env 然后点击 Configuration -> Software -> Modify 然后添加这个 env variable

 BUNDLER_VERSION=2.0.1

然后点击保存

步骤#3。再次部署应用程序

$ eb deploy

希望它能奏效。