简体   繁体   English

mina deploy 抛出错误 - 捆绑:找不到命令! 错误:部署失败

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

Am trying to deploy rails app to digital ocean using mina gem.我正在尝试使用 mina gem 将 rails 应用程序部署到数字海洋。 I did all the configuration and mina setup also is getting executed properly.我做了所有的配置,mina 设置也得到了正确执行。

mina deploy throws error. mina 部署抛出错误。 Any help would be much appreciated.任何帮助将非常感激。

Here is the mina deploy --trace这是 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.我有些感觉它与可执行目录的路径有关,因此这样做了.. gem 环境 - 给出了这个。

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). Bundler 必须安装在您的服务器机器上(您尝试部署到的机器)。 The easiest way is to login into it by ssh and run gem install bundler once.最简单的方法是通过 ssh 登录并运行gem install bundler一次。 It's listed as a common question in official mina FAQ它被列为官方 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.对我来说,问题是没有加载 rbenv。

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.如果您确定 ruby​​ 和 bundler 像我一样正确安装在服务器上,那么修复是确保您的 shell 加载rbenv 的第一件事。

Open .bashrc打开.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 -)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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