Capistrano deploy configuration

♀尐吖头ヾ 提交于 2019-12-11 02:17:02

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/28825872/capistrano-deploy-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!