3

I'm trying to deploy a Rails 5 app to Elastic Beanstalk but I am getting the following error in my log file that appears to indicate that my home directory is not properly set.

I tried setting the HOME environment variable by setting HOME to ~/my-app-name but I have had no luck and it doesn't appear to be using the variable anyway. I set the variable under the software section in the environment configurations.

/var/log/eb-activity.log:

+ cd /var/app/ondeck
+ su -s /bin/bash -c 'bundle exec 
/opt/elasticbeanstalk/support/scripts/check-for-rake-task.rb assets:precompile' webapp
`/home/webapp` is not a directory.
Bundler will use `/tmp/bundler/home/webapp' as your home directory temporarily.
+ '[' false == true ']'
+ su -s /bin/bash -c 'bundle exec rake assets:precompile' webapp
`/home/webapp` is not a directory.
Bundler will use `/tmp/bundler/home/webapp' as your home directory temporarily.
rake aborted!
Psych::SyntaxError: (<unknown>): did not find expected alphabetic or numeric 
character while scanning an alias at line 83 column 22
/var/app/ondeck/config/environments/production.rb:96:in `block in <top (required)>'
/var/app/ondeck/config/environments/production.rb:1:in `<top (required)>'
/var/app/ondeck/config/environment.rb:5:in `<top (required)>'
/opt/rubies/ruby-2.5.3/bin/bundle:23:in `load'
/opt/rubies/ruby-2.5.3/bin/bundle:23:in `<main>'
Tasks: TOP => environment
(See full trace by running task with --trace) (Executor::NonZeroExitStatus)

I found a a similar issue here: issue deploying rails 5 application to AWS using Elastic Beanstalk due to rb-readline

I also asked another question yesterday about the psych error (posted link below) but I am beginning to think that this error may be caused due to the invalid reference to HOME. I'm rather lost at this point and have been working on this for several hours with absolutely no luck.

Another question I posted yesterday about the psych error: Error Deploying on Elastic Beanstalk - Rails

Cannon Moyer
  • 3,014
  • 3
  • 31
  • 75
  • 1
    You wrote "another question" and "other question", but I don't see any question here. What is your question? – sawa Dec 27 '18 at 17:18
  • @sawa https://stackoverflow.com/questions/53937817/error-deploying-on-elastic-beanstalk-rails/53943338#53943338 – Cannon Moyer Dec 27 '18 at 17:20
  • I think this issue is related to the psych error. I do not modify the home directory for my Rails deploys with elastic beanstalk and I receive the same warning in the eb-activity log file but it has never caused any problems. – littleforest Dec 29 '18 at 17:16

1 Answers1

3

Ruby: 2.7.0 Rails: 6.0.2.1 Solidus: v2.10.0

Just add the "commands" section below to your .ebextensions/packages.config

Add required commands:

# Setup linux packages
option_settings:
  - option_name: BUNDLE_DISABLE_SHARED_GEMS
    value: "1"
  - option_name: BUNDLE_PATH
    value: "vendor/bundle"

packages:
  yum:
    git: []
    ImageMagick: []
    ImageMagick-devel: []
    openssl-devel: []
    postgresql93-devel: []

commands:
  01_node_get:
    # run this command from /tmp directory
    cwd: /tmp
    # flag -y for no-interaction installation
    command: 'curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -'

  02_node_install:
    # run this command from /tmp directory
    cwd: /tmp
    command: 'sudo yum -y install nodejs'

  03_yarn_get:
    # run this command from /tmp directory
    cwd: /tmp
    # don't run the command if yarn is already installed (file /usr/bin/yarn exists)
    test: '[ ! -f /usr/bin/yarn ] && echo "yarn not installed"'
    command: 'sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo'

  04_yarn_install:
    # run this command from /tmp directory
    cwd: /tmp
    test: '[ ! -f /usr/bin/yarn ] && echo "yarn not installed"'
    command: 'sudo yum -y install yarn'

  05_home_dir:
    test: '[ ! -p /home/webapp ] && echo "webapp not exited"'
    command: 'sudo mkdir -p /home/webapp'

  06_grant_home_dir:
    test: '[ ! -p /home/webapp ] && echo "webapp not exited"'
    command: 'sudo chmod 777 /home/webapp'

source: https://medium.com/@tranduchanh.ms/deploy-and-manage-production-rails-5-app-with-aws-elastic-beanstalk-3efb0dfe021a

Gil Perez
  • 853
  • 10
  • 13