Skip to content

Instantly share code, notes, and snippets.

@mikedory
Last active December 15, 2015 08:08
Show Gist options
  • Select an option

  • Save mikedory/5228140 to your computer and use it in GitHub Desktop.

Select an option

Save mikedory/5228140 to your computer and use it in GitHub Desktop.

Revisions

  1. mikedory revised this gist Mar 23, 2013. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion fabfile.py
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,10 @@ def test():

    # add and commit all local files
    def commit():
    local("git add -p && git commit")
    with settings(warn_only=True):
    commit = local("git add -p && git commit")
    if commit.failed:
    print("Nothing to commit. Moving on.")


    # push up to github
  2. mikedory revised this gist Mar 23, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fabfile.py
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ def commit():

    # push up to github
    def push():
    local("git push")
    local("git push origin master")


    # run all the pre-flight tests
  3. mikedory created this gist Mar 23, 2013.
    45 changes: 45 additions & 0 deletions fabfile.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    # import the fabric requirements
    from __future__ import with_statement
    from fabric.api import *
    from fabric.contrib.console import confirm

    # import local_settings.py
    from local_settings import *

    # run Django's test framework
    def test():
    with settings(warn_only=True):
    result = local('./manage.py test appname', capture=True)
    if result.failed and not confirm("Tests failed! D: Continue anyway?"):
    abort("Aborting!")


    # add and commit all local files
    def commit():
    local("git add -p && git commit")


    # push up to github
    def push():
    local("git push")


    # run all the pre-flight tests
    # this would also be a handy place to pack/minify, if so desired
    def prepare_deploy():
    test()
    commit()
    push()


    # ---------------------

    # deploy to the remote server
    def deploy():
    with settings(warn_only=True):
    if run("test -d %s" % code_dir).failed:
    run("git clone %s %s" % (code_repo, code_dir))
    with cd(code_dir):
    run("git fetch")
    run("git merge origin/master")
    run("supervisorctl restart appname")
    12 changes: 12 additions & 0 deletions local_settings.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    # deploy/fabric needs
    from fabric.api import *

    # remote server configs
    env.user = 'username'
    env.hosts = ['domain.com']
    env.key_filename = '/path/to/.ssh/id_rsa'

    # deploy directory and repo info
    code_dir_root = '/path/to/code/directory'
    code_dir_target = '/path/to/code/directory/target'
    code_repo = '[email protected]:user/REPO.git'