2015-03-03 131 views
2

请帮助配置capistrano进行部署。 我有SSH:Capistrano部署配置

  • 用户:用户
  • 主机:8.8.8.8:6554
  • 通:123

然后,我已经到位桶库[email protected]:somerepo /代码git的

我只需要将代码从默认分支部署到[email protected]:8888:/ public_html/test /。在本地机器上我有ssh密钥,允许我无需密码连接。但卡皮斯特拉诺没有连接。

有我的配​​置:

lock '3.3.5' 
set :application, 'App' 
set :scm, :git 
set :repo_url, '[email protected]:somerepo/code.git' 
set :scm_passphrase, "" 
set :scm_user, "[email protected]" 
set :user, 'User' 
set :deploy_to, '/public_html/test' 
set :app_dir, "/public_html/test" 
set :ssh_options, {:forward_agent => true} 
role :web, '8.8.8.8:6554' 

namespace :deploy do 
    after :restart, :clear_cache do 
    on roles(:web), in: :groups, limit: 3, wait: 10 do 
    end 
    end 
end 

错误:

connection closed by remote host ** Invoke deploy:failed (first_time) ** Execute deploy:failed

+1

请帮助别人。我今天需要部署这个。 – 2015-03-03 08:09:26

回答

1

步骤1:中的Gemfile

gem 'capistrano' 
gem 'capistrano-bundler' 
gem 'capistrano-rails' 

步骤2:

第3步:cap install ##就会生成设定文件的

第4步:Capfile并粘贴以下代码##该文件将平行于Rails应用程序

require 'capistrano/setup' 
require 'capistrano/deploy' 
require 'capistrano/bundler' 
require 'capistrano/rails/assets' 
require 'capistrano/rails/migrations' 
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } 

步骤5:配置/ deploy.rb,这将是通用于ENV

该文件将被共享/通用跨应用环境

set :application, 'your_app' ## keep in mind that your app dir name will be your_app 
    set :repo_url, '[email protected]:somerepo/code.git' 
    set :branch, 'master' 
    set :use_sudo, true 
    set :deploy_to, '/public_html/test' 
    set :linked_files, fetch(:linked_files, []).push('config/database.yml') 
    set :linked_dirs, fetch(:linked_dirs, []).push('bin', 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system') 
namespace :deploy do 

    after :restart, :clear_cache do 
    on roles(:web), in: :groups, limit: 3, wait: 10 do 
     # Here we can do anything such as: 
     # within release_path do 
     # execute :rake, 'cache:clear' 
     # end 
    end 
    end 

end 

第六步:我们创建ENV特定的文件,现在对于生产环境

config/deploy/production.rb ##这个文件将被生成cap install这个时候你以前没有必要的命令

请注意除此以外的所有代码

role :app, %w{8.8.8.8:6554} 
set :ssh_options, { 
       user: 'User' 
      } 

步骤6:现在做ssh to your serverssh [email protected]:6554 现在它会要求输入密码...give password

第7步:现在默认的程序将会/var/www/app,在这里你需要相应地,但在你的情况下创建的文件夹,你set :deploy_to, '/public_html/test'#确保目录名称后跟/“正斜杠”这个错误我做了很多次

sudo mkdir -p /public_html 
sudo mkdir -p /public_html/test 
sudo chown User:User /public_html/test # `chown` will change the owner ship so that `User` user can `**Read/Write**` 
umask 0002 
mkdir /public_html/test/releases ## these are convention 
mkdir /public_html/test/shared ## these are convention 
sudo chown User:User public_html/test/releases 
sudo chown User:User public_html/test/shared 
mkdir .ssh 
chmod .ssh 007 
ssh-keygen -t rsa 
and follow the step ## this will generate ssh key 
cat .ssh/id_rsa.pub 

现在加上这关键看你的回购的进入=>设置=>部署键按钮=>点击那个和添加Key。把标签命名为任何你想要的东西,并粘贴ssh key在这里。

那它服务器

第八步:现在,您需要将您的SSH密钥添加到服务器 对于做cat ~/.ssh/id_rsa.pub如果你有rsa键其他明智的产生RSA密钥是很容易到箱子

步骤9:登录到服务器使用ssh

`vi .ssh/authorized_keys` and paste your local machine rsa key 

保存并退出

步骤10:cap -T ##列出所有任务

步骤11:cap production deploy:check

因为database.yml文件,是不是会引发错误there

对于那vi /public_html/test/shared/config/database.yml

development: 
    adapter: postgresql 
    database: testdb_cap 
    pool: 5 
    timeout: 5000 

保存并退出

再做cap production deploy:check

这一次也不会引发任何错误

步骤12:

cap production deploy 

,这就是它

请检查这个ruby rake task after deploymewnt

+0

这没有用。 SSHKit ::命令::失败:git退出状态:127 – 2015-03-05 09:40:06

+0

@МаксимВладимирович:你的问题解决了吗?因为我有一些问题但无法解决:P – VKatz 2016-03-30 07:35:16

+0

不,这对我没有帮助。 – 2016-04-01 08:40:45