gpt4 book ai didi

ruby-on-rails - Capistrano 部署配置

转载 作者:行者123 更新时间:2023-12-02 14:03:21 24 4
gpt4 key购买 nike

请帮助配置 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 key ,它允许我在没有密码的情况下连接。但 capistrano 没有连接。

    有我的配置:
    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

    错误:

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

    最佳答案

    第一步:在 Gemfile

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

    第二步:

    第三步: cap install ##它将生成一组文件

    第四步:进去 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 }

    第五步: 共有的配置/deploy.rb环境

    此文件将在应用程序环境中共享/共用
        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

    第六步: 现在让我们为生产环境创建 ENV 特定文件
    config/deploy/production.rb ## 这个文件将由 cap install 生成您之前执行的命令这次不需要

    注释除此之外的所有代码
    role :app, %w{8.8.8.8:6554}
    set :ssh_options, {
    user: 'User'
    }

    第六步:现在做 ssh to your server ssh User@8.8.8.8:6554现在它会要求输入密码... give password
    第七步:现在默认情况下,您的应用程序将转到 /var/www/app在这里你需要相应地创建文件夹但在你的情况下你 set :deploy_to, '/public_html/test' # 确保 Dir 名称后跟/'Forward slash' 这个错误我犯了很多次
    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 添加到您的 repo 的 go to => setting => deployment keys Button => 点击它并 添加 Key .把 标签 命名任何你想要的东西并粘贴 ssh key这里。

    那它来自 服务器

    第八步:现在您需要将 ssh key 添加到服务器
    为此做 cat ~/.ssh/id_rsa.pub如果你有 rsa key 否则生成 rsa key 很容易创建

    第九步:使用 ssh 登录到您的服务器
    `vi .ssh/authorized_keys` and paste your local machine rsa key 

    保存并退出

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

    第 11 步: cap production deploy:check
    它将抛出一个错误,因为 database.yml 文件不存在

    为此 vi /public_html/test/shared/config/database.yml
        development:
    adapter: postgresql
    database: testdb_cap
    pool: 5
    timeout: 5000

    保存退出

    再做一次 cap production deploy:check
    这次不会抛出任何错误

    第十二步:
     cap production deploy

    就是这样

    也检查一下 ruby rake task after deploymewnt

    关于ruby-on-rails - Capistrano 部署配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28825872/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com