Esempio n. 1
0
def cleanup():
  releases = fetch('releases')
  keep_releases = int(fetch('keep_releases'))
  releases_path = fetch('releases_path')
  if keep_releases < len(releases):
    delete_releases = map(lambda release: os.path.join(releases_path, release), releases[0:-keep_releases])
    run('rm -rf %(delete_releases)s' % dict(delete_releases=' '.join(delete_releases)))
Esempio n. 2
0
def setup():
  with settings(warn_only=True):
    dirs = [fetch('deploy_to'), fetch('releases_path'), fetch('shared_path')]
    dirs += map(lambda path: os.path.join(fetch('shared_path'), path), ['log', 'pids', 'system'])
    result = run('mkdir -p %(dirs)s && chmod g+w %(dirs)s' % dict(dirs=' '.join(dirs)))
    if result.failed:
      error('failed to setup.')

  if fetch('virtualenv') is not None:
    invoke('setup_virtualenv')
Esempio n. 3
0
def rollback():
  previous_release = fetch('previous_release')
  if previous_release is None:
    error('no previous releases.')
  run("""
    rm -f %(current_path)s && ln -s %(previous_release)s %(current_path)s
  """ % var('current_path', 'previous_release', 'latest_release'))
  run("""
    if [ `readlink %(current_path)s` != %(current_release)s ]; then rm -rf %(current_release)s; fi
  """ % var('current_path', 'current_release'))
Esempio n. 4
0
def rollback():
  previous_release = fetch('previous_release')
  if previous_release is None:
    error('no previous releases.')
  run("""
    rm -f {current_path} && ln -s {previous_release} {current_path}
  """.format(**var('current_path', 'previous_release', 'latest_release')))
  run("""
    if [ `readlink {current_path}` != {current_release} ]; then rm -rf {current_release}; fi
  """.format(**var('current_path', 'current_release')))
Esempio n. 5
0
def setup_pybundle():
  with settings(warn_only=True):
    requirement = 'packages.txt'
    result = local("""
      if test -f {requirement}; then pip install --requirement={requirement}; else pip freeze --local > {requirement}; fi &&
      pip bundle --requirement={requirement} {application}.pybundle
    """.format(**var('application', requirement=requirement)))
    if result.failed:
      error('failed to create pybundle.')

    result = put('{application}.pybundle'.format(**var('application')), fetch('pybundle_path'))
    if result.failed:
      error('failed to upload pybundle.')
Esempio n. 6
0
def finalize_update():
  with settings(warn_only=True):
    result = run("""
      rm -rf %(latest_release)s/log %(latest_release)s/public/system %(latest_release)s/tmp/pids &&
      mkdir -p %(latest_release)s/public &&
      mkdir -p %(latest_release)s/tmp &&
      ln -s %(shared_path)s/log %(latest_release)s/log &&
      ln -s %(shared_path)s/system %(latest_release)s/public/system &&
      ln -s %(shared_path)s/pids %(latest_release)s/tmp/pids
    """ % var('latest_release', 'shared_path'))
    if result.failed:
      alert('failed to finalize update. try to delete temporal files.')
      run('rm -rf %(latest_release)s; true' % var('latest_release'))
      error('failed to finalize update.')

    if fetch('group_writable'):
      run('chmod -R g+w %(latest_release)s' % var('latest_release'))
Esempio n. 7
0
def finalize_update():
  with settings(warn_only=True):
    result = run("""
      rm -rf {latest_release}/log {latest_release}/public/system {latest_release}/tmp/pids &&
      mkdir -p {latest_release}/public &&
      mkdir -p {latest_release}/tmp &&
      ln -s {shared_path}/log {latest_release}/log &&
      ln -s {shared_path}/system {latest_release}/public/system &&
      ln -s {shared_path}/pids {latest_release}/tmp/pids
    """.format(**var('latest_release', 'shared_path')))
    if result.failed:
      alert('failed to finalize update. try to delete temporal files.')
      run('rm -rf {latest_release}; true'.format(**var('latest_release')))
      error('failed to finalize update.')

    if fetch('group_writable'):
      run('chmod -R g+w {latest_release}'.format(**var('latest_release')))
Esempio n. 8
0
def fetch(key, default_val=None):
  import options
  return options.fetch(key, default_val)
Esempio n. 9
0
def upload_pybundle():
  with settings(warn_only=True):
    result = put('%(application)s.pybundle' % var('application'), fetch('pybundle_path'))
    if result.failed:
      error('failed to upload pybundle.')
Esempio n. 10
0
def var(*keys, **kwargs):
  for key in keys:
    kwargs[key] = fetch(key)
  return kwargs
Esempio n. 11
0
def update_code():
  try:
    fetch('strategy').deploy()
  except Exception, e:
    run('rm -rf %(latest_release)s; true' % var('latest_release'))
    error('failed to update code. (%(reason)s)' % dict(reason=str(e)))
Esempio n. 12
0
def update_code():
  try:
    fetch('strategy').deploy()
  except Exception, e:
    run('rm -rf {latest_release}; true'.format(**var('latest_release')))
    error('failed to update code. ({reason})'.format(reason=str(e)))