我正在使用Capistrano将Sinatra应用程序部署到托管公司(https://railsplayground.com/)。
托管公司支持3个版本的Ruby:
$ ruby -v
ruby 2.0.0p645 (2015-04-13 revision 50299) [x86_64-linux]
$ /usr/local/bin/ruby224 -v
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]
$ /usr/local/bin/ruby233 -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
作为Sinatra 2.0.3 requires Ruby >=2.2.0,我决定使用Ruby 2.3.3。托管公司已创建了相关的可执行文件:
$ /usr/local/bin/ruby233 /usr/local/bin/gem233 -v
2.5.2
$ /usr/local/bin/ruby233 /usr/local/bin/bundle233 -v
Bundler version 1.14.4
为了测试Gem的安装过程,我创建了一个带有Gemfile的文件夹:
$ cat Gemfile
source 'http://rubygems.org'
gem 'sinatra'
我运行了捆绑程序($ /usr/local/bin/ruby233 /usr/local/bin/bundle233 install --path=vendor/bundle
),并将gems安装在应用程序的vendor/bundle
目录中:
$ ll vendor/bundle/ruby/2.3.0/gems/
total 28
drwxrwxr-x 7 foobar foobar 4096 Sep 10 06:35 ./
drwxrwxr-x 9 foobar foobar 4096 Sep 10 06:35 ../
drwxrwxr-x 5 foobar foobar 4096 Sep 10 06:35 mustermann-1.0.3/
drwxrwxr-x 7 foobar foobar 4096 Sep 10 06:35 rack-2.0.5/
drwxrwxr-x 3 foobar foobar 4096 Sep 10 06:35 rack-protection-2.0.3/
drwxrwxr-x 4 foobar foobar 4096 Sep 10 06:35 sinatra-2.0.3/
drwxrwxr-x 7 foobar foobar 4096 Sep 10 06:35 tilt-2.0.8/
接下来,我创建了一个简单的Sinatra应用程序,并尝试对其进行部署。
Gemfile
:
source "http://rubygems.org"
gem "sinatra"
group :development do
# deployment
gem 'capistrano'
gem 'capistrano-bundler'
gem 'capistrano-passenger'
end
config.ru
:
require 'bundler'
Bundler.setup
# desired
#/usr/local/bin/ruby233 /usr/local/bin/bundle233 install --path=vendor/bundle
require File.join(File.dirname(__FILE__), 'app')
run Sinatra::Application
deploy.rb
:
set :git_user, 'foobar'
set :application, "cap"
set :repo_url, "git@bitbucket.org:#{fetch(:git_user)}/#{fetch(:application)}.git"
set :branch, 'master'
set :passenger_restart_with_touch, true
staging.rb
:
set :stage, :staging
set :ssh_user, 'foobarbaz'
set :use_sudo, false
server "supersonic.webhostserver.biz", user: fetch(:ssh_user), roles: %w{app, web, db}
set :tmp_dir, "/home/#{fetch(:ssh_user)}/tmp"
set :deploy_to, "/home/#{fetch(:ssh_user)}/apps/#{fetch(:application)}"
我运行了临时部署(从工作站):
$ bundle exec cap staging deploy
当脚本尝试安装Gems时,它将失败:
00:14 bundler:install
01 bundle install --path /home/foobarbaz/apps/cap/shared/bundle --without development test --deployment --quiet
01 stdin: is not a tty
01 An error occurred while installing mustermann (1.0.3), and Bundler cannot
01 continue.
01 Make sure that `gem install mustermann -v '1.0.3'` succeeds before bundling.
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as foobarbaz@supersonic.webhostserver.biz: bundle exit status: 5
bundle stdout: An error occurred while installing mustermann (1.0.3), and Bundler cannot
continue.
Make sure that `gem install mustermann -v '1.0.3'` succeeds before bundling.
bundle stderr: stdin: is not a tty
它失败是因为mustermann
需要Ruby> = 2.2.0,但是脚本试图使用Ruby 2.0(默认设置)来安装Gem。
如何获取capistrano(工作站上的3.11.0版)以在服务器上使用所需版本的捆绑器(bundle233)?