capistrano / rbenv

Idiomatic rbenv support for Capistrano 3.x
MIT License
203 stars 60 forks source link

Capistrano unable to locate rbenv correctly #99

Closed gleb-skobinsky closed 2 years ago

gleb-skobinsky commented 2 years ago

I’m trying to deploy a Rails server using Capistrano, but it does not seem to manage paths correctly.

At first, I followed the guide at gorails.com, but ended up with the following error:
bash: No such file or directory: /home/my_user/.rbenv/bin/rbenv

I assumed that Capistrano was looking for the rbenv executable, and specified this in the config/deploy.rb file:
set :rbenv_prefix, “/home/my_user/rbenv/bin/rbenv”

However, now I get the following error:
rbenv: bundle: command not found

Here are my configs:

Capfile:

# Load DSL and set up stages 
require "capistrano/setup" 
require "capistrano/deploy" 
require "capistrano/rails" 
require "capistrano/passenger" 
require "capistrano/rbenv" 

set :rbenv_type, :user 
set :rbenv_ruby, '3.0.2' 
# 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 

Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

deploy.rb:

# config valid for current version and patch releases of Capistrano 
lock "~> 3.17.0" 

set :application, "messenger_integration" 
set :repo_url, "[GIT_REPO_URL]" 
set :rbenv_ruby, "3.0.2" 
set :rbenv_prefix, '/home/ruby/rbenv/bin/rbenv' 

# Default branch is :master 
# ask :branch, `git rev-parse —abbrev-ref HEAD`.chomp 

# Default deploy_to directory is /var/www/my_app_name 
set :deploy_to, "/home/ruby/apps/#{fetch :application}" 
# Default value for :format is :airbrussh. 
# set :format, :airbrussh 

# You can configure the Airbrussh format using :format_options. 
# These are the defaults. 
set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto 

# Default value for :pty is false 
# set :pty, true 

# Default value for :linked_files is [] 
append :linked_files, "config/database.yml", 'config/master.key' 

# Default value for linked_dirs is [] 
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "tmp/webpacker", "public/system", "vendor", "storage" 

# Default value for default_env is {} 
# set :default_env, { path: "/opt/ruby/bin:$PATH" } 

# Default value for local_user is ENV['USER'] 
# set :local_user, -> { `git config user.name`.chomp } 

# Default value for keep_releases is 5 
set :keep_releases, 5 

# Uncomment the following to require manually verifying the host key before first deploy. 
# set :ssh_options, verify_host_key: :secure
gleb-skobinsky commented 2 years ago

I think what’s gone wrong in the first place is that my $HOME/.rbenv directory does not have a “bin” folder and, accordingly, an rbenv executable inside of it. However, when I came I had it already installed on the server, by another team that launched a couple of apps on this machine previously. Probably it’s some older version of rbenv? rbenv —version responds with 1.2.2. Which version of capestrano should be compatible with it?

gleb-skobinsky commented 2 years ago

Okay, so for any future wanderers in search of a solution, I simply ran git init and git pull https://github.com/rbenv/rbenv.git to fix my .rbenv installation. This ensured presence of both bin/rbenv and the files it points to through symbolic link.