5

我正在尝试使用 mina 将我的应用程序部署到数字海洋服务器并在 bitbucket 上有一个 git repo。我能够运行mina setup' just fine, but when I runmina deploy` 我得到一个错误。

我的部署.rb

require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv'  # for rbenv support. (http://rbenv.org)
# require 'mina/rvm'    # for rvm support. (http://rvm.io)

# Basic settings:
#   domain       - The hostname to SSH to.
#   deploy_to    - Path to deploy into.
#   repository   - Git repo to clone from. (needed by mina/git)
#   branch       - Branch name to deploy. (needed by mina/git)

set :rails_env, 'production' 
set :domain, 'my.server'
set :deploy_to, '/home/deployer/mysite'
set :repository, 'git@bitbucket.org:me/myproject.git'
set :branch, 'master'
set :user, 'deployer'
set :forward_agent, true
set :port, '22'


# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
# They will be linked in the 'deploy:link_shared_paths' step.
set :shared_paths, ['config/database.yml', 'log', 'config/secrets.yml']

# Optional settings:
#   set :user, 'foobar'    # Username in the server to SSH to.
#   set :port, '30000'     # SSH port number.

# This task is the environment that is loaded for most commands, such as
# `mina deploy` or `mina rake`.
task :environment do
  # If you're using rbenv, use this to load the rbenv environment.
  # Be sure to commit your .rbenv-version to your repository.
  queue %{
    echo "-----> Loading environment"  
    #{echo_cmd %[source ~/.bashrc]}
  }
  invoke :'rbenv:load'

  # For those using RVM, use this to load an RVM version@gemset.
  # invoke :'rvm:use[ruby-1.9.3-p125@default]'
end

# Put any custom mkdir's in here for when `mina setup` is ran.
# For Rails apps, we'll make some of the shared paths that are shared between
# all releases.
task :setup => :environment do
  queue! %[mkdir -p "#{deploy_to}/shared/log"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]

  queue! %[mkdir -p "#{deploy_to}/shared/config"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]

  queue! %[touch "#{deploy_to}/shared/config/database.yml"]
  queue  %[echo "-----> Be sure to edit 'shared/config/database.yml'."]

  queue! %[touch "#{deploy_to}/shared/config/secrets.yml"]
  queue %[echo "-----> Be sure to edit 'shared/config/secrets.yml'."]
end

desc "Deploys the current version to the server."
task :deploy => :environment do
  deploy do
    # Put things that will set up an empty directory into a fully set-up
    # instance of your project.
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'

    to :launch do
      invoke :'passenger:restart'
    end
  end
end

desc "Restarts the nginx server."  
task :restart do  
  invoke :'passenger:restart'
end

namespace :passenger do  
  task :restart do
    queue "mkdir #{deploy_to}/current/tmp; touch #{deploy_to}/current/tmp/restart.txt"
  end
end  

# For help in making your deploy script, see the Mina documentation:
#
#  - http://nadarei.co/mina
#  - http://nadarei.co/mina/tasks
#  - http://nadarei.co/mina/settings
#  - http://nadarei.co/mina/helpers

当我执行“mina deploy”时,出现此错误

-----> Loading environment        
-----> Loading rbenv        
-----> Creating a temporary build path        
-----> Cloning the Git repository        
       Cloning into bare repository '/home/deployer/mysite/scm'...
       Host key verification failed.
       fatal: Could not read from remote repository.

       Please make sure you have the correct access rights
       and the repository exists.
 !     ERROR: Deploy failed.   
-----> Cleaning up build        
       Unlinking current 
       OK 

 !     Command failed.
       Failed with status 19

我在 bitbucket 上设置了 ssh 密钥,我可以从我的计算机上很好地将我的 repo 推送到它,我还在 bitbucket 上设置了我的服务器的 ssh 密钥(不确定是否需要,但我想我会尝试它)。有什么问题?

4

3 回答 3

4

将此添加到您的 deploy.rb 文件中

set :term_mode, nil

确保您在 github 上添加了服务器 SSH 公钥

于 2015-03-05T12:22:07.330 回答
1

您可以为此使用本地 ssh 密钥。

使用 SSH 的-A 设置。并像这样在 mina 中设置它set :port, '22 -A'会将 -A 附加到 Mina 发出的 ssh 命令中。

基本上,它会转发您在部署服务器上使用的身份验证。(就像set :forward_agent, true在 Capistrano 中所做的那样)


然而,我认为最佳实践是在服务器上生成一个 ssh 密钥并将其设置为托管 SCM 解决方案中的部署密钥。

于 2014-10-15T16:20:38.700 回答
-3

Your server tries to git from git@bitbucket.org:me/myproject.git, but there is host key at your server.
You can copy your id_rsa.pub and known_hosts file through scp command on server and then run it again. It will work.

于 2014-09-17T08:06:40.153 回答