【问题标题】:Fabric 2 automating deployment error when git pulling on remote server. Repository not foundFabric 2 在 git pull 远程服务器时自动部署错误。未找到存储库
【发布时间】:2020-01-23 18:45:31
【问题描述】:

我正在尝试使用 Fabric 2 自动化我的部署。

当我通过远程服务器上的命令行手动执行 git pull 时,一切正常。

当我尝试对我的 Fabric/Invoke 脚本执行相同操作时,它不允许我拉动。

虽然它允许我执行 git status 和其他命令。

代码:

# Imports
from fabric import Connection
from fabric.tasks import task
import os

# Here i pass my local passphrase:
kwargs = {'passphrase': os.environ["SSH_PASSPHRASE"]}

@task
def serverdeploy(c, branch="Staging"):
    con = Connection('myuser@myhost', connect_kwargs=kwargs)
    with con.cd("/home/user/repository/"):
        # Activate the virtual environment:
        with con.prefix("source ENV/bin/activate"):
            con.run("git pull origin {}".format(branch))

结果是:

git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

注意事项:

在进行拉取操作时,我什至没有被要求输入密码。

我尝试过在不激活环境的情况下进行拉取,但这也不起作用。


可能是什么问题?

【问题讨论】:

    标签: python git paramiko fabric invoke-command


    【解决方案1】:

    请将con.run("git pull origin {}".format(branch))放在with con.prefix("source ENV/bin/activate"):之外。

    您的代码与解释器或虚拟环境无关!试试看,它应该可以工作!

    【讨论】:

    • 谢谢,这是第一步。第二步是在 git 命令上添加 pty=True
    【解决方案2】:

    最可能的问题是您登录的用户具有正确的 bitbucket.org 的 ssh 密钥设置,但结构连接用户不同。您可以作为fabric连接的用户使用这两个命令来测试设置是否正确:

    ssh -T git@bitbucket.org
    ssh -T -i /path/to/private_key git@bitbucket.org
    

    为了解决这个问题,请将私钥复制到/home/myuser/.ssh 目录并将bitbucket.org 的ssh 配置条目添加到/home/myuser/.ssh/config

    Host bitbucket.org
      IdentityFile /path/to/private_key
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-29
      • 1970-01-01
      • 2018-08-13
      • 1970-01-01
      相关资源
      最近更新 更多