Deploy rails to beanstalk error - ruby-on-rails

When deploying standard rails api app to beanstalk, it was failing with following log :
++ export RUBY_ROOT=/opt/rubies/ruby-2.4.3
++ RUBY_ROOT=/opt/rubies/ruby-2.4.3
++ export RUBYOPT=
++ RUBYOPT=
++ export PATH=/opt/rubies/ruby-2.4.3/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
++ PATH=/opt/rubies/ruby-2.4.3/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
+++ /opt/rubies/ruby-2.4.3/bin/ruby -
++ eval 'export RUBY_ENGINE=ruby;
export RUBY_VERSION=2.4.3;
export GEM_ROOT="/opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0";'
+++ export RUBY_ENGINE=ruby
+++ RUBY_ENGINE=ruby
+++ export RUBY_VERSION=2.4.3
+++ RUBY_VERSION=2.4.3
+++ export GEM_ROOT=/opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0
+++ GEM_ROOT=/opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0
++ (( 0 != 0 ))
+ cd /var/app/ondeck
+ su -s /bin/bash -c 'bundle exec /opt/elasticbeanstalk/support/scripts/check-for-rake-task.rb db:migrate' 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 'leader_only bundle exec rake db:migrate' webapp
`/home/webapp` is not a directory.
Bundler will use `/tmp/bundler/home/webapp' as your home directory temporarily.
rake aborted!
Bundler::GemRequireError: There was an error while trying to load the gem 'rb-readline'.
Gem Load Error is: HOME environment variable (or HOMEDRIVE and HOMEPATH) must be set and point to a directory
I am new to Beanstalk, may someone point out what is the issue?
It seems it was trying to use "/home/webapp" but the directory was not created somehow.
Thanks a lot!

I found the issue to be resolved by deleting rb-readline gem from the build. Not a best fix, but for now it works.

Related

Add local binstubs to rbenv (getting command not found)

If you have simple shell command binstubs in the local bin directory of a Rails project (e.g. not generated by or running a gem), rbenv seems to have trouble executing them. For example, #tpope's heroku binstubs generate a binstub named production in the local bin directory:
#!/bin/sh
HEROKU_APP=myapp-production HKAPP=myapp-production exec "${HEROKU_COMMAND:-heroku}" "$#"
After an rbenv rehash, the production command shows up in the ~/.rbenv/shims directory looking something like this:
#!/usr/bin/env bash
set -e
[ -n "$RBENV_DEBUG" ] && set -x
program="${0##*/}"
if [ "$program" = "ruby" ]; then
for arg; do
case "$arg" in
-e* | -- ) break ;;
*/* )
if [ -f "$arg" ]; then
export RBENV_DIR="${arg%/*}"
break
fi
;;
esac
done
fi
export RBENV_ROOT="/Users/Username/.rbenv"
exec "/usr/local/Cellar/rbenv/0.4.0/libexec/rbenv" exec "$program" "$#"
So executing which production gives you:
/Users/Username/.rbenv/shims/production
But executing rbenv which production (or trying to run the command) gives you:
rbenv: production: command not found
I'm new to rbenv so maybe I missed a config step?
Apparently project-specific binstubs in Rails projects should be kept outside of the local bin/ directory since those are primarily for application scripts. So one approach (i.e. that used by the rbenv-binstubs plugin) is to keep local binstubs separate and override rbenv shims with that local binstub directory (e.g. .bundle/bin). So by using the plugin you might see this result from which production:
/Users/Username/.rbenv/shims/production
But if you move the production binstub to .bundle/bin, then rbenv which production should yield:
{PROJECT_ROOT}/.bundle/bin/production

bundle not found when running services using upstart/foreman

I'm setting up a staging environment for a Rails 4 app on Ubuntu 12.04.
I use:
- rbenv for managing rubies
- capistrano for deployemnt
- foreman for managing services
In particular, I want to run que as a service. My Procfile looks like
que: bundle exec rake que:work
I have exported the Procfile for upstart successfully. My sapp-que-1.conf looks like
start on starting ft-id-que
stop on stopping ft-id-que
respawn
exec su - deployer -c 'cd /home/deployer/apps/sapp/releases/20140307080502; export PORT=5000; bundle exec rake que:work >> /home/deployer/apps/sapp/current/log/que-1.log 2>&1'
When I try to start it (sudo start sapp) I get the following error:
-su: bundle: command not found
However if I cd into /home/deployer/apps/sapp/releases/20140307080502 and I manually run bundle exec rake que:work the rake is executed.
Am I missing anything here?
Thanks.
Could you have .bash_profile ?
The su does not read .bashrc.
[SOLVED] Special user, .bashrc not being executed upon login
I create .bash_profile with
# Load the default .profile
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile"
# Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

RVM not loaded in Jenkins Shell Environment

I want to run bundle install on my Jenkins server in the context of a given RVM Ruby Installation.
When I sign in via SSH it all works fine:
which bundle
# /Users/me/.rvm/gems/ruby-2.1.0#global/bin/bundle
ruby -v
# ruby 2.1.0p0 ...
But when I do this via Jenkins I get this:
which bundle
# /usr/bin/bundle
So I added source ~/.bash_profile to the top of my script which should load the RVM context but for this I get the following output and the path of bundle is still wrong:
+ source /Users/me/.bash_profile
++ [[ -s /Users/me/.profile ]]
++ source /Users/me/.profile
+++ PATH=/usr/bin:/bin:/usr/sbin:/sbin:/Users/me/.rvm/bin
++ [[ -s /Users/me/.rvm/scripts/rvm ]]
++ source /Users/me/.rvm/scripts/rvm
+++ __rvm_has_opt posix
+++ [[ -n '' ]]
+++ [[ -n 3.2.51(1)-release ]]
+++ [[ :braceexpand:errexit:hashall:interactive-comments:posix:xtrace: =~ :posix: ]]
+++ return 0
+ which bundle
/usr/bin/bundle
Now how do I tell Jenkins to always load the RVM Environment. Thanks :)
When I run a shell script in Jenkins, I do something like
#!/bin/bash
echo '##################### BUNDLE/MIGRATION #####################'
source ~/.bashrc
rvm use 2.1#gemset
bundle install
bundle exec rake db:schema:load RAILS_ENV=test
bundle exec rake db:test:prepare
I my .bashrc I have the lines
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
PATH=$PATH:$HOME/.rvm/bin
I do not know if this is the state of the art, but it works :-)
Try this: rvm 2.1 do which bundle

Error while installing ruby on rails on server

After installing rvm when i run this
source $HOME/rvm/scripts/rvm
i get error
-bash: /root/rvm/scripts/rvm: No such file or directory
reference: Problem deploying Ruby+RVM and daemontools
I found the answer but looking at the rvmsudo script installed with
rvm, here is a working run script:
#!/bin/sh
# redirect stderr to stdout
exec 2>&1
cd /app
# load rvm
. /usr/local/rvm/scripts/rvm
# select ruby version for this application
rvm use 1.9.1
# # depending on your configuration you may need to provide the absolute path to rvm, like that:
# /usr/local/bin/rvm use 1.9.1
# build the exec command line preserving the rvm environment
command="exec sudo -u app_user /usr/bin/env PATH='$PATH'"
[[ -n "${GEM_HOME:-}" ]] && command="${command} GEM_HOME='$GEM_HOME' "
[[ -n "${GEM_PATH:-}" ]] && command="${command} GEM_PATH='$GEM_PATH' "
# this is where your real command line goes
command="${command} ruby main.rb"
# run the application
eval "${command}"
Try source ~/.rvm/scripts/rvm. Exit out of your current shell and then try again it should work.

How to set up Rails build on Cloudbees?

I am trying to set up a Rails job on Cloudbees and I'm running into problems that I can't solve anymore. I tried to follow the instructions but didn't find enough details to find out what's wrong myself.
This is how the Shell execution section of my job currently looks like:
curl -s -o use-ruby https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/ruby/use-ruby
RUBY_VERSION=1.9.3-p327 source ./use-ruby
bundle install --path vendor/bundle
bundle exec rake db:test:create
bundle exec rake test
I'm actually not sure yet about the last 2 lines, since I never made it past line #3 ;)
When I run this, I get the following result:
(...)
Commencing build of Revision 2e1549004e2b49903d4d006ad8bfa7e4b4bfda08 (origin/master)
Checking out Revision 2e1549004e2b49903d4d006ad8bfa7e4b4bfda08 (origin/master)
[API Continuous Testing] $ /bin/sh -xe /tmp/hudson4854632522106638677.sh
+ curl -s -o use-ruby https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/ruby/use-ruby
+ RUBY_VERSION=1.9.3-p327
+ source ./use-ruby
++ [[ -z 1.9.3-p327 ]]
++ ruby187='1.8.7-*'
++ [[ 1.9.3-p327 == 1.8.7-* ]]
++ '[' '!' -f /scratch/jenkins/use.sh ']'
++ . /scratch/jenkins/use.sh
++ mkdir -p /scratch/jenkins/ruby
+++ addon_architecture
+++ uname -m
++ ruby_name=ruby-1.9.3-p327-x86_64
++ '[' '!' -f /scratch/jenkins/ruby/ruby-1.9.3-p327-x86_64.tar.bz2 ']'
++ '[' '!' -f /scratch/jenkins/ruby/ruby-1.9.3-p327-x86_64/bin/ruby ']'
++ export PATH=/scratch/jenkins/ruby/ruby-1.9.3-p327-x86_64/bin:/opt/jdk/jdk1.6.latest/bin:/opt/jdk/latest/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/opt/maven/latest/bin:/opt/ant/latest/bin:/opt/android/android-sdk-linux/tools:/opt/gradle/latest/bin:/home/jenkins/bin:/opt/jdk/jdk.latest/bin
++ PATH=/scratch/jenkins/ruby/ruby-1.9.3-p327-x86_64/bin:/opt/jdk/jdk1.6.latest/bin:/opt/jdk/latest/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/opt/maven/latest/bin:/opt/ant/latest/bin:/opt/android/android-sdk-linux/tools:/opt/gradle/latest/bin:/home/jenkins/bin:/opt/jdk/jdk.latest/bin
++ unset GEM_PATH
++ unset GEM_HOME
++ unset BUNDLE_PATH
+ bundle install --path vendor/bundle
/tmp/hudson4854632522106638677.sh: line 5: bundle: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
I assumed that after the Cloudbees installer is finished, "bundle" would be available for me to execute. Is that not right? Or am I missing anything?
Bundler is not included by default as there are many versions (and some people prefer a newer / older / pre-release version).
In regards the following bcrypt issue, it's caused by spaces in the job name. I've renamed the job in question and it now passes.
I've also added the PostgreSQL installer so your full install now completes successfully.
You should refer to http://wiki.cloudbees.com/bin/view/DEV/PostgreSQL for more information on PostgreSQL configuration (preparing the users and databases).
I think you may need to install bundler, as if it was a "normal" ruby installation:
gem install bundler
As the first thing (as it doesn't come with ruby itself)
(although I can see why a "use-ruby" script could be expected to do that - I will see if it can).

Resources