From c7c57a2de91d8a5208880f741c600737be3041ea Mon Sep 17 00:00:00 2001 From: coffeedogs Date: Wed, 15 Aug 2018 11:37:43 +0100 Subject: [PATCH] Added: Fabric task to deploy current project to remote host --- fabfile/__init__.py | 12 ++++++++---- fabfile/tasks.py | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/fabfile/__init__.py b/fabfile/__init__.py index 9aec62bb..d8d6b2e5 100644 --- a/fabfile/__init__.py +++ b/fabfile/__init__.py @@ -17,7 +17,7 @@ For more help on a particular command from fabric.api import env -from fabfile.tasks import code_quality, build_docs, push_docs, clean, test +from fabfile.tasks import build_docs, clean, code_quality, configure, deploy, push_docs, test, start, stop # Without this, `fab -l` would display the whole docstring as preamble @@ -25,11 +25,15 @@ __doc__ = "" # This list defines which tasks are made available to the user __all__ = [ - "code_quality", - "test", "build_docs", - "push_docs", "clean", + "code_quality", + "configure", + "deploy", + "push_docs", + "start", + "stop", + "test", ] # Honour the user's ssh client configuration diff --git a/fabfile/tasks.py b/fabfile/tasks.py index fb05937d..41c0cefa 100644 --- a/fabfile/tasks.py +++ b/fabfile/tasks.py @@ -315,4 +315,46 @@ def clean(): """Clean up files generated by fabric commands.""" with hide('running', 'stdout'): with cd(PROJECT_ROOT): - run(r"find . -name '*.pyc' -exec rm '{}' \;") + with settings(warn_only=True): + run(r"find . -name '*.pyc' -exec rm '{}' \;") + + +@task +def start(path): + """ + Start pybitmessage on the target host + .. todo:: automate this: xpra start :7 && DISPLAY=:7 src/bitmessagemain.py & + """ + with cd(path): + pass + + +@task +def stop(): + """Stop pybitmessage on the target host""" + with settings(warn_only=True): + run('pkill -9 pybitmessage; pkill xpra') + + +@task +def configure(): + """Prepare a host for deployment""" + sudo('apt install -y rsync xpra pyqt4-dev-tools') + + +@task +def deploy(): + """ + Deploy current version to test host. + """ + clean() + stop() + remote_dir = os.path.join(run('pwd'), 'pybitmessage') + rsync_project( + remote_dir=remote_dir, + local_dir=os.path.join(PROJECT_ROOT, ''), + exclude=[ + '.git/', + ] + ) + start(remote_dir)