Capistrano部署配置

Capistrano部署配置

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

问题描述

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


  • 用户:用户

  • 主机:8.8.8.8: 6554

  • 传递:123



然后我有bitbucket存储库[email protected]:somerepo /code.git





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

   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步:

 产量部署

这就是它

检查这也


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 [email protected]:somerepo/code.git

I am just need to deploy code from default branch to [email protected]: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, '[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

Error:

解决方案

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, '[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

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 [email protected]:6554now 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 serverFor 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部署配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 12:17