Reputation: 921
I've been spending the day trying to figure out how to deploy this Rails app to Elastik Beanstalk. After much research, I've finally gotten closer to deployment but keep getting this error log and not sure what to make of it or how to solve it:
eb error log:
i-0ad55a5cbcbb7752c Severe 1 hour 4 -- -- -- -- -- -- -- -- -- -- 1.00 1.02 89.1 10.9 0.0 0.0
Application update failed at 2019-10-28T20:11:32Z with exit status 1 and error: Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh failed.
++ /opt/elasticbeanstalk/bin/get-config container -k script_dir
+ EB_SCRIPT_DIR=/opt/elasticbeanstalk/support/scripts
++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir
+ EB_APP_STAGING_DIR=/var/app/ondeck
++ /opt/elasticbeanstalk/bin/get-config container -k app_user
+ EB_APP_USER=webapp
++ /opt/elasticbeanstalk/bin/get-config container -k support_dir
+ EB_SUPPORT_DIR=/opt/elasticbeanstalk/support
+ . /opt/elasticbeanstalk/support/envvars-wrapper.sh
+++ /opt/elasticbeanstalk/bin/get-config container -k support_dir
++ EB_SUPPORT_DIR=/opt/elasticbeanstalk/support
++ set +x
+ . /opt/elasticbeanstalk/support/scripts/use-app-ruby.sh
++ . /usr/local/share/chruby/chruby.sh
+++ CHRUBY_VERSION=0.3.9
+++ RUBIES=()
+++ for dir in '"$PREFIX/opt/rubies"' '"$HOME/.rubies"'
+++ [[ -d /opt/rubies ]]
++++ ls -A /opt/rubies
+++ [[ -n ruby-1.9.3-p551
ruby-2.0.0-p648
ruby-2.1.10
ruby-2.2.10
ruby-2.3.8
ruby-2.4.9
ruby-2.5.7
ruby-2.6.5
ruby-current ]]
+++ RUBIES+=("$dir"/*)
+++ for dir in '"$PREFIX/opt/rubies"' '"$HOME/.rubies"'
+++ [[ -d /.rubies ]]
+++ unset dir
+++ cat /etc/elasticbeanstalk/.ruby_version
++ chruby 2.6.5
++ case "$1" in
++ local dir match
++ for dir in '"${RUBIES[@]}"'
++ dir=/opt/rubies/ruby-1.9.3-p551
++ case "${dir##*/}" in
++ for dir in '"${RUBIES[@]}"'
++ dir=/opt/rubies/ruby-2.0.0-p648
++ case "${dir##*/}" in
++ for dir in '"${RUBIES[@]}"'
++ dir=/opt/rubies/ruby-2.1.10
++ case "${dir##*/}" in
++ for dir in '"${RUBIES[@]}"'
++ dir=/opt/rubies/ruby-2.2.10
++ case "${dir##*/}" in
++ for dir in '"${RUBIES[@]}"'
++ dir=/opt/rubies/ruby-2.3.8
++ case "${dir##*/}" in
++ for dir in '"${RUBIES[@]}"'
++ dir=/opt/rubies/ruby-2.4.9
++ case "${dir##*/}" in
++ for dir in '"${RUBIES[@]}"'
++ dir=/opt/rubies/ruby-2.5.7
++ case "${dir##*/}" in
++ for dir in '"${RUBIES[@]}"'
++ dir=/opt/rubies/ruby-2.6.5
++ case "${dir##*/}" in
++ match=/opt/rubies/ruby-2.6.5
++ for dir in '"${RUBIES[@]}"'
++ dir=/opt/rubies/ruby-current
++ case "${dir##*/}" in
++ [[ -z /opt/rubies/ruby-2.6.5 ]]
++ shift
++ chruby_use /opt/rubies/ruby-2.6.5 ''
++ [[ ! -x /opt/rubies/ruby-2.6.5/bin/ruby ]]
++ [[ -n '' ]]
++ export RUBY_ROOT=/opt/rubies/ruby-2.6.5
++ RUBY_ROOT=/opt/rubies/ruby-2.6.5
++ export RUBYOPT=
++ RUBYOPT=
++ export PATH=/opt/rubies/ruby-2.6.5/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
++ PATH=/opt/rubies/ruby-2.6.5/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
+++ /opt/rubies/ruby-2.6.5/bin/ruby -
++ eval 'export RUBY_ENGINE=ruby;
export RUBY_VERSION=2.6.5;
export GEM_ROOT="/opt/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0";'
+++ export RUBY_ENGINE=ruby
+++ RUBY_ENGINE=ruby
+++ export RUBY_VERSION=2.6.5
+++ RUBY_VERSION=2.6.5
+++ export GEM_ROOT=/opt/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0
+++ GEM_ROOT=/opt/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0
++ (( 0 != 0 ))
+ cd /var/app/ondeck
+ '[' -f Gemfile ']'
+ echo 'running '\''bundle install'\'' with Gemfile:'
running 'bundle install' with Gemfile:
+ cat Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.3'
gem 'sqlite3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.0'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.4.4'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
# Bootstrap
gem 'bootstrap', '~> 4.1.1'
# Use SCSS for stylesheets
# gem 'bootstrap-sass', '~> 3.4.1'
# gem 'sass-rails', '~> 5'
# gem 'jquery-rails'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
# gem 'turbolinks', '~> 5'
# gem 'jquery-turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# gems for creating PDF docments from screen
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary-edge'
gem 'pry', '~> 0.12.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :local, :test do
gem 'rspec-rails', '~> 3.8'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'factory_bot_rails'
gem 'shoulda-matchers'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
+ '[' -d /var/app/ondeck/vendor/cache ']'
+ bundle install --local
/opt/rubies/ruby-2.6.5/lib/ruby/site_ruby/2.6.0/rubygems.rb:284:in `find_spec_for_exe': Could not find 'bundler' (2.0.2) required by your /var/app/ondeck/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.0.2`
from /opt/rubies/ruby-2.6.5/lib/ruby/site_ruby/2.6.0/rubygems.rb:303:in `activate_bin_path'
from /opt/rubies/ruby-2.6.5/bin/bundle:23:in `<main>'.
Incorrect application version "app-cbe4-191028_161033" (deployment 4). Expected version "app-cbe4-191028_141438" (deployment 2).
100 % of CPU is in use.
My local eb yml file looks like this:
branch-defaults:
develop_b5:
environment: Tmlportal-env
global:
application_name: tmlPortal
branch: null
default_ec2_keyname: null
default_platform: Ruby 2.6 (Puma)
default_region: us-east-1
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: eb-cli
repository: null
sc: git
workspace_type: Application
and my eb status:
nvironment details for: Tmlportal-env
Application name: tmlPortal
Region: us-east-1
Deployed Version: app-cbe4-191028_141438
Environment ID: e-vke6pngump
Platform: arn:aws:elasticbeanstalk:us-east-1::platform/Puma with Ruby 2.6 running on 64bit Amazon Linux/2.11.0
Tier: WebServer-Standard-1.0
CNAME: tmlportal.us-east-1.elasticbeanstalk.com
Updated: 2019-10-28 20:11:37.751000+00:00
Status: Ready
Health: Red
Also, my config/database.yml:
# MySQL. Versions 5.5.8 and up are supported.
#
# Install the MySQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
default: &default
adapter: mysql2
encoding: utf8
database: requests
username: <%= Rails.application.credentials[:aws_username] %>
password: <%= Rails.application.credentials[:aws_password] %>
host: <%= Rails.application.credentials[:aws_host] %>
cast: false
port: 3306
development:
aws:
<<: *default
local:
adapter: mysql2
encoding: utf8mb4
database: tml_local
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: <%= Rails.application.credentials[:local_username] %>
password: <%= Rails.application.credentials[:local_password] %>
socket: /tmp/mysql.sock
production:
aws:
<<: *default
local:
adapter: mysql2
encoding: utf8
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
test:
aws:
<<: *default
local:
adapter: mysql2
encoding: utf8mb4
database: tml_local
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: <%= Rails.application.credentials[:local_username] %>
password: <%= Rails.application.credentials[:local_password] %>
socket: /tmp/mysql.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
# test:
# <<: *default
and Puma file:
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }
# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
environment ENV.fetch("RAILS_ENV") { "local" }
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
bind "unix:///var/run/puma/my_app.sock"
pidfile "/var/run/puma/my_app.sock"
plugin :tmp_restart
Upvotes: 1
Views: 1047
Reputation: 1429
You are on "Big Snag #1" on the road to deploying Rails to EB.
The key info in the EB error log is towards the bottom:
/opt/rubies/ruby-2.6.5/lib/ruby/site_ruby/2.6.0/rubygems.rb:284:in `find_spec_for_exe': Could not find 'bundler' (2.0.2) required by your /var/app/ondeck/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.0.2`
Translation: EB comes bundled with an older version of Bundler and your app specifies a newer version causing things fail.
You want to install an ebextension in your project that ensures bundler is up-to-date before your app bundles its gems. The top answer here is what you are looking for, replacing with your specific version of bundler of-course:
After this you will likely need to tweak your Puma config adding in:
bind "unix:///var/run/puma/my_app.sock"
Then you might also have issues reaching RDS if the Security Groups are not setup.
You also need to be careful that your changes actually get deployed. Some errors cause EB to rollback. If a fix seems like it does not work you may need to rebuild the EB Environment (5-15 min) to ensure it cannot rollback... and I occasionally had to deploy twice in a row to get past some of these errors.
I am personally on "Big Snag #7" which is ActiveStorage and S3 getting along.
Upvotes: 2