capistrano / bundler

Bundler support for Capistrano 3.x
MIT License
219 stars 83 forks source link

Specify bundler executable location #108

Closed craibuc closed 6 years ago

craibuc commented 6 years ago

I'm using a shared hosting environment that has 3 version of Ruby installed: 2.0, 2.22, and 2.33. I'm using 2.33 in my application. Unfortunately, they don't use rvm or rbenv to manage this.

As a result, I need to use specific bundler settings to get my Gems installed in their environment:

app_dir$ /usr/local/bin/ruby233 /usr/local/bin/bundle233 --path vendor/bundle

When run manually (via ssh), this installs the Gems in the app_dir/shared/vendor/bundle directory.

How would I represent /usr/local/bin/ruby233 /usr/local/bin/bundle233 --path vendor/bundle in capistrano/bundler?

mattbrictson commented 6 years ago

I'd suggest customizing the bundle command via the SSHKit command-map, like this:

# put this in deploy.rb
SSHKit.config.command_map[:bundle] = "/usr/local/bin/ruby233 /usr/local/bin/bundle233"

Does that work?

craibuc commented 6 years ago

Seems like it is interfering with the deploy:check:directories step for some reason.

Pre-SSHKit

Capfile:

# Load DSL and set up stages
require "capistrano/setup"

# Include default deployment tasks
require "capistrano/deploy"

# Git
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

# Phusion Passenger tasks
# https://github.com/capistrano/passenger
# require "capistrano/passenger"

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

$ bundle exec cap staging deploy:

[user]@pippin:~/Projects/sinatra/foo$ bundle exec cap staging deploy
00:00 git:wrapper
      01 mkdir -p /home/[user]/tmp
      01 stdin: is not a tty
    ✔ 01 [user]@supersonic.webhostserver.biz 0.817s
      Uploading /home/[user]/tmp/git-ssh-foo-staging-[user].sh 100.0%
      02 chmod 700 /home/[user]/tmp/git-ssh-foo-staging-[user].sh
      02 stdin: is not a tty
    ✔ 02 [user]@supersonic.webhostserver.biz 0.229s
00:01 git:check
      01 git ls-remote git@bitbucket.org:[user]/foo.git HEAD
      01 stdin: is not a tty
      01 f8c6a45edc27c11667c706d31dbf5a4d34001f00   HEAD
    ✔ 01 [user]@supersonic.webhostserver.biz 1.643s
00:03 deploy:check:directories
      01 mkdir -p /home/[user]/apps/foo/shared /home/[user]/apps/foo/releases
      01 stdin: is not a tty
    ✔ 01 [user]@supersonic.webhostserver.biz 0.229s
00:03 deploy:check:make_linked_dirs
      01 mkdir -p /home/[user]/apps/foo/shared/config
      01 stdin: is not a tty
    ✔ 01 [user]@supersonic.webhostserver.biz 0.237s
00:04 git:clone
      The repository mirror is at /home/[user]/apps/foo/repo
00:04 git:update
      01 git remote set-url origin git@bitbucket.org:[user]/foo.git
      01 stdin: is not a tty
    ✔ 01 [user]@supersonic.webhostserver.biz 0.240s
      02 git remote update --prune
      02 stdin: is not a tty
      02 Fetching origin
    ✔ 02 [user]@supersonic.webhostserver.biz 1.662s
00:06 git:create_release
      01 mkdir -p /home/[user]/apps/foo/releases/20181003173654
      01 stdin: is not a tty
    ✔ 01 [user]@supersonic.webhostserver.biz 0.229s
      02 git archive master | /usr/bin/env tar -x -f - -C /home/[user]/apps/foo/releases/20181003173654
      02 stdin: is not a tty
    ✔ 02 [user]@supersonic.webhostserver.biz 0.231s
00:08 deploy:set_current_revision
      01 echo "f8c6a45edc27c11667c706d31dbf5a4d34001f00" > REVISION
      01 stdin: is not a tty
    ✔ 01 [user]@supersonic.webhostserver.biz 0.229s
00:08 deploy:symlink:linked_files
      01 mkdir -p /home/[user]/apps/foo/releases/20181003173654/config
      01 stdin: is not a tty
    ✔ 01 [user]@supersonic.webhostserver.biz 0.227s
      02 ln -s /home/[user]/apps/foo/shared/config/database.yml /home/[user]/apps/foo/releases/20181003173654/config/database.yml
      02 stdin: is not a tty
    ✔ 02 [user]@supersonic.webhostserver.biz 0.226s
00:09 deploy:symlink:release
      01 ln -s /home/[user]/apps/foo/releases/20181003173654 /home/[user]/apps/foo/releases/current
      01 stdin: is not a tty
    ✔ 01 [user]@supersonic.webhostserver.biz 0.227s
      02 mv /home/[user]/apps/foo/releases/current /home/[user]/apps/foo
      02 stdin: is not a tty
    ✔ 02 [user]@supersonic.webhostserver.biz 0.229s
00:09 deploy:cleanup
      Keeping 3 of 4 deployed releases on supersonic.webhostserver.biz
      01 rm -rf /home/[user]/apps/foo/releases/20181003172452
      01 stdin: is not a tty
    ✔ 01 [user]@supersonic.webhostserver.biz 0.227s
00:10 deploy:log_revision
      01 echo "Branch master (at f8c6a45edc27c11667c706d31dbf5a4d34001f00) deployed as release 20181003173654 by [user]" >> /home/[user]/apps/foo/revision…
      01 stdin: is not a tty
    ✔ 01 [user]@supersonic.webhostserver.biz 0.232s

Post-SSHKit

Capfile:

# Load DSL and set up stages
require "capistrano/setup"

# Include default deployment tasks
require "capistrano/deploy"

# Git
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

# to allow for setting a specific location of bundler
require 'sshkit'
require 'sshkit/dsl'
include SSHKit::DSL

# bundler-specific settings (for server)
# https://github.com/capistrano/bundler
require "capistrano/bundler"

# Phusion Passenger tasks
# https://github.com/capistrano/passenger
# require "capistrano/passenger"

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

staging.rb:

set :ssh_user, 'foobar'
set :use_sudo, false

# set :ruby_version, '/usr/local/bin/ruby233'

server "supersonic.webhostserver.biz", user: fetch(:ssh_user), roles: %w{app, web, db}

# force tem directory to be located home directory; useful on a shared host like Site5.com
set :tmp_dir, "/home/#{fetch(:ssh_user)}/tmp"

# where the application will reside
set :deploy_to, "/home/#{fetch(:ssh_user)}/apps/#{fetch(:application)}"
set :shared_path, "/home/#{fetch(:ssh_user)}/apps/#{fetch(:application)}/shared"

#
# sshkit - set desired bundler path
#

SSHKit.config.command_map[:bundle] = "/usr/local/bin/ruby233 /usr/local/bin/bundle233"

# Install the current Bundler environment. By default, gems will be installed to
# the shared/bundle path. Gems in the development and test group will not be
# installed. The install command is executed with the --deployment and --quiet
# flags. You can override any of these defaults by setting the variables shown
# below.

set :bundle_flags,        '--deployment --quiet'
set :bundle_without,      [:development, :test]

$ bundle exec cap staging deploy:

00:00 git:wrapper
      01 mkdir -p /home/[user]/tmp
      01 stdin: is not a tty
    ✔ 01 [user]@supersonic.webhostserver.biz 0.893s
      Uploading /home/[user]/tmp/git-ssh-csb-staging-craibuc.sh 100.0%
      02 chmod 700 /home/[user]/tmp/git-ssh-csb-staging-craibuc.sh
      02 stdin: is not a tty
    ✔ 02 [user]@supersonic.webhostserver.biz 0.230s
00:01 git:check
      01 git ls-remote git@bitbucket.org:craibuc/csb.git HEAD
      01 stdin: is not a tty
      01 f8c6a45edc27c11667c706d31dbf5a4d34001f00 HEAD
    ✔ 01 [user]@supersonic.webhostserver.biz 2.508s
(Backtrace restricted to imported tasks)
cap aborted!
TypeError: no _dump_data is defined for class Thread::Mutex

Tasks: TOP => deploy:check:directories
(See full trace by running task with --trace)
The deploy has failed with an error: no _dump_data is defined for class Thread::Mutex

** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:

 DEBUG [f0b9c1a3]   stdin: is not a tty

  INFO [f0b9c1a3] Finished in 0.232 seconds with exit status 0 (successful).

  INFO ---------------------------------------------------------------------------

  INFO START 2018-10-03 12:46:04 -0500 cap staging deploy

  INFO ---------------------------------------------------------------------------

  INFO [64a8fb1b] Running /usr/bin/env mkdir -p /home/[user]/tmp as [user]@supersonic.webhostserver.biz

 DEBUG [64a8fb1b] Command: /usr/bin/env mkdir -p /home/[user]/tmp

 DEBUG [8995ded5]   stdin: is not a tty

  INFO [8995ded5] Finished in 0.893 seconds with exit status 0 (successful).

 DEBUG Uploading /home/[user]/tmp/git-ssh-csb-staging-craibuc.sh 0.0%

  INFO Uploading /home/[user]/tmp/git-ssh-csb-staging-craibuc.sh 100.0%

  INFO [04a0a348] Running /usr/bin/env chmod 700 /home/[user]/tmp/git-ssh-csb-staging-craibuc.sh as [user]@supersonic.webhostserver.biz

 DEBUG [04a0a348] Command: /usr/bin/env chmod 700 /home/[user]/tmp/git-ssh-csb-staging-craibuc.sh

 DEBUG [207e6200]   stdin: is not a tty

  INFO [207e6200] Finished in 0.230 seconds with exit status 0 (successful).

  INFO [8d522656] Running /usr/bin/env git ls-remote git@bitbucket.org:craibuc/csb.git HEAD as [user]@supersonic.webhostserver.biz

 DEBUG [8d522656] Command: ( export GIT_ASKPASS="/bin/echo" GIT_SSH="/home/[user]/tmp/git-ssh-csb-staging-craibuc.sh" ; /usr/bin/env git ls-remote git@bitbucket.org:craibuc/csb.git HEAD )

 DEBUG [02b5e475]   stdin: is not a tty

 DEBUG [02b5e475]   f8c6a45edc27c11667c706d31dbf5a4d34001f00  HEAD

  INFO [02b5e475] Finished in 2.508 seconds with exit status 0 (successful).
mattbrictson commented 6 years ago

I'm curious why you added this?

require 'sshkit'
require 'sshkit/dsl'
include SSHKit::DSL

SSHKit is an inherent part of Capistrano and there is no need to require it. Try removing these lines and see what happens.

craibuc commented 6 years ago

Why did I include it? Lack of knowledge.

That worked.

Thanks for the help.

mattbrictson commented 6 years ago

Why did I include it? Lack of knowledge.

I just wanted to make sure there wasn't another problem you discovered that you had solved by requiring SSHKit. Apologies if that came off as passive-aggressive. 😅