Esempio n. 1
0
def putFile(fileName):
  configuration.check()
  if configuration.current()['runLocally']:
    log.error("putFile not supported when 'runLocally' is set!")
    exit(1)

  methods.call('files', 'put', configuration.current(), filename=fileName)
Esempio n. 2
0
def copyDBFrom(source_config_name):
    configuration.check()
    source_configuration = configuration.get(source_config_name)
    methods.runTask(configuration.current(),
                    'copyDBFrom',
                    source_config=source_configuration,
                    nextTasks=['reset'])
Esempio n. 3
0
def putFile(fileName):
  configuration.check()
  if configuration.current()['runLocally']:
    print red("putFile not supported when 'runLocally' is set!")
    exit(1)

  methods.call('files', 'put', configuration.current(), filename=fileName)
Esempio n. 4
0
def docker(command=False, **kwargs):
    configuration.check()
    methods.call('docker',
                 'runCommand',
                 configuration.current(),
                 command=command,
                 **kwargs)
Esempio n. 5
0
def createApp(**kwargs):
  configuration.check(['docker'])
  stages = [
    {
      'stage': 'checkExistingInstallation',
      'connection': 'docker',
      'context': {
        'installationExists': False
        }
    }
  ]
  createDestroyHelper(stages, 'createApp')
  if stages[0]['context']['installationExists']:
    print green('Found an existing installaion, running deploy instead!')
    deploy()
    return

  # Install the app.
  stages = configuration.getSettings('createAppStages', [
    { 'stage': 'installCode','connection': 'docker' },
    { 'stage': 'installDependencies','connection': 'docker' },
    { 'stage': 'spinUp','connection': 'docker' },
    { 'stage': 'install','connection': 'ssh' },
  ])

  createDestroyHelper(stages, 'createApp', **kwargs)

  if 'copyFrom' in kwargs:
   copyFrom(kwargs['copyFrom'])
Esempio n. 6
0
def getBackup(commit):
  configuration.check()
  files = get_backup_files(commit)
  for file in files:
    remotePath = configuration.current('backupFolder') + "/" + file['file']
    localPath = './' + file['file']

    get(remote_path=remotePath, local_path=localPath)
Esempio n. 7
0
def updateApp(**kwargs):
  configuration.check()
  config = configuration.current()
  if config['type'] != 'dev':
    print red('Task updateApp is not supported for this configuration. Please check if "type" is set correctly.')
    exit(1)
  backupDB()
  methods.runTask(configuration.current(), 'updateApp', **kwargs)
Esempio n. 8
0
def getBackup(commit):
    configuration.check()
    files = get_backup_files(commit)
    for file in files:
        remotePath = configuration.current("backupFolder") + "/" + file["file"]
        localPath = "./" + file["file"]

        get(remote_path=remotePath, local_path=localPath)
Esempio n. 9
0
def updateApp(**kwargs):
  configuration.check()
  config = configuration.current()
  if config['type'] != 'dev':
    log.error('Task updateApp is not supported for this configuration. Please check if "type" is set correctly.')
    exit(1)
  backupDB()
  methods.runTask(configuration.current(), 'updateApp', **kwargs)
Esempio n. 10
0
def getBackup(commit):
  configuration.check()
  files = get_backup_files(commit)
  for file in files:
    remotePath = configuration.current('backupFolder') + "/" + file['file']
    localPath = './' + file['file']

    get(remote_path=remotePath, local_path=localPath)
Esempio n. 11
0
def install(**kwargs):
  configuration.check()
  config = configuration.current()
  if config['type'] == 'prod' or not config['supportsInstalls']:
    print red('Task install is not supported for this configuration. Please check if "type" and "supportsInstalls" is set correctly.')
    exit(1)

  methods.runTask(configuration.current(), 'install', nextTasks=['reset'], **kwargs)
Esempio n. 12
0
def updateApp(**kwargs):
    configuration.check()
    config = configuration.current()
    if config["type"] != "dev":
        print red('Task updateApp is not supported for this configuration. Please check if "type" is set correctly.')
        exit(1)
    backupDB()
    methods.runTask(configuration.current(), "updateApp", **kwargs)
Esempio n. 13
0
def getFile(remotePath, localPath='./'):
    configuration.check()

    methods.call('files',
                 'get',
                 configuration.current(),
                 remotePath=remotePath,
                 localPath=localPath)
Esempio n. 14
0
def restore(commit, cleanupBeforeRestore=0):
    configuration.check()
    files = get_backup_files(commit)
    methods.runTask(configuration.current(),
                    'restore',
                    files=files,
                    cleanupBeforeRestore=cleanupBeforeRestore)

    reset()
Esempio n. 15
0
def destroyApp(**kwargs):
  configuration.check(['docker'])
  stages = configuration.getSettings('destroyAppStages', [
    { 'stage': 'spinDown','connection': 'docker' },
    { 'stage': 'deleteContainer','connection': 'docker' },
    { 'stage': 'deleteCode','connection': 'docker' },
  ])

  createDestroyHelper(stages, 'destroyApp', **kwargs)
Esempio n. 16
0
def destroyApp(**kwargs):
  configuration.check(['docker'])
  stages = configuration.getSettings('destroyAppStages', [
    { 'stage': 'spinDown','connection': 'docker' },
    { 'stage': 'deleteContainer','connection': 'docker' },
    { 'stage': 'deleteCode','connection': 'docker' },
  ])

  createDestroyHelper(stages, 'destroyApp', **kwargs)
Esempio n. 17
0
def createApp(**kwargs):
    configuration.check(['docker'])
    if not configuration.getSettings('repository'):
        log.error('Missing repository in fabfile, can\'t continue')
        exit(1)

    log.info('Create app from source at %s' %
             configuration.getSettings('repository'))
    stages = [{
        'stage': 'checkExistingInstallation',
        'connection': 'docker',
        'context': {
            'installationExists': False
        }
    }]
    createDestroyHelper(stages, 'createApp')
    if stages[0]['context']['installationExists']:
        log.info('Found an existing installation, running deploy instead!')

        # Spin up the container.
        stages = [
            {
                'stage': 'spinUp',
                'connection': 'docker'
            },
        ]
        createDestroyHelper(stages, 'createApp', **kwargs)

        deploy()
        return

    # Install the app.
    stages = configuration.getSettings('createAppStages', [
        {
            'stage': 'installCode',
            'connection': 'docker'
        },
        {
            'stage': 'spinUp',
            'connection': 'docker'
        },
        {
            'stage': 'installDependencies',
            'connection': 'ssh'
        },
        {
            'stage': 'install',
            'connection': 'ssh',
            'withReset': 'copyFrom' not in kwargs
        },
    ])

    createDestroyHelper(stages, 'createApp', **kwargs)

    if 'copyFrom' in kwargs:
        copyFrom(kwargs['copyFrom'])
Esempio n. 18
0
def backup(withFiles = True):
  configuration.check()
  log.info('backing up files and database of "%s" @ "%s"' % (configuration.getSettings('name'), configuration.current('config_name')))
  i = datetime.datetime.now()
  basename = [
    configuration.current('config_name'),
    i.strftime('%Y-%m-%d--%H-%M-%S')
  ]

  methods.runTask(configuration.current(), 'backup', withFiles = withFiles, baseName = basename)
Esempio n. 19
0
def backup(withFiles=True):
    configuration.check()
    print green(
        'backing up files and database of "%s" @ "%s"'
        % (configuration.getSettings("name"), configuration.current("config_name"))
    )
    i = datetime.datetime.now()
    basename = [configuration.current("config_name"), i.strftime("%Y-%m-%d--%H-%M-%S")]

    methods.runTask(configuration.current(), "backup", withFiles=withFiles, baseName=basename)
Esempio n. 20
0
def install(**kwargs):
    configuration.check()
    config = configuration.current()
    if config["type"] == "prod" or not config["supportsInstalls"]:
        print red(
            'Task install is not supported for this configuration. Please check if "type" and "supportsInstalls" is set correctly.'
        )
        exit(1)

    methods.runTask(configuration.current(), "install", nextTasks=["reset"], **kwargs)
Esempio n. 21
0
def deploy(overrideBranch=False):
  configuration.check()
  config = configuration.current()
  if overrideBranch:
    config['branch'] = overrideBranch

  if config['backupBeforeDeploy']:
      backup(withFiles=False)

  methods.runTask(config, 'deploy', nextTasks=['reset'])
Esempio n. 22
0
def deploy(overrideBranch=False):
    configuration.check()
    config = configuration.current()
    if overrideBranch:
        config["branch"] = overrideBranch

    if config["backupBeforeDeploy"]:
        backup(withFiles=False)

    methods.runTask(config, "deploy", nextTasks=["reset"])
Esempio n. 23
0
def backup(withFiles = True):
  configuration.check()
  print green('backing up files and database of "%s" @ "%s"' % (configuration.getSettings('name'), configuration.current('config_name')))
  i = datetime.datetime.now()
  basename = [
    configuration.current('config_name'),
    i.strftime('%Y-%m-%d--%H-%M-%S')
  ]

  methods.runTask(configuration.current(), 'backup', withFiles = withFiles, baseName = basename)
Esempio n. 24
0
def deploy(overrideBranch=False):
  configuration.check()
  config = configuration.current()
  if overrideBranch:
    config['branch'] = overrideBranch

  if config['backupBeforeDeploy']:
      backup(withFiles=False)

  methods.runTask(config, 'deploy', nextTasks=['reset'])
Esempio n. 25
0
def install(**kwargs):
  configuration.check()
  config = configuration.current()
  if config['type'] == 'prod' or not config['supportsInstalls']:
    log.error('Task install is not supported for this configuration. Please check if "type" and "supportsInstalls" is set correctly.')
    exit(1)

  if 'nextTasks' not in kwargs:
    kwargs['nextTasks'] = ['reset']

  methods.runTask(configuration.current(), 'install', **kwargs)
Esempio n. 26
0
def getFilesDump():
  configuration.check();
  file_name = '--'.join([configuration.current('config_name'), time.strftime("%Y%m%d-%H%M%S")]) + '.tgz'

  log.info('Get files dump from %s' % configuration.current('config_name'))

  file_name = configuration.current('tmpFolder') + '/' + file_name
  methods.runTask(configuration.current(), 'backupFiles', backup_file_name = file_name)
  getFile(file_name)
  if configuration.current()['runLocally']:
    local('rm ' + file_name)
  else:
    run('rm ' + file_name);
Esempio n. 27
0
def getSQLDump():
    configuration.check()

    file_name = "--".join([configuration.current("config_name"), time.strftime("%Y%m%d-%H%M%S")]) + ".sql"

    print green("Get SQL dump from %s" % configuration.current("config_name"))

    file_name = "/tmp/" + file_name
    methods.runTask(configuration.current(), "backupSql", backup_file_name=file_name)
    if configuration.current("supportsZippedBackups"):
        file_name += ".gz"
    getFile(file_name)
    run("rm " + file_name)
Esempio n. 28
0
def install(**kwargs):
    configuration.check()
    config = configuration.current()
    if config['type'] == 'prod' or not config['supportsInstalls']:
        log.error(
            'Task install is not supported for this configuration. Please check if "type" and "supportsInstalls" is set correctly.'
        )
        exit(1)

    if 'nextTasks' not in kwargs:
        kwargs['nextTasks'] = ['reset']

    methods.runTask(configuration.current(), 'install', **kwargs)
Esempio n. 29
0
def getProperty(in_key):
  configuration.check()
  with hide('output', 'running', 'warnings'):
    keys = in_key.split('/')
    c = configuration.current()
    for key in keys:
      if key in c:
        c = c[key]
      else:
        print red('property "%s" not found!' % in_key)
        exit(1)

  print c
  exit(0)
Esempio n. 30
0
def getProperty(in_key):
  configuration.check()
  with hide('output', 'running', 'warnings'):
    keys = in_key.split('/')
    c = configuration.current()
    for key in keys:
      if key in c:
        c = c[key]
      else:
        log.error('property "%s" not found!' % in_key)
        exit(1)

  print c
  exit(0)
Esempio n. 31
0
def getProperty(in_key):
    configuration.check()
    with hide("output", "running", "warnings"):
        keys = in_key.split("/")
        c = configuration.current()
        for key in keys:
            if key in c:
                c = c[key]
            else:
                print red('property "%s" not found!' % in_key)
                exit(1)

    print c
    exit(0)
Esempio n. 32
0
def getSQLDump():
  configuration.check()

  file_name = '--'.join([configuration.current('config_name'), time.strftime("%Y%m%d-%H%M%S")]) + '.sql'

  print green('Get SQL dump from %s' % configuration.current('config_name'))

  file_name = '/tmp/' + file_name
  methods.runTask(configuration.current(), 'backupSql', backup_file_name = file_name)
  if configuration.current('supportsZippedBackups'):
    file_name += '.gz'
  getFile(file_name)
  if configuration.current()['runLocally']:
    local('rm ' + file_name)
  else:
    run('rm ' + file_name);
Esempio n. 33
0
def getSQLDump():
  configuration.check()

  file_name = '--'.join([configuration.current('config_name'), time.strftime("%Y%m%d-%H%M%S")]) + '.sql'

  log.info('Get SQL dump from %s' % configuration.current('config_name'))

  file_name = configuration.current('tmpFolder') + '/' + file_name
  methods.runTask(configuration.current(), 'backupSql', backup_file_name = file_name)
  if configuration.current('supportsZippedBackups'):
    file_name += '.gz'
  getFile(file_name)
  if configuration.current()['runLocally']:
    local('rm ' + file_name)
  else:
    run('rm ' + file_name);
Esempio n. 34
0
def getFilesDump():
    configuration.check()
    file_name = '--'.join(
        [configuration.current('config_name'),
         time.strftime("%Y%m%d-%H%M%S")]) + '.tgz'

    log.info('Get files dump from %s' % configuration.current('config_name'))

    file_name = configuration.current('tmpFolder') + '/' + file_name
    methods.runTask(configuration.current(),
                    'backupFiles',
                    backup_file_name=file_name)
    getFile(file_name)
    if configuration.current()['runLocally']:
        local('rm ' + file_name)
    else:
        run('rm ' + file_name)
Esempio n. 35
0
def script(scriptKey=False, *args, **kwargs):
    configuration.check()
    scripts = configuration.current('scripts')
    scriptData = scripts[scriptKey] if scriptKey in scripts else False

    if not scriptData:
        scripts = configuration.getSettings('scripts')
        scriptData = scripts[scriptKey] if scriptKey in scripts else False

    if not scriptData:
        log.error('Could not find any script named "%s" in fabfile.yaml' %
                  scriptKey)
        if configuration.current('scripts'):
            print 'Available scripts in %s:\n  - ' % configuration.current(
                'config_name') + '\n  - '.join(
                    configuration.current('scripts').keys())

        if configuration.getSettings('scripts'):
            print 'Available scripts: \n  - ' + '\n  - '.join(
                configuration.getSettings('scripts').keys())

        exit(1)

    if isinstance(scriptData, dict):
        if 'defaults' in scriptData:
            kwargs = configuration.data_merge(scriptData['defaults'], kwargs)

        scriptData = scriptData['script']

    # compute arguments:
    arguments = ' '.join(args)
    for key in kwargs.keys():
        arguments += ' ' + key + '="' + kwargs[key] + '"'
    variables = {
        'arguments': kwargs,
    }
    variables['arguments']['combined'] = arguments

    if scriptData:
        methods.call('script',
                     'runScript',
                     configuration.current(),
                     script=scriptData,
                     variables=variables)
Esempio n. 36
0
def listBackups(commit = False):
  configuration.check()
  results = []
  if commit:
    results = get_backup_files(commit)

    print "\nFound last backup for %s and commit %s:" % (configuration.current('config_name'), commit)
  else:
    methods.runTask(configuration.current(), 'listBackups', results = results)
    results = sorted(results, key = lambda l: (l['date'], l['time']))
    print "\nFound backups for "+ configuration.current('config_name') + ":"
  last_date = ''
  for result in results:
    if result['date'] == last_date:
      result['date'] = '          '
    else:
      last_date = result['date']

    print "{date} {time}  |  {commit:<30}  |  {method:<10}  |  {file}".format(**result)
Esempio n. 37
0
def listBackups(commit = False):
  configuration.check()
  results = []
  if commit:
    results = get_backup_files(commit)

    print "\nFound last backup for %s and commit %s:" % (configuration.current('config_name'), commit)
  else:
    methods.runTask(configuration.current(), 'listBackups', results = results)
    results = sorted(results, key = lambda l: (l['date'], l['time']))
    print "\nFound backups for "+ configuration.current('config_name') + ":"
  last_date = ''
  for result in results:
    if result['date'] == last_date:
      result['date'] = '          '
    else:
      last_date = result['date']

    print "{date} {time}  |  {commit:<30}  |  {method:<10}  |  {file}".format(**result)
Esempio n. 38
0
def createApp(**kwargs):
  configuration.check(['docker'])
  if not configuration.getSettings('repository'):
    log.error('Missing repository in fabfile, can\'t continue')
    exit(1)

  log.info('Create app from source at %s' % configuration.getSettings('repository'))
  stages = [
    {
      'stage': 'checkExistingInstallation',
      'connection': 'docker',
      'context': {
        'installationExists': False
        }
    }
  ]
  createDestroyHelper(stages, 'createApp')
  if stages[0]['context']['installationExists']:
    log.info('Found an existing installation, running deploy instead!')

    # Spin up the container.
    stages = [
      { 'stage': 'spinUp','connection': 'docker' },
    ]
    createDestroyHelper(stages, 'createApp', **kwargs)

    deploy()
    return

  # Install the app.
  stages = configuration.getSettings('createAppStages', [
    { 'stage': 'installCode','connection': 'docker' },
    { 'stage': 'spinUp','connection': 'docker' },
    { 'stage': 'installDependencies','connection': 'ssh' },
    { 'stage': 'install','connection': 'ssh', 'withReset': 'copyFrom' not in kwargs },
  ])

  createDestroyHelper(stages, 'createApp', **kwargs)

  if 'copyFrom' in kwargs:
   copyFrom(kwargs['copyFrom'])
Esempio n. 39
0
def script(scriptKey = False, *args, **kwargs):
  configuration.check()
  scripts = configuration.current('scripts')
  scriptData = scripts[scriptKey] if scriptKey in scripts else False

  if not scriptData:
    scripts = configuration.getSettings('scripts')
    scriptData = scripts[scriptKey] if scriptKey in scripts else False

  if not scriptData:
    log.error('Could not find any script named "%s" in fabfile.yaml' % scriptKey)
    if configuration.current('scripts'):
      print 'Available scripts in %s:\n  - ' % configuration.current('config_name') + '\n  - '.join(configuration.current('scripts').keys())

    if configuration.getSettings('scripts'):
      print 'Available scripts: \n  - '  + '\n  - '.join(configuration.getSettings('scripts').keys())

    exit(1)

  if isinstance(scriptData, dict):
    if 'defaults' in scriptData:
      kwargs = configuration.data_merge(scriptData['defaults'], kwargs)

    scriptData = scriptData['script']

  # compute arguments:
  arguments = ' '.join(args)
  for key in kwargs.keys():
    arguments += ' ' + key + '="' + kwargs[key]+'"'
  variables = {
    'arguments': kwargs,
  }
  variables['arguments']['combined'] = arguments


  if scriptData:
    methods.call('script', 'runScript', configuration.current(), script=scriptData, variables=variables)
Esempio n. 40
0
def script(scriptKey=False, *args, **kwargs):
    configuration.check()
    scripts = configuration.current("scripts")
    scriptData = scripts[scriptKey] if scriptKey in scripts else False

    if not scriptData:
        scripts = configuration.getSettings("scripts")
        scriptData = scripts[scriptKey] if scriptKey in scripts else False

    if not scriptData:
        print red('Could not find any script named "%s" in fabfile.yaml' % scriptKey)
        if configuration.current("scripts"):
            print "Available scripts in %s:\n  - " % configuration.current("config_name") + "\n  - ".join(
                configuration.current("scripts").keys()
            )

        if configuration.getSettings("scripts"):
            print "Available scripts: \n  - " + "\n  - ".join(configuration.getSettings("scripts").keys())

        exit(1)

    if isinstance(scriptData, dict):
        if "defaults" in scriptData:
            kwargs = configuration.data_merge(scriptData["defaults"], kwargs)

        scriptData = scriptData["script"]

    # compute arguments:
    arguments = " ".join(args)
    for key in kwargs.keys():
        arguments += " " + key + '="' + kwargs[key] + '"'
    variables = {"arguments": kwargs}
    variables["arguments"]["combined"] = arguments

    if scriptData:
        methods.call("script", "runScript", configuration.current(), script=scriptData, variables=variables)
Esempio n. 41
0
def copyFrom(source_config_name):
  configuration.check()
  copyDBFrom(source_config_name)
  copyFilesFrom(source_config_name)
Esempio n. 42
0
def copyFilesFrom(source_config_name):
  configuration.check()
  source_configuration = configuration.get(source_config_name)
  methods.runTask(configuration.current(), 'copyFilesFrom', source_config=source_configuration)
Esempio n. 43
0
def notify(message):
  configuration.check()
  methods.runTask(configuration.current(), 'notify', message=message)
Esempio n. 44
0
def restore(commit, cleanupBeforeRestore=0):
  configuration.check()
  files = get_backup_files(commit)
  methods.runTask(configuration.current(), 'restore', files = files, cleanupBeforeRestore = cleanupBeforeRestore)

  reset()
Esempio n. 45
0
def installFrom(source_config_name, **kwargs):
  configuration.check()
  kwargs['nextTasks'] = []
  install(**kwargs)
  copyFrom(source_config_name)
Esempio n. 46
0
def notify(message):
  configuration.check()
  methods.runTask(configuration.current(), 'notify', message=message)
Esempio n. 47
0
def docker(command = False, **kwargs):
  configuration.check()
  methods.call('docker', 'runCommand', configuration.current(), command = command, **kwargs)
Esempio n. 48
0
def reset(**kwargs):
  configuration.check()

  methods.runTask(configuration.current(), 'reset', **kwargs)
Esempio n. 49
0
def composer(composer_command):
  configuration.check(['composer'])
  methods.call('composer', 'composer', configuration.current(), command=composer_command)
Esempio n. 50
0
def drupalconsole(drupal_command):
  configuration.check(['drupalconsole'])
  methods.call('drupalconsole', 'drupalconsole', configuration.current(), command=drupal_command)
Esempio n. 51
0
def copyFilesFrom(source_config_name):
  configuration.check()
  source_configuration = configuration.get(source_config_name)
  methods.runTask(configuration.current(), 'copyFilesFrom', source_config=source_configuration)
Esempio n. 52
0
def restoreSQLFromFile(full_file_name):
  configuration.check()
  methods.runTask(configuration.current(), 'restoreSQLFromFile', sourceFile = full_file_name)
Esempio n. 53
0
def ssh():
  configuration.check(['ssh'])
  methods.call('ssh', 'openShell', configuration.current())
Esempio n. 54
0
def doctor(**kwargs):
  configuration.check()
  methods.runTask(configuration.current(), 'doctor', **kwargs)
Esempio n. 55
0
def copyDBFrom(source_config_name):
  configuration.check()
  source_configuration = configuration.get(source_config_name)
  methods.runTask(configuration.current(), 'copyDBFrom', source_config=source_configuration, nextTasks=['reset'])
Esempio n. 56
0
def drush(drush_command):
  configuration.check(['drush7', 'drush8'])
  methods.call('drush', 'drush', configuration.current(), command=drush_command)
Esempio n. 57
0
def doctor(**kwargs):
  configuration.check()
  methods.runTask(configuration.current(), 'doctor', **kwargs)
Esempio n. 58
0
def copyFrom(source_config_name):
  configuration.check()
  copyDBFrom(source_config_name)
  copyFilesFrom(source_config_name)
Esempio n. 59
0
def version():
  configuration.check('git')
  version = methods.call('git', 'getVersion', configuration.current())
  print green('%s @ %s tagged with: %s' % (configuration.getSettings('name'), configuration.current('config_name'), version))
Esempio n. 60
0
def restoreSQLFromFile(full_file_name):
  configuration.check()
  methods.runTask(configuration.current(), 'restoreSQLFromFile', sourceFile = full_file_name)