I am getting following error when trying to deploy a rails 4.2.1 app on ec2 using elastic beanstalk
on't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching source index from https://rubygems.org/
Fetching git#github.com:bokmann/font-awesome-rails.git
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Retrying git clone 'git#github.com:bokmann/font-awesome-rails.git' "/var/app/ondeck/vendor/bundle/ruby/2.0/cache/bundler/git/font-awesome-rails-aa9211906101215f2656ef38ba0c26146ba4c6bc" --bare --no-hardlinks --quiet due to error (2/3): Bundler::Source::Git::GitCommandError Git error: command `git clone 'git#github.com:bokmann/font-awesome-rails.git' "/var/app/ondeck/vendor/bundle/ruby/2.0/cache/bundler/git/font-awesome-rails-aa9211906101215f2656ef38ba0c26146ba4c6bc" --bare --no-hardlinks --quiet` in directory /var/app/ondeck has failed.
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Git error: command `git clone 'git#github.com:bokmann/font-awesome-rails.git'
"/var/app/ondeck/vendor/bundle/ruby/2.0/cache/bundler/git/font-awesome-rails-aa9211906101215f2656ef38ba0c26146ba4c6bc"
--bare --no-hardlinks --quiet` in directory /var/app/ondeck has failed.
2014-07-13 15:16:48,672 [ERROR] (4743 MainThread) [directoryHooksExecutor.py-33] [root directoryHooksExecutor error] Script /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh failed with returncode 11
and .ebextensions/ruby.config looks like this
# Install git in order to be able to bundle gems from git
packages:
yum:
git: []
patch: []
commands:
# Run rake with bundle exec to be sure you get the right version
add_bundle_exec:
test: test ! -f /opt/elasticbeanstalk/support/.post-provisioning-complete
cwd: /opt/elasticbeanstalk/hooks/appdeploy/pre
command: perl -pi -e 's/(rake)/bundle exec $1/' 11_asset_compilation.sh 12_db_migration.sh
# Bundle with --deployment as recommended by bundler docs
# cf. http://gembundler.com/v1.2/rationale.html under Deploying Your Application
add_deployment_flag:
test: test ! -f /opt/elasticbeanstalk/support/.post-provisioning-complete
cwd: /opt/elasticbeanstalk/hooks/appdeploy/pre
command: perl -pi -e 's/(bundle install)/$1 --deployment/' 10_bundle_install.sh
# Vendor gems to a persistent directory for speedy subsequent bundling
make_vendor_bundle_dir:
test: test ! -f /opt/elasticbeanstalk/support/.post-provisioning-complete
command: mkdir /var/app/support/vendor_bundle
# Store the location of vendored gems in a handy env var
set_vendor_bundle_var:
test: test ! -f /opt/elasticbeanstalk/support/.post-provisioning-complete
cwd: /opt/elasticbeanstalk/support
command: sed -i '12iexport
EB_CONFIG_APP_VENDOR_BUNDLE=$EB_CONFIG_APP_SUPPORT/vendor_bundle' envvars
# The --deployment flag tells bundler to install gems to vendor/bundle/, so
# symlink that to the persistent directory
symlink_vendor_bundle:
test: test ! -f /opt/elasticbeanstalk/support/.post-provisioning-complete
cwd: /opt/elasticbeanstalk/hooks/appdeploy/pre
command: sed -i 's/\(^cd $EB_CONFIG_APP_ONDECK\)/\1\nln -s $EB_CONFIG_APP_VENDOR_BUNDLE .\/vendor\/bundle/' 10_bundle_install.sh
# Don't run the above commands again on this instance
# cf. http://stackoverflow.com/a/16846429/283398
z_write_post_provisioning_complete_file:
cwd: /opt/elasticbeanstalk/support
command: touch .post-provisioning-complete%
I am using a 64 bit Amazon Linux server and trying to install using ruby-2.0.0 and passenger
I suspect this is failing because in your ebextensions you are running bundle install --deployment. Is there a reason you want to use the --deployment flag. Take a look at this answer: https://stackoverflow.com/a/3681411/161628.
If your usecase does not need the --deployment flag, I would suggest don't use it.
You can locally package your app dependencies using vendor/cache using the approach documented in this blog.
Can you update the question with the contents of your Gemfile. Are you are using git# URLs in your Gemfile? You might want to use URLs like "git://github.com:bokmann/font-awesome-rails.git" in case you have "git#github.com:bokmann/font-awesome-rails.git" in your Gemfile.
Take a look at this answer.
Related
I have a previously deployed Ruby on Rails API that I wanted to add some additional seed data to.
I am getting the following error when I deploy from either the Heroku CLI or from the web interface:
-----> Ruby app detected
-----> Installing bundler 2.0.2
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.6.5
-----> Installing dependencies using bundler 2.0.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
bash: /tmp/build_9062c7d5995d7f7c573d9509eb8f19d5/bin/bundle: cannot execute binary file: Exec format error
Bundler Output: bash: /tmp/build_9062c7d5995d7f7c573d9509eb8f19d5/bin/bundle: cannot execute binary file: Exec format error
!
! Failed to install gems via Bundler.
!
! Push rejected, failed to compile Ruby app.
! Push failed
I am not sure what the issue is. I have tried:
Deploying to a brand new Heroku application
Adding a Procfile
Adding a Ruby build pack
Resolving some outstanding security warnings from Github by running Bundle update locally and getting the new gemfile into my repo, prior to this there were no new Gem changes
None of these has changed the error I am getting.
If I clone the repo from github into a new folder on my Macbook I am able to get it up and running locally.
I have the following on my Macbook:
Ruby Version 2.6.5p114
Rails Version 6.0.3.2
Google does not seem to be turning up much, aside from some references to CPU architecture which I assume I have no control of in the Heroku environment.
My feeling is that it is related to bash being unable to execute bin/bundle but I've no idea why or how to resolve.
I vaguely recall having issues previously on this app, in that I was not able to run heroku run rake commands, possibly getting a similar error message, but to resolve I think I was able to simply run heroku run bin/rake
I believe the original rails new command was run on Windows 10 WSL environment in case that is relevant.
EDIT: I'm able to recreate a similar issue with rake, but the fix for rake does not work for bundle and I'm not even sure if it would help with the deployment issue.
➜ appbackend git:(master) heroku run rake
Running rake on ⬢ heroku-name-40049... up, run.8396 (Hobby)
bash: /app/bin/bundle: cannot execute binary file: Exec format error
➜ appbackend git:(master) heroku run bin/rake
Running bin/rake on ⬢ heroku-name-40049... up, run.5201 (Hobby)
Abort testing: Your Rails environment is running in production mode!
➜ appbackend git:(master)
➜ appbackend git:(master) heroku run bundle install
Running bundle install on ⬢ heroku-name-40049... up, run.7746 (Hobby)
bash: /app/bin/bundle: cannot execute binary file: Exec format error
➜ appbackend git:(master) heroku run bin/bundle install
Running bin/bundle install on ⬢ heroku-name-40049... up, run.4632 (Hobby)
bash: bin/bundle: cannot execute binary file: Exec format error
Turns out it was exactly as the error message stated Exec format error.
The bundle file in the bin directory was not the right format. Not sure how I managed to deploy in the first place (the history of this file has only 2 version in the repo, the first commit, and now the fix).
I was able to resolve by overwriting the bundle file from a different working rails install. Appreciated the help provided.
I have a rails site, which I deploy via ssh using a git post-receive hook. When I ssh into the server and run bundle install it runs correctly under the specified ruby version of 2.2.2. However, when I push to the server from my local machine and it hits the 'bundle install command', I get the following:
hooks/post-receive: /usr/local/bin/bundle: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
I can't find for the life of me why it is pointing to ruby1.9.1. This directory does not exist. I do see a directory for ruby2.3 in that directory, but not ruby2.2.2 which is the correct directory. Something is quite fouled up, but I can't figure how to fix it. Anyone seen anything like this?
UPDATE: Here is my post-receive hook, as per the request below...
#!/bin/bash
GIT_DIR=/home/deploy/www_production
WORK_TREE=/home/deploy/www
export MGOTS_DATABASE_USER='user'
export MGOTS_DATABASE_PASSWORD='pass'
export RAILS_ENV="production"
. ~/.bash_profile
while read oldrev newrev ref
do
if [[ $ref = refs/heads/master ]];
then
echo "Master ref received. Deploying master branch to production..."
mkdir -p $WORK_TREE
git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f
mkdir -p $WORK_TREE/shared/pids $WORK_TREE/shared/sockets $WORK_TREE/shared/log
# start deploy tasks
cd $WORK_TREE
bundle install
rake db:create
rake db:migrate
rake assets:precompile
rake requests:cleanup
sudo restart puma-manager
sudo service nginx restart
# end deploy tasks
echo "Git hooks deploy complete"
else
echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
fi
done
UPDATE: For the sake of clarity, as the answer points to the correct place to find the answer, but doesn't state it exactly, I am posting my updated hook file here. You can see the difference between this one and the one above, and that is what solved the problem. Please note that the path to the rvm directory can be found by typing the command: which rvm - that's the one you want to point to.
#!/bin/bash
GIT_DIR=/home/deploy/www_production
WORK_TREE=/home/deploy/www
export MGOTS_DATABASE_USER='user'
export MGOTS_DATABASE_PASSWORD='pass'
export RAILS_ENV="production"
export RUBYGEMS_GEMDEPS="/home/deploy/.rvm/ruby-2.2.2#www/gems"
. ~/.bash_profile
[[ -s "/usr/share/rvm/bin/rvm" ]] && source "/usr/share/rvm/bin/rvm"
while read oldrev newrev ref
do
if [[ $ref = refs/heads/master ]];
then
echo "Master ref received. Deploying master branch to production..."
mkdir -p $WORK_TREE
git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f
mkdir -p $WORK_TREE/shared/pids $WORK_TREE/shared/sockets $WORK_TREE/shared/log
# start deploy tasks
cd $WORK_TREE
bundle install
rake db:create
rake db:migrate
rake assets:precompile
rake requests:cleanup
sudo restart puma-manager
sudo service nginx restart
# end deploy tasks
echo "Git hooks deploy complete"
else
echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
fi
done
You need to load RVM functions to the shell script. link
Or just switch to Rbenv :)
First, set your default ruby to use the version 2.2.2
Are you using RVM? For RVM its: rvm use --default 2.2.2
I have an Ubuntu server to deploy my Rails projects. In my Ubuntu server I had RVM.
Now I want to deploy new projects with Rails 5.1 and webpacker. To deploy this projects, I've installed NVM, npm and yarn in my Ubuntu server.
In my Rails 5.1 / Webpacker project I have following gems for capistrano deployment:
Gemfile
group :development do
gem 'capistrano-rails'
gem 'capistrano-rvm'
gem 'capistrano-passenger'
gem 'capistrano-nvm', require: false
gem 'capistrano-yarn'
end
In deploy.rb I've added some configurations for capistrano nvm and capistrano yarn.
deploy.rb
set :nvm_type, :user # or :system, depends on your nvm setup
set :nvm_node, 'v7.10.0'
set :nvm_map_bins, %w{node npm yarn}
set :yarn_target_path, -> { release_path.join('client') } #
set :yarn_flags, '--production --silent --no-progress' # default
set :yarn_roles, :all # default
set :yarn_env_variables, {}
Also I've added node_modules in linked_dirs.
deploy.rb
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system node_modules client/node_modules}
The problem comes when I execute cap deploy in assets:precompile step. Next you have the error log.
terminal log
00:10 deploy:assets:precompile
01 /usr/local/rvm/bin/rvm 2.4.1#project do bundle exec rake assets:precompile
01 Yarn executable was not detected in the system.
01 Download Yarn at https://yarnpkg.com/en/docs/install
01 /home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake: No such file or directory - node
01 Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xxx.xxx: rake exit status: 1
rake stdout: Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
/home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake: No such file or directory - node
Node.js not installed. Please download and install Node.js
https://nodejs.org/en/download/
rake stderr: Nothing written
SSHKit::Command::Failed: rake exit status: 1
rake stdout: Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
/home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake: No such file or directory - node
Node.js not installed. Please download and install Node.js
https://nodejs.org/en/download/
rake stderr: Nothing written
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing on host xxx.xxx.xxx.xxx: rake exit status: 1
rake stdout: Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
/home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake: No such file or directory - node
Node.js not installed. Please download and install Node.js
https://nodejs.org/en/download/
rake stderr: Nothing written
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
DEBUG [016276ab] * spring (2.0.1)
DEBUG [016276ab] * spring-watcher-listen (2.0.1)
DEBUG [016276ab] * web-console (3.5.0)
DEBUG [016276ab] Install missing gems with `bundle install`
DEBUG [016276ab] Finished in 0.677 seconds with exit status 1 (failed).
INFO [86e74b01] Running /usr/local/rvm/bin/rvm 2.4.1#project do bundle install --path /home/deploy/rails/241/project/shared/bundle --without development test --deployment --quiet on xxx.xxx.xxx.xxx
DEBUG [86e74b01] Command: cd /home/deploy/rails/241/project/releases/20170511083021 && ( export NODE_VERSION="v7.10.0" ; /usr/local/rvm/bin/rvm 2.4.1#project do bundle install --path /home/deploy/rails/241/project/shared/bundle --without development test --deployment --quiet )
DEBUG [86e74b01] Warning, new version of rvm available '1.29.1', you are using older version '1.26.11'.
You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
INFO [86e74b01] Finished in 3.209 seconds with exit status 0 (successful).
DEBUG [4a428031] Running if test ! -d /home/deploy/rails/241/project/releases/20170511083021; then echo "Directory does not exist '/home/deploy/rails/241/project/releases/20170511083021'" 1>&2; false; fi on xxx.xxx.xxx.xxx
DEBUG [4a428031] Command: if test ! -d /home/deploy/rails/241/project/releases/20170511083021; then echo "Directory does not exist '/home/deploy/rails/241/project/releases/20170511083021'" 1>&2; false; fi
DEBUG [4a428031] Finished in 0.066 seconds with exit status 0 (successful).
INFO [d225a8b5] Running /usr/local/rvm/bin/rvm 2.4.1#project do bundle exec rake assets:precompile on xxx.xxx.xxx.xxx
DEBUG [d225a8b5] Command: cd /home/deploy/rails/241/project/releases/20170511083021 && ( export NODE_VERSION="v7.10.0" RAILS_ENV="production" ; /usr/local/rvm/bin/rvm 2.4.1#project do bundle exec rake assets:precompile )
DEBUG [d225a8b5] Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
DEBUG [d225a8b5] /home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake: No such file or directory - node
DEBUG [d225a8b5] Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/
Thanks in advance!
I prefer to compile assets locally and then copy to the production servers with rsync:
# lib/capistrano/tasks/precompile.rake
namespace :assets do
desc 'Precompile assets locally and then rsync to web servers'
task :precompile do
run_locally do
with rails_env: stage_of_env do
execute :bundle, 'exec rake assets:precompile'
end
end
on roles(:web), in: :parallel do |server|
run_locally do
execute :rsync,
"-a --delete ./public/packs/ #{fetch(:user)}##{server.hostname}:#{shared_path}/public/packs/"
execute :rsync,
"-a --delete ./public/assets/ #{fetch(:user)}##{server.hostname}:#{shared_path}/public/assets/"
end
end
run_locally do
execute :rm, '-rf public/assets'
execute :rm, '-rf public/packs'
end
end
end
# config/deploy.rb
after 'deploy:updated', 'assets:precompile'
In your Capfile you need to include all the capistrano tasks:
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/**/*.rake').each { |r| import r }
This eliminates the need to install node and yarn on the production servers.
Of course you need node and yarn installed locally
What worked for me was making sure NVM was included in the PATH. By default, in a bash terminal, NVM adds its environment variables to the end of ~/.bashrc, but much of that file is not usually executed in a non-interactive terminal (which Capistrano runs in). I found this comment helpful:
Put your NVM source script in your .bashrc which is still evaluated even during an non-interactive SSH session. Just make sure you place the declarations at the top, before the case statement:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
The error tells you pretty much what's wrong. Neither Yarn or Node can be found on the server. Your installation might be incorrect.
Follow instructions to install both here:
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
and here:
https://yarnpkg.com/lang/en/docs/install/#linux-tab
Then make sure you can call:
yarn
node
On the server. If not, you might need to add paths to executables into your PATH variable
First - Install Yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn
Second - Install NodeJS(now 14 is newest):
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
I'M trying to deploy with capistrano to a staging server. This command fails both on deploy and manually:
cd .../apps/myapp/releases/20150205154326 && ( RVM_BIN_PATH=/usr/local/rvm/bin/ PATH=/usr/bin/git:$PATH /usr/local/rvm/bin/rvm default do bundle install --path .../apps/myapp/shared/bundle --without development test --deployment --quiet )
error:
Git error: command 'git clone --no-checkout --quiet
".../apps/myapp/shared/bundle/ruby/2.1.0/cache/bundler/git/fog- 8836460df0e4c80347618efd3adda34209f0c6f7"
".../apps/myapp/shared/bundle/ruby/2.1.0/bundler/gems/fog- 5ceace13efe1"'
in directory .../apps/myapp/releases/20150205154326 has failed.
If this error persists you could try removing the cache directory
'.../apps/myapp/shared/bundle/ruby/2.1.0/cache/bundler/git/fog-8836460df0e4c80347618efd3adda34209f0c6f7'
However, this dir exists, and the permissions are ok. I've tried to delete it and run again, but to no avail.
solved by reinstalling bundler and rvm
I've setup a post-update hook for my project. I have a bare repository (/var/git/myproject) which I push to, and a live repository (/var/www/myproject) where my app is running. I also included bundle install and bundle exec rake db:migrate to install gems and update db.
Below is my post-update hook
#!/bin/bash
echo "Pulling changes into Live..."
cd /var/www/myproject || exit
unset GIT_DIR
git pull origin master
# check if ruby app
if [ -f /var/www/myproject/Gemfile ];
then
echo " Ruby app detected..."
bundle install --without development test
bundle exec rake db:migrate # migrate database
fi
exec git-update-server-info
When I push my changes though I get the following message (notice the "bundle command not found" error):
martyn#localhost:~/www/myproject$ git push -u origin master
martyn#192.168.0.100's password:
Counting objects: 832, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (783/783), done.
Writing objects: 100% (832/832), 487.70 KiB, done.
Total 832 (delta 434), reused 0 (delta 0)
remote: Pulling changes into Live...
remote: From /var/git/myproject
remote: * branch master -> FETCH_HEAD
remote: Ruby app detected...
remote: hooks/post-update: line 13: bundle: command not found
remote: hooks/post-update: line 14: bundle: command not found
To 192.168.24.100:/var/git/myproject.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
Why is bundle not running? I cd to the live app directory in the script. When I'm in terminal myself and I cd to the live directory and run bundle install it works so bundle is there.
Your hook shell ins't the same than the one you logged in (and which has the proper PATH)
You can try using at the beginning your your hook script:
#!/bin/bash -l
(See this answer
The -l parameter executes the command in a login shell, which means that it inherits your path and other settings from your shell profile.
)
Or you can make sure your script gets the same environment than your current session, by adding in the first lines of your hook:
$ source $HOME/.bash_profile # single user RVM setup
$ source /etc/profile # multi user RVM setup
Or (final alternative) you can add (before calling bundle) (for a single-user rvm installation)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"