Capistrano部署配置 [英] Capistrano deploy configuration

查看:146
本文介绍了Capistrano部署配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


  • 用户:用户

  • 主机:8.8.8.8: 6554

  • 传递:123



然后我有bitbucket存储库git@bitbucket.org:somerepo /code.git




  • 用户:Repouser@gmail.com

  • 传递:repopass



我只需要将代码从默认分支部署到User@8.8.8.8:8888:/ public_html / test /。在本地机器上我有ssh密钥,允许我无需密码连接。

 > lock'3.3.5'
set:application,'App'
set:scm,:git
set:repo_url,'git@bitbucket.org:somerepo / code.git'
set:scm_passphrase,
set:scm_user,Repouser@gmail.com
set:user,'User'
set:deploy_to,'/ public_html / test'
set:app_dir,/ public_html / test
set:ssh_options,{:forward_agent => true:
角色:web,'8.8.8.8:6554'

命名空间:deploy do
after:restart,:clear_cache do
角色(:web) ,在::groups,limit:3,wait:10 do
end
end
end

错误:


由远程主机关闭连接
**调用deploy:failed(first_time)
**执行部署:失败


解决方案

/ strong> in Gemfile

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

第2步:套餐



第3步: cap install ##它会生成一组文件
$步骤4:进入 Capfile 并粘贴以下代码##该文件将与您的Rails应用程序并行
p>

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

第5步: Config / deploy.rb通用于 ENV

此文件将在应用程序环境中共享/共享

  set:application,'your_app'##请记住,您的应用程序目录名称为your_app 
set:repo_url,'git @ bitbucket .org:somerepo / code.git'
set:branch,'master'
set:use_sudo,true
set:deploy_to,'/ public_html / test'
set:linked_files ('linked','])。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
在角色(:web)上,在::groups,limit:3,wait:10 do
#在这里我们可以做任何事情,例如:
#在releas e_path do
#execute:rake,'cache:clear'
#end
end
end

end
现在可以创建ENV专用文件用于生产环境


$ b

config / deploy / production.rb ##此文件将由 cap install

可以评论除此之外的所有代码

角色:app,%w {8.8.8.8:6554} 
设置:ssh_options,{
用户:'用户'
}

第6步:现在执行 ssh到您的服务器 ssh User@8.8.8.8:6554
现在它会要求密码... 给密码现在,默认情况下,您的应用将转到 / var / www / app code>,在这里您需要相应地创建文件夹。但在您的情况下,您 s et:deploy_to,'/ public_html / test'#确保Dir名字后面跟着/'正斜杠'这个错误,我做过很多次了


 sudo chown用户:User / public_html / test#`chown`会改变船主所以'用户'用户可以'**读/写'
umask 0002
mkdir / public_html / test / releases ##这些是约定
mkdir / public_html / test / shared# #这些是约定
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
并按照步骤##这将生成ssh密钥
cat .ssh / id_rsa.pub

现在将此密钥添加到您的存储库中go => setting =>部署密钥Button =>点击该密钥并添加密钥 即可。将标签名称放入您想要的任何内容,然后在此处粘贴 ssh键



服务器一方

第8步:现在您需要添加ssh如果你有 rsa 键,那么 cat〜/ .ssh / id_rsa.pub 第三步:使用ssh登录到你的服务器

$ b

 `vi .ssh / authorized_keys`并粘贴本地机器rsa密钥

保存并退出



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



第11步: cap production deploy:check

它会抛出错误,因为database.yml文件不存在



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

 开发:
适配器:postgresql
数据库:testdb_cap
池:5
超时:5000

保存并退出



再次 cap production deploy:check $ b 这一次不会引发任何错误

第12步:

 产量部署

这就是它

检查这也部署后的ruby rake任务


Help please to configure capistrano for deployment. I have ssh:

  • user: User
  • host: 8.8.8.8:6554
  • pass: 123

Then i have bitbucket repository git@bitbucket.org:somerepo/code.git

  • user: Repouser@gmail.com
  • pass: repopass

I am just need to deploy code from default branch to User@8.8.8.8:8888:/public_html/test/ . On local machine i have ssh key, that allows me to connect without password. But capistrano didn't connect.

There is my config:

lock '3.3.5'
set :application, 'App'
set :scm, :git
set :repo_url, 'git@bitbucket.org:somerepo/code.git'
set :scm_passphrase, ""
set :scm_user, "Repouser@gmail.com"
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

Error:

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

解决方案

Step 1: in Gemfile

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

Step 2: bundle

Step 3: cap install ## it will generate set of file

Step 4: go in Capfile and paste the following code ## this file will be parallel to your rails application

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 }

Step 5: Config/deploy.rb that will be common to both ENV

This file will be shared/common across the application environment

    set :application, 'your_app'  ## keep in mind that your app dir name will be your_app  
    set :repo_url, 'git@bitbucket.org: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

Step6: Lets create ENV specific file for now For production Environment

config/deploy/production.rb ## this file will be generate by cap install command that you did earlier no need for this time

do comment all the code except this

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

Step 6: now do ssh to your server ssh User@8.8.8.8:6554 now it will ask for the password ... give password

Step 7: now by default your app will go /var/www/app and here you need to create the folder accordingly But in your case as you set :deploy_to, '/public_html/test' # make sure Dir name is followed by / 'Forward slash' this mistake i did many times

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

Now add this key to your repo's go to => setting => deployment keys Button => click on that and add Key. Put the label name any thing you want and paste the ssh key here.

That it from server side

Step8: Now you need to add your ssh key to server For that do cat ~/.ssh/id_rsa.pub if you have rsa key other wise generate rsa key it is very easy to crate

Step 9: Login to your server using ssh

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

save and exit

Step 10 : cap -T ## list out all the task

step 11: cap production deploy:check

It will throw an error because database.yml file is not there

For that vi /public_html/test/shared/config/database.yml

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

save and exit

Do again cap production deploy:check

This time would not throw any error

Step 12:

 cap production deploy

And That's it

Check this also ruby rake task after deploymewnt

这篇关于Capistrano部署配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆