【问题标题】:capistrano 3.5 use git https repocapistrano 3.5 使用 git https repo
【发布时间】:2016-06-26 11:08:38
【问题描述】:

我有一台服务器,我想通过 capistrano 部署我的源代码。 我可以通过此服务器上的 ssh 访问部署用户,但我从中提取的存储库实际上只能通过 https 访问。 我正在使用 capistrano 3.5 和

帽子分期医生

在变量中显示以下内容。可能不止标准上限,但我认为他们的所作所为是显而易见的。

变量

:application                 "capistrano_deployment"
:branch                      "master"
:default_env                 {}
:deploy_prefix               ""
:deploy_root                 "/var/www"
:deploy_to                   "/var/www/capistrano_deployment"
:format                      :airbrussh
:git_environmental_variables {:git_askpass=>"/bin/echo", :git_ssh=>"/tmp/capistrano_deployment/git-ssh.sh"}
:keep_releases               5
:local_user                  "myuser"
:log_level                   :debug
:pty                         true
:repo_url                    "https://myuser@git.internal.net/git/capistrano_deployment.git"
:scm                         :git
:stage                       :staging
:target_directory            "capistrano_deployment"
:tmp_dir                     "/tmp"

我遇到的问题是部署失败,因为 capistrano 没有要求我输入 git 这个存储库的密码,该存储库由 https 和 not 访问,因为 capistrano 似乎通过 ssh 假设。

 INFO [ce69c094] Running /usr/bin/env git ls-remote --heads https://myuser@git.internal.net/git/capistrano_deployment.git as deploy@…
DEBUG [ce69c094] Command: ( export GIT_ASKPASS="/bin/echo" GIT_SSH="/tmp/capistrano_deployment/git-ssh.sh" ; /usr/bin/env git ls-remo…
DEBUG [ce69c094]       fatal: Authentication failed for 'https://myuser@git.internal.net/git/capistrano_deployment.git/'

我需要更改 capistrano 要求输入 https url 的密码 - 希望只有一次,而不是每个由 capistrano 执行的 git 查询? 似乎也有解决方案以明文形式在 .netrc 中部署用户名和密码(不是选项!)。想不惜一切代价避免这样的解决方案

【问题讨论】:

    标签: git http authentication https capistrano


    【解决方案1】:

    您可以像这样通过 Capistrano 提供密码:

    set :git_http_password, "secret"
    

    或者像这样提示 Capistrano 用户:

    ask :git_http_password
    

    不幸的是,这一切实际上只是将密码以明文形式放在存储库 URL 中。这意味着它将在日志中以及可能在其他地方得到回显。

    来源:https://github.com/capistrano/capistrano/blob/4406674cd324a714c14a52554300aa721fb2b2b7/lib/capistrano/dsl/paths.rb#L38-L53

    可能不是您想要的,但如果您想使用 HTTPS,我相信这是您唯一可用的选项。

    【讨论】:

      【解决方案2】:

      即使代码仍在 Capistrano 中,我也无法得到 Matt 的答案。但我没有试图弄清楚,而是让 Capistrano 自己询问用户名和密码。将此添加到 config/deploy.rb:

      ask(:github_user_name, nil)
      ask(:github_password, nil)
      
      set :repo_url, "https://#{fetch(:github_user_name)}:#{fetch(:github_password)}@github.com/github-account-name/my-repo.git"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-17
        • 1970-01-01
        • 2014-12-26
        • 1970-01-01
        • 1970-01-01
        • 2019-12-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多