【问题标题】:Run local commands with Fabric使用 Fabric 运行本地命令
【发布时间】:2019-08-18 13:54:51
【问题描述】:

我的环境基于以 vagrant 或 docker 作为实际环境的 windows。不过,我想建立一种直接从 Windows 临时部署东西的快速方法,如果我能运行就好了

fab deploySomething

例如,这将在本地构建一个反应应用程序,提交并推送到服务器。但是我被困在本地位。

我的设置是: 视窗 10 面料2 Python 3

我已经设置了一个 fabfile.py 并进行了简单的测试:

from fabric import Connection, task, Config

@task
def deployApp(context):
    config = Config(overrides={'user': 'XXX', 'connect_kwargs': {'password': 'YYY'}})
    c = Connection('123.123.123.123', config=config)
    # c.local('echo ---------- test from local')             
    with c.cd('../../app/some-app'):
        c.local('dir') #this is correct
        c.local('yarn install', echo=True)

但我只是得到:

'yarn' is not recognized as an internal or external command, operable program or batch file.

您几乎可以用任何东西替换“纱线”,我无法使用本地运行的命令手动运行良好。调试后,我得到的只是:

DEBUG:invoke:Received a possibly-skippable exception: <UnexpectedExit: cmd='cd ../../app/some-app && yarn install' exited=1>

这不是很有帮助...有人遇到过这个吗?我能找到的任何带有 fabric 的本地命令示例似乎都是指旧的 1.X 版本

【问题讨论】:

  • 您尝试连接的服务器的操作系统是什么?为什么要使用这条路径../../app/some-app?我假设当您连接到服务器时,您可以使用绝对路径而不是相对路径!你试过吗?
  • 这个命令指的是windows、mac或者linux vagrant box上的LOCAL实例。命令 c.local('dir') 工作正常,它在 windows 上显示相关输出,它也适用于 mac 或 linux 上的 c.local('ls')。但我无法运行任何其他命令,例如 node --version 或 yarn install 按照示例...

标签: python build local fabric yarnpkg


【解决方案1】:

要运行本地命令,请从您的 context 而非您的连接中运行它们。注意,这会将您降到invoke 级别:

from fabric import task

@task
def hello(context):
    with context.cd('/path/to/local_dir'):
        context.run('ls -la')

也就是说,问题可能是您需要到 yarn 的完全限定路径,因为您的环境路径尚未获取。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-02
    • 2020-04-18
    相关资源
    最近更新 更多