带有rbenv:/home/deploy/.rbenv/bin/rbenv的capistrano部署:没有这样的文件或目



我最近在ubuntu服务器上从rvm切换到了rbenv。我遵守了官方文件中的所有说明https://github.com/rbenv/rbenv.当我尝试使用capistrano进行部署时,我遇到一条错误消息,说它找不到/bin/rbenv目录。

00:24 bundler:config
01 RBENV_ROOT=$HOME/.rbenv RBENV_VERSION=2.5.8 $HOME/.rbenv/bin/rbenv exec bundle config --local deployment true
01 bash: /home/deploy/.rbenv/bin/rbenv: No such file or directory
#<Thread:0x00007ff4640d25e0@/Users/kevinsun/.rvm/gems/ruby-2.5.8@wager/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /Users/kevinsun/.rvm/gems/ruby-2.5.8@wager/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/kevinsun/.rvm/gems/ruby-2.5.8@wager/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as deploy@3.133.135.38: bundle exit status: 127 (SSHKit::Runner::ExecuteError)
bundle stdout: Nothing written
bundle stderr: bash: /home/deploy/.rbenv/bin/rbenv: No such file or directory
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@3.133.135.38: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: bash: /home/deploy/.rbenv/bin/rbenv: No such file or directory

Caused by:
SSHKit::Command::Failed: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: bash: /home/deploy/.rbenv/bin/rbenv: No such file or directory
Tasks: TOP => deploy:updated => bundler:install => bundler:config
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy@3.133.135.38: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: bash: /home/deploy/.rbenv/bin/rbenv: No such file or directory

在我的例子中,深入到该目录,我可以确认/home/deploy/.rbenv/下没有/bin/rbenv

ubuntu@ip-10-0-0-163:/home/deploy/.rbenv$ ls -a
.  ..  plugins  shims  versions

我试着根据这个答案摆弄我的部署文件,但没有用。

这是我的Gemfile、Capfile和deploy.rb:

Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.8'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.3'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
gem "font-awesome-rails"
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
gem 'momentjs-rails'
gem 'bootstrap-toggle-rails'
#Admin user
gem 'activeadmin'
gem 'activeadmin_settings_cached'
gem 'formadmin'
gem 'active_admin_role'
gem "kaminari"
# charts
gem "chartkick"
gem 'groupdate'
#background
gem "redis"
gem 'sidekiq', '5.2.7'
gem 'sidekiq-status'
# copy clipboard
gem 'clipboard-rails'
# ransack
gem 'ransack'
# geocoder
gem 'geocoder'
# Plus integrations with:
gem 'devise'
gem 'cancancan'
gem 'draper'
gem 'pundit'
#design
gem "bootstrap", '~> 4.3.1'
gem 'ckeditor', github: 'galetahub/ckeditor'
gem 'paperclip'
gem 'aws-sdk', '~> 3.0', '>= 3.0.1'
gem 'aws-sdk-s3', '~> 1.83', '>= 1.83.1'
gem 'color'
#payments
gem 'money-rails'
gem 'stripe'
gem 'paypal-sdk-rest'
#nested form
gem 'nested_form_fields'
# slick
gem "jquery-slick-rails"
gem 'jquery-rails'
gem 'jquery-ui-rails'
#gem 'font-awesome-sass'
gem 'remotipart'
# paginate
gem 'will_paginate'
gem 'will_paginate_infinite'
gem 'validates_email_format_of'
# simple form and validations
gem 'simple_form'
gem 'client_side_validations'
gem 'client_side_validations-simple_form'
gem 'jquery-validation-rails'
gem 'alertifyjs-rails'
gem 'bootstrap3-datetimepicker-rails', '~> 4.17.47'
#social login
gem 'omniauth'
gem 'omniauth-facebook'
gem 'omniauth-google-oauth2'
#API
gem 'rack-cors', '0.4.0'
gem 'rack-attack', '5.0.1'
gem 'active_model_serializers'
gem 'jwt'
gem 'simple_command'
gem 'bcrypt'
# sitemap
gem 'sitemap_generator'
# notifications
gem 'notifications', '~> 0.6.0'
# enum
gem 'simple_enum'
# recaptcha
gem "recaptcha", :require => "recaptcha/rails"
# cron
gem 'whenever', require: false
# autolink
gem "rails_autolink"
#for read unread
gem 'unread'
#list gem
gem 'acts_as_list'
#cropper and dropzone
gem 'cropper_rails'
gem 'dropzonejs-rails'
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'byebug'
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'annotate'
gem 'bullet'
gem "brakeman"
gem "rb-readline"
#deploy
gem 'capistrano',         require: false
# gem 'capistrano-rvm',     require: false
gem 'capistrano-rbenv', '~> 2.2'
gem 'capistrano-rails',   require: false
gem 'capistrano-bundler', require: false
gem 'capistrano-sidekiq', require: false
gem 'capistrano3-puma',   require: false
gem 'sshkit-sudo',        require: false
gem 'capistrano-nvm',     require: false
gem 'capistrano3-monit', github: 'naps62/capistrano3-monit'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'language_filter'
gem 'nokogiri', '~> 1.10', '>= 1.10.9'
gem 'figaro'
#gem 'rvm-capistrano'

Capfile

# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
# Include tasks from other gems included in your Gemfile
require 'capistrano/rails'
require 'capistrano/bundler'
# require 'capistrano/rvm'
require 'capistrano/rbenv'
require 'capistrano/puma'
require 'capistrano/sidekiq'
require "whenever/capistrano"
require 'capistrano/sidekiq/monit'

install_plugin Capistrano::Puma  # Default puma tasks
install_plugin Capistrano::Puma::Workers  # if you want to control the workers (in cluster mode)
install_plugin Capistrano::Puma::Monit 
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

deploy.rb

# config valid only for current version of Capistrano
#lock '3.8.1'
#require "rvm/capistrano"
set :application, 'ewagers-noah-rails'
set :repo_url, 'git@gitlab.com:ankush_verma/ewagers.git'
set :branch, 'autoscale-test'

set :user,            'deploy'
set :puma_threads,    [4, 16]
set :puma_workers,    4
# Don't change these unless you know what you're doing
set :pty,             false
set :use_sudo,        false
set :sidekiq_user,    fetch(:user)
set :stage,           :production
set :deploy_via,      :remote_cache
set :deploy_to,       "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind,       "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log,  "#{release_path}/log/puma.access.log"
set :ssh_options,     { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true  # Change to false when not using ActiveRecord
set :rvm_ruby_version, 'ruby-2.5.8@wager'
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml', 'puma.rb', 'config/app.yml', "config/sidekiq.yml", "config/env.yml")
set :sidekiq_config, 'config/sidekiq.yml'
# Default value for linked_dirs is []
# append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system'
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads', 'public/watir')
## Defaults:
# set :scm,           :git
# set :branch,        :master
# set :format,        :pretty
# set :log_level,     :debug
set :keep_releases, 2
set :execute_monit_without_sudo, false
## Linked Files & Directories (Default None):
# set :linked_files, %w{config/database.yml}
# set :linked_dirs,  %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
before :start, :make_dirs
end
namespace :deploy do
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/#{fetch(:branch)}`
puts "WARNING: HEAD is not the same as origin/#{fetch(:branch)}"
puts "Run `git push` to sync changes."
exit
end
end
end
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'puma:restart'
end
end

before :starting,     :check_revision
after  :finishing,    :compile_assets
after  :finishing,    :cleanup
after  :finishing,    :restart
end
namespace :deploy do
desc "Update crontab with whenever"
task :update_cron do
on roles(:app) do
within current_path do
execute :bundle, :exec, "whenever --update-crontab #{fetch(:application)}"
end
end
end
after :finishing, 'deploy:update_cron'
end
namespace :deploy do
desc 'run "CREATE EXTENSION IF NOT EXISTS "pgcrypto"" in sudo mode'
task :sudo_pgcrypto do
on roles(:all) do |host|
execute :sudo, "CREATE EXTENSION IF NOT EXISTS", "pgcrypto"
end
end
end
namespace :logs do
desc "tail rails logs" 
task :puma do
on roles(:app) do
execute "tail -f -n 500 #{shared_path}/log/#{fetch(:rails_env)}.log "
end
end
end
# ps aux | grep puma    # Get puma pid
# kill -s SIGUSR2 pid   # Restart puma
# kill -s SIGTERM pid   # Stop puma
set :rbenv_type, :user # or :system, or :fullstaq (for Fullstaq Ruby), depends on your rbenv setup
set :rbenv_ruby, '2.5.8'
set :rbenv_ruby_dir, '/home/deploy/.rbenv/versions/2.5.8'
# in case you want to set ruby version from the file:
# set :rbenv_ruby, File.read('.ruby-version').strip
set :default_env, {
path: '/home/deploy/.rbenv/plugins/ruby-build/bin:/home/deploy/.rbenv/shims:/home/deploy/.rbenv/bin:$PATH',
rbenv_root: '/usr/bin/rbenv' # also tried '/home/deploy/.rbenv' here
}
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
set :rbenv_roles, :all # default value
set :rbenv_custom_path, '/usr/bin/rbenv' # also tried '/home/deploy/.rbenv' here

这对我的情况有帮助,我遇到了同样的问题,capistrano无法找到rbenv二进制

set :rbenv_prefix, '/usr/bin/rbenv exec'

由于github上的这个问题github

最新更新