pyinvoke / invoke

Pythonic task management & command execution.
http://pyinvoke.org
BSD 2-Clause "Simplified" License
4.39k stars 367 forks source link

Advice on task execution in a container host / guest scenario #822

Open iongion opened 3 years ago

iongion commented 3 years ago

Trying to create a decorator

@container
@task(pre=[validate])
def query(c, query):
    mysql_execute(c, query)

The container decorator will check an environment variable, CONTAINER=yes|no, if that is set on 'yes', then it will execute the same step inside the container, not in the host.

def container(fn):
    if in_container():
        return fn()
    else:
        print('Detect what task it coresponds to and execute in container')
        coresponding_task = 'HOW TO I GET IT ?'
        os.system(f'docker exec -i -t "mycontainer" /bin/bash -i -l "inv {coresponding_task}"')

But now how do I know what task the function corresponds to ?

Is this even the proper way ?

paradox-lab commented 2 years ago
coresponding_task = fn.__name__