如何在ROR部署中为git + capistrano 3配置远程引用?

 齐鲁墨_931 发布于 2023-02-12 16:13

我正在尝试使用capistrano(第一次)部署我的rails应用程序.首先要点,我正在使用:

红宝石1.9.3p362

Rails 3.2.13

rvm 1.24.7

Capistrano 3.0.1

Phusion Passenger 4.0.26

Ubuntu 12.04 LTS

尝试运行时出现以下错误 cap production deploy

DEBUG [679a47be]致命:没有远程配置列出引用.

我的完整cap production deploy输出包括在下面

   INFO [488ba755] Running /usr/bin/env mkdir -p /tmp/AppName/ on sub.example.com
    DEBUG [488ba755] Command: /usr/bin/env mkdir -p /tmp/AppName/
     INFO [488ba755] Finished in 1.730 seconds with exit status 0 (successful).
    DEBUG Uploading /tmp/AppName/git-ssh.sh 0.0%
     INFO Uploading /tmp/AppName/git-ssh.sh 100.0%
     INFO [c895f068] Running /usr/bin/env chmod +x /tmp/AppName/git-ssh.sh on sub.example.com
    DEBUG [c895f068] Command: /usr/bin/env chmod +x /tmp/AppName/git-ssh.sh
     INFO [c895f068] Finished in 0.217 seconds with exit status 0 (successful).
    DEBUG [679a47be] Running /usr/bin/env git ls-remote  on sub.example.com
    DEBUG [679a47be] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/AppName/git-ssh.sh /usr/bin/env git ls-remote  )
    DEBUG [679a47be]  fatal: No remote configured to list refs from.
    DEBUG [679a47be] Finished in 1.775 seconds with exit status 128 (failed).

的Gemfile

# Deploy with Capistrano
gem 'capistrano',  '~> 3.0.0'
gem 'capistrano-rails', '~> 1.1.0'
gem 'rvm1-capistrano3', require: false

Capfile

# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'

# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

deploy.rb

我已经改变了这个文件来添加我的git url,应用程序名称,deploy_to路径以及内部任务task :restart,以便重启Phusion Passenger.

set :application, 'AppName'
set :deploy_to, '/var/www/appname'

set :repository, "git@github.com:username/appname.git"  # Your clone URL
set :scm, "git"
set :user, "my-github-deploy-user"  # The server's user for deploys
set :scm_passphrase, "correct-password"  # The deploy user's password
set :branch, "master"
set :deploy_via, :remote_cache

# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }

set :ssh_options, {
   verbose: :debug
}

set :format, :pretty
set :log_level, :debug
# set :pty, true

set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# set :keep_releases, 5

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      execute :touch, release_path.join('tmp/restart.txt')
      # task :start do ; end
      # task :stop do ; end
      # task :restart, :roles => :app, :except => { :no_release => true } do
      #   run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
      # end
    end
  end

  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
  after :finishing, 'deploy:cleanup'
end

我试图包含所有必要的信息,请告诉我是否还有其他任何我可以添加的内容,感谢您提供的任何帮助!

1 个回答
  • 在Capistrano 3中,您使用repo_url而不是repository

    所以在你的deploy.rb尝试更换

    set :repository, "git@github.com:username/appname.git"  # Your clone URL
    

    set :repo_url, "https://github.com/username/appname.git"  # Your clone URL
    

    希望这会有所帮助.

    更新:ssh URL需要一个密钥; https网址没有.它对我有用.

    2023-02-12 16:15 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有