使用Capistrano从本地代理后面部署应用程序

时间:2014-01-21 14:46:06

标签: ruby-on-rails-3 deployment proxy capistrano

我正在尝试使用Capistrano在rails应用程序上部署ruby。我的开发机器和服务器都在代理之后。我在远程机器上使用代理时遇到了麻烦(这是涉及代理和Capistrano的大多数问题)。

当Capistrano执行命令run_locally时,它不会保留我的bashrc中设置的任何环境变量。如何在本地运行命令时为Capistrano设置设置?像executing locally: "git ls-remote https://github.com:user/project.git master这样的命令失败了。

deploy.rb

require 'bundler/capistrano'
require "capistrano-rbenv"
load 'deploy/assets'
require 'creds.rb'
set :rbenv_ruby_version, "1.9.3-p484"
set :rbenv_repository, "https://github.com/sstephenson/rbenv.git"

set :application, "visio"



# Deploy from your local Git repo by cloning and uploading a tarball
set :scm, :git
set :repository,  "https://github.user/project.git"
set :deploy_via, :copy
set :branch, "master"
set :rails_env,     "production"


set :user, :deploy
set :deploy_to, "/var/www/#{application}"
set :use_sudo, false

set :ssh_options, { :forward_agent => true }
default_run_options[:pty] = true

role :web, "10.9.43.153"                          # Your HTTP server, Apache/etc
role :app, "10.9.43.153"                          # This may be the same as your `Web` server
role :db,  "10.9.43.153", :primary => true # This is where Rails migrations will run

# ensure http_proxy variables are set
set :default_environment, {
  'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH",
  'BASH_ENV' => '$HOME/.bashrc',
  'https_proxy' => 'https://proxy.org.local:8080',
  'http_proxy' => 'http://proxy.org.local:8080'
}

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
   run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
end

1 个答案:

答案 0 :(得分:2)

试试这个

default_run_options[:env] = {
    'http_proxy' => '192.168.1.10:8080', #Your HTTP proxy server
    'https_proxy' => '192.168.1.10:8080', #Your HTTPS proxy server
    'HTTPS_PROXY_REQUEST_FULLURI' => 'false',
}

它对我有用。

来源:http://architects.dzone.com/articles/using-proxy-capifonycapistrano