Ever needed to deploy with fabric on multiple machines?
Here’s a simple solution to aproach this issue.
In your fabfile.py , add these two methods:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
def live(): global PATH, ENV_PATH env.hosts = ["22.2.222.2"] env.user = 'test' PATH = '/path/to/project' # optional, is using virtualenv ENV_PATH = '/path/to/virtualenv' # overwrite whatever variabled you need to change on the current machine def staging(): global PATH, ENV_PATH env.hosts = ["11.1.11.1"] env.user = 'test2' PATH = '/path/to/project/on/second/machine' # optional, is using virtualenv ENV_PATH = '/path/to/virtualenv' # overwrite whatever variabled you need to change on the current machine |
Now, when deploying, for example:
1 2 3 4 5 6 |
def deploy(): with cd(PATH), virtualenv(ENV_PATH): run('uber command') run('another uber command') |
you must use the following commands, in the correct order:
1 2 3 4 5 6 7 |
#deploy on staging fab staging deploy # deploy on live fab live deploy |
Fabric runs the “staging” or “deploy” commands first, setting the envrinoment variables, and then it runs the “deploy” command doing whatever you asked it to do.