简体   繁体   中英

mina deploy throws error - bundle: command not found ! ERROR: Deploy failed

Am trying to deploy rails app to digital ocean using mina gem. I did all the configuration and mina setup also is getting executed properly.

mina deploy throws error. Any help would be much appreciated.

Here is the mina deploy --trace

root@ruby-rails-1gb-blr1-01:/home/rails/rails-demo# mina deploy --trace
** Invoke deploy (first_time)
** Execute deploy
** Invoke remote_environment (first_time)
** Execute remote_environment
** Invoke git:clone (first_time)
** Execute git:clone
** Invoke deploy:link_shared_paths (first_time)
** Execute deploy:link_shared_paths
** Invoke bundle:install (first_time)
** Execute bundle:install
** Invoke rails:db_migrate (first_time)
** Execute rails:db_migrate
** Invoke rails:assets_precompile (first_time)
** Execute rails:assets_precompile
** Invoke deploy:cleanup (first_time)
** Execute deploy:cleanup
** Invoke puma:phased_restart (first_time)
** Invoke remote_environment (first_time)
** Execute remote_environment
** Execute puma:phased_restart
root@139.59.72.156's password: 
-----> Creating a temporary build path
-----> Deploying rails-demo to 139.59.72.156:/home/rails/rails-demo
-----> Fetching new git commits
       remote: Counting objects: 43, done.
remote: Compressing objects: 100% (33/33), done.
remote: Total 43 (delta 6), reused 43 (delta 6), pack-reused 0
Unpacking objects: 100% (43/43), done.   
       From github.com:krishnateja/rails-demo
          739096a..4cf74f8  master     -> master
-----> Using git branch 'master'
       Cloning into '.'...
       done.
-----> Using this git commit
       root (4cf74f8):
       > small config change
-----> Symlinking shared paths
-----> Installing gem dependencies using Bundler
       bash: line 137: bundle: command not found
 !     ERROR: Deploy failed.
-----> Cleaning up build
       Unlinking current
       OK
       Connection to 139.59.72.156 closed.

 !     Run Error

deploy.rb

require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rvm'
require 'mina/puma'

set :application_name, 'rails-demo'
set :domain, '139.59.72.156'
set :deploy_to, '/home/rails/rails-demo'
set :repository, 'git@github.com:krishnateja/rails-demo.git'

set :shared_dirs, fetch(:shared_dirs, []).push('log', 'tmp/pids', 'tmp/sockets', 'public/uploads')
set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml', 'config/puma.rb')
set :user, 'root'

task :environment do
  invoke :'rvm:use', 'ruby-2.2.3'
end

task :setup do
  command %[touch "#{fetch(:shared_path)}/config/database.yml"]
  command %[touch "#{fetch(:shared_path)}/config/secrets.yml"]
  command %[touch "#{fetch(:shared_path)}/config/puma.rb"]
  comment "Be sure to edit '#{fetch(:shared_path)}/config/database.yml', 'secrets.yml' and puma.rb."
end

task :deploy do
  deploy do
    comment "Deploying #{fetch(:application_name)} to #{fetch(:domain)}:#{fetch(:deploy_to)}"
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'

    on :launch do
      invoke :'puma:phased_restart'
    end
  end

end

puma.rb

environment "production"

bind  "unix:///home/rails/rails-demo/shared/tmp/sockets/puma.sock"
pidfile "/home/rails/rails-demo/shared/tmp/pids/puma.pid"
state_path "/home/rails/rails-demo/shared/tmp/sockets/puma.state"
directory "/home/rails/rails-demo/current"

workers 2
threads 1,2

daemonize true

activate_control_app 'unix:///home/rails/rails-demo/shared/tmp/sockets/pumactl.sock'

prune_bundler

I Some how felt its something to do with the path to executable directory, hence did this.. gem environment - gives this.

root@ruby-rails-1gb-blr1-01:/home/rails/rails-demo# gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 2.6.14
  - RUBY VERSION: 2.2.3 (2015-08-18 patchlevel 173) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/local/rvm/gems/ruby-2.2.3
  - USER INSTALLATION DIRECTORY: /root/.gem/ruby/2.2.0
  - RUBY EXECUTABLE: /usr/local/rvm/rubies/ruby-2.2.3/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/rvm/gems/ruby-2.2.3/bin
  - SPEC CACHE DIRECTORY: /root/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /usr/local/rvm/rubies/ruby-2.2.3/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/local/rvm/gems/ruby-2.2.3
     - /usr/local/rvm/gems/ruby-2.2.3@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/local/rvm/gems/ruby-2.2.3/bin
     - /usr/local/rvm/gems/ruby-2.2.3@global/bin
     - /usr/local/rvm/rubies/ruby-2.2.3/bin
     - /usr/local/rvm/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games
     - /usr/local/games
     - /snap/bin

Added EXECUTABLE DIRECTORY to Path.

root@ruby-rails-1gb-blr1-01:/home/rails/rails-demo# export PATH=$PATH:/usr/local/rvm/gems/ruby-2.2.3/bin
root@ruby-rails-1gb-blr1-01:/home/rails/rails-demo# echo $PATH
/usr/local/rvm/gems/ruby-2.2.3/bin:/usr/local/rvm/gems/ruby-2.2.3@global/bin:/usr/local/rvm/rubies/ruby-2.2.3/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/rvm/gems/ruby-2.2.3/bin

Bundler has to be installed on your server machine (the one you trying to deploy to). The easiest way is to login into it by ssh and run gem install bundler once. It's listed as a common question in official mina FAQ

I have this issue as well, and workaround it by moving my launch tasks to a separate task. So you could do this by turning

task :deploy do
  deploy do
    comment "Deploying #{fetch(:application_name)} to #{fetch(:domain)}:#{fetch(:deploy_to)}"
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'

    on :launch do
      invoke :'puma:phased_restart'
    end
  end

end

to

task :deploy do
  deploy do
    comment "Deploying #{fetch(:application_name)} to #{fetch(:domain)}:#{fetch(:deploy_to)}"
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'
  end
end

task :launch do
  invoke :'puma:phased_restart'
end

And then execute it separately (which is admittedly suboptimal):

$ mina deploy
$ mina launch

I don't know the particulars of your task, but I configure mine like so:

task :launch => :remote_environment do
  in_path(fetch(:current_path)) do
    invoke :'my:task'
  end
end

I know this isn't a solution or explanation, but hopefully it helps.

For me the issue was with rbenv not being loaded.

If you're sure that ruby and bundler are correctly installed on the server as I was then the fix is to make sure the first thing your shell does it to load rbenv.

Open .bashrc

Make sure the following is called before

# If not running interactively, don't do anything

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM