rita
rita

Reputation: 545

Run local commands with Fabric

My environments are based on windows with vagrant or docker as the actual environments. I'd like to set up a quick way of ad hoc deploying stuff directly from windows though, it would be great if I could just run

fab deploySomething

And that would for example locally build an react app, commit and push to the server. However I'm stuck at the local bit.

My setup is: Windows 10 Fabric 2 Python 3

I've got a fabfile.py set up with a simple test:

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)

But I'm just getting:

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

you can replace 'yarn' with pretty much anything, I can't run a command with local that works fine manually. With debugging on, all i get is:

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

which isn't very helpful...anyone came across this? Any examples of local commands with fabric I can find seem to refer to the old 1.X versions

Upvotes: 0

Views: 1989

Answers (1)

2ps
2ps

Reputation: 15926

To run local commands, run them off of your context and not your connection. n.b., this drops you to the invoke level:

from fabric import task

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

That said, the issue is probably that you need the fully qualified path to yarn since your environment's path hasn't been sourced.

Upvotes: 4

Related Questions