Skip to content

Instantly share code, notes, and snippets.

@ericwilson
Created April 27, 2014 02:04
Show Gist options
  • Save ericwilson/11336001 to your computer and use it in GitHub Desktop.
Save ericwilson/11336001 to your computer and use it in GitHub Desktop.
Fabric deploy task: tags the set of files with the name of the host machine the deploy is going to + a unique time stamp
# Default directory for the installation
code_dir = '/opt/your_deployment'
.
.
.
@task
def tag(branch):
"""
Tags the release
"""
now = datetime.datetime.now()
refspec = ('{0:s}_{1:s}{2:s}'.format(target_host(), now.strftime('%Y.%m.%d.%H.%M.'),
(sudo('git log --since=1.day --oneline | wc -l').strip())))
print('Tagging version {ref:s} in fabfile'.format(**{'ref': refspec}))
sudo('git tag {ref:s} -m "Tagging version {ref:s} in fabfile"'.format(**{'ref': refspec}))
sudo('git push --tags')
fn = '{0:>s}.tag'.format(refspec)
with open(fn, 'a') as f:
f.write('Tagged version deployed: {0:s}{1:s}\n'.format(branch, refspec))
with cd(code_dir):
put(fn, '.', use_sudo=True)
return refspec
@task
def target_host():
"""
display hostname of the target machine
"""
hn = sudo('hostname')
return hn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment