def run(self):
     # Move composer files out of WEBDIR
     (self._builder.move()
         .under('{BUILD_DIR}/{WEBDIR}')
         .where_name_is('composer.json')
         .into('BUILD_DIR')
      .done())
     (self._builder.move()
         .under('{BUILD_DIR}/{WEBDIR}')
         .where_name_is('composer.lock')
         .into('BUILD_DIR')
      .done())
     # Sanity Checks
     if not os.path.exists(os.path.join(self._ctx['BUILD_DIR'],
                                        'composer.lock')):
         msg = (
             'PROTIP: Include a `composer.lock` file with your '
             'application! This will make sure the exact same version '
             'of dependencies are used when you deploy to CloudFoundry.')
         self._log.warning(msg)
         print msg
     # rewrite a temp copy of php.ini for use by composer
     (self._builder.copy()
         .under('{BUILD_DIR}/php/etc')
         .where_name_is('php.ini')
         .into('TMPDIR')
      .done())
     utils.rewrite_cfgs(os.path.join(self._ctx['TMPDIR'], 'php.ini'),
                        {'TMPDIR': self._ctx['TMPDIR'],
                         'HOME': self._ctx['BUILD_DIR']},
                        delim='@')
     # Run from /tmp/staged/app
     try:
         phpPath = os.path.join(self._ctx['BUILD_DIR'], 'php', 'bin', 'php')
         phpCfg = os.path.join(self._ctx['TMPDIR'], 'php.ini')
         composerPath = os.path.join(self._ctx['BUILD_DIR'], 'php',
                                     'bin', 'composer.phar')
         composerEnv = {
             'LD_LIBRARY_PATH': os.path.join(self._ctx['BUILD_DIR'],
                                             'php', 'lib'),
             'HOME': self._ctx['BUILD_DIR'],
             'COMPOSER_VENDOR_DIR': self._ctx['COMPOSER_VENDOR_DIR'],
             'COMPOSER_BIN_DIR': self._ctx['COMPOSER_BIN_DIR'],
             'COMPOSER_CACHE_DIR': self._ctx['COMPOSER_CACHE_DIR']
         }
         composerCmd = [phpPath,
                        '-c "%s"' % phpCfg,
                        composerPath,
                        'install',
                        '--no-progress']
         composerCmd.extend(self._ctx['COMPOSER_INSTALL_OPTIONS'])
         self._log.debug("Running [%s]", ' '.join(composerCmd))
         output = stream_output(sys.stdout,
                                ' '.join(composerCmd),
                                env=composerEnv,
                                cwd=self._ctx['BUILD_DIR'],
                                shell=True)
         _log.debug('composer output [%s]', output)
     except Exception:
         _log.error("Command Failed: %s")
 def test_rewrite_custom_delimiter(self):
     ctx = utils.FormattedDict({
         'TMPDIR': '/tmp',
         'HOME': '/home/user',
         'SOMEPATH': '{TMPDIR}/path'
     })
     utils.rewrite_cfgs(self.cfgs, ctx, delim='@')
     self.assert_cfg_custom(os.path.join(self.cfgs, 'test.cfg'))
     self.assert_cfg_custom(os.path.join(self.cfgs, 'subdir', 'test.cfg'))
 def test_rewrite_file(self):
     ctx = utils.FormattedDict({
         'TMPDIR': '/tmp',
         'HOME': '/home/user',
         'SOMEPATH': '{TMPDIR}/path'
     })
     utils.rewrite_cfgs(os.path.join(self.cfgs, 'test.cfg'), ctx)
     self.assert_cfg_std(os.path.join(self.cfgs, 'test.cfg'))
     self.assert_cfg_fresh(os.path.join(self.cfgs, 'subdir', 'test.cfg'))
Example #4
0
 def write_config(self, builder):
     # rewrite a temp copy of php.ini for use by composer
     (builder.copy().under('{BUILD_DIR}/php/etc').where_name_is(
         'php.ini').into('TMPDIR').done())
     utils.rewrite_cfgs(os.path.join(self._ctx['TMPDIR'], 'php.ini'), {
         'TMPDIR': self._ctx['TMPDIR'],
         'HOME': self._ctx['BUILD_DIR']
     },
                        delim='@')
Example #5
0
 def write_config(self, builder):
     # rewrite a temp copy of php.ini for use by composer
     (builder.copy()
         .under('{BUILD_DIR}/php/etc')
         .where_name_is('php.ini')
         .into('TMPDIR')
      .done())
     utils.rewrite_cfgs(os.path.join(self._ctx['TMPDIR'], 'php.ini'),
                        {'TMPDIR': self._ctx['TMPDIR'],
                         'HOME': self._ctx['BUILD_DIR']},
                        delim='@')
Example #6
0
 def run(self):
     # Move composer files out of WEBDIR
     (self._builder.move().under('{BUILD_DIR}/{WEBDIR}').where_name_is(
         'composer.json').into('BUILD_DIR').done())
     (self._builder.move().under('{BUILD_DIR}/{WEBDIR}').where_name_is(
         'composer.lock').into('BUILD_DIR').done())
     # Sanity Checks
     if not os.path.exists(
             os.path.join(self._ctx['BUILD_DIR'], 'composer.lock')):
         msg = ('PROTIP: Include a `composer.lock` file with your '
                'application! This will make sure the exact same version '
                'of dependencies are used when you deploy to CloudFoundry.')
         self._log.warning(msg)
         print msg
     # rewrite a temp copy of php.ini for use by composer
     (self._builder.copy().under('{BUILD_DIR}/php/etc').where_name_is(
         'php.ini').into('TMPDIR').done())
     utils.rewrite_cfgs(os.path.join(self._ctx['TMPDIR'], 'php.ini'), {
         'TMPDIR': self._ctx['TMPDIR'],
         'HOME': self._ctx['BUILD_DIR']
     },
                        delim='@')
     # Run from /tmp/staged/app
     try:
         phpPath = os.path.join(self._ctx['BUILD_DIR'], 'php', 'bin', 'php')
         phpCfg = os.path.join(self._ctx['TMPDIR'], 'php.ini')
         composerPath = os.path.join(self._ctx['BUILD_DIR'], 'php', 'bin',
                                     'composer.phar')
         composerEnv = {
             'LD_LIBRARY_PATH':
             os.path.join(self._ctx['BUILD_DIR'], 'php', 'lib'),
             'HOME':
             self._ctx['BUILD_DIR'],
             'COMPOSER_VENDOR_DIR':
             self._ctx['COMPOSER_VENDOR_DIR'],
             'COMPOSER_BIN_DIR':
             self._ctx['COMPOSER_BIN_DIR'],
             'COMPOSER_CACHE_DIR':
             self._ctx['COMPOSER_CACHE_DIR']
         }
         composerCmd = [
             phpPath,
             '-c "%s"' % phpCfg, composerPath, 'install', '--no-progress'
         ]
         composerCmd.extend(self._ctx['COMPOSER_INSTALL_OPTIONS'])
         self._log.debug("Running [%s]", ' '.join(composerCmd))
         output = stream_output(sys.stdout,
                                ' '.join(composerCmd),
                                env=composerEnv,
                                cwd=self._ctx['BUILD_DIR'],
                                shell=True)
         _log.debug('composer output [%s]', output)
     except Exception:
         _log.error("Command Failed: %s")
Example #7
0
def install_wordpress(ctx, builder, wordpressDir):
    # rewrite a temp copy of php.ini for use by wp-cli
    (builder
        .copy()
        .under('{BUILD_DIR}/php/etc')
        .where_name_is('php.ini')
        .into('TMPDIR')
     .done())
    utils.rewrite_cfgs(os.path.join(ctx['TMPDIR'], 'php.ini'),
                       {'TMPDIR': ctx['TMPDIR'],
                        'HOME': ctx['BUILD_DIR']},
                       delim='@')
    # get path to php config we just created
    phpconfig = os.path.join(ctx['TMPDIR'], 'php.ini')
    # get path to php binary
    phpcmd = os.path.join(ctx['BUILD_DIR'], 'php', 'bin', 'php')
    # set the library path so php can find it's extension
    os.environ['LD_LIBRARY_PATH'] = os.path.join(ctx['BUILD_DIR'], 'php', 'lib')

    print 'Installing WordPress'
    setupjson = load_json(wordpressDir)
    if setupjson.has_key('wordpress_version'):
        args = [phpcmd, '-c', phpconfig, 'wp-cli.phar', 'core', 'download', '--version=%s' % setupjson['wordpress_version']]
    else:
        args = [phpcmd, '-c', phpconfig, 'wp-cli.phar', 'core', 'download', '--version=latest']
    subprocess.call(args, cwd=wordpressDir)
    args = [phpcmd, '-c', phpconfig, 'wp-cli.phar', 'core', 'install', '--url=%s' % setupjson['site_info']['url'], '--title=%s' % setupjson['site_info']['title'], '--admin_user=%s' % setupjson['site_info']['admin_user'], '--admin_password=%s' % setupjson['site_info']['admin_password'], '--admin_email=%s' % setupjson['site_info']['admin_email']]
    subprocess.call(args, cwd=wordpressDir)
    if setupjson.has_key('plugins') and len(setupjson['plugins']):
        for plugin in setupjson['plugins']:
          if plugin.has_key('name') and plugin.has_key('version'):
              args = [phpcmd, '-c', phpconfig, 'wp-cli.phar', 'plugin', 'install', '%s' % plugin['name'], '--version=%s' % plugin['version'], '--activate']
          elif plugin.has_key('name'):
              args = [phpcmd, '-c', phpconfig, 'wp-cli.phar', 'plugin', 'install', '%s' % plugin['name'], '--activate']
          elif plugin.has_key('url'):
              args = [phpcmd, '-c', phpconfig, 'wp-cli.phar', 'plugin', 'install', '%s' % plugin['url'], '--activate']
          subprocess.call(args, cwd=wordpressDir)
    if setupjson.has_key('themes') and len(setupjson['themes']):
        for theme in setupjson['themes']:
          if theme.has_key('name') and theme.has_key('version'):
              args = [phpcmd, '-c', phpconfig, 'wp-cli.phar', 'theme', 'install', '%s' % theme['name'], '--version=%s' % theme['version']]
          elif theme.has_key('name'):
              args = [phpcmd, '-c', phpconfig, 'wp-cli.phar', 'theme', 'install', '%s' % theme['name']]
          elif theme.has_key('url'):
              args = [phpcmd, '-c', phpconfig, 'wp-cli.phar', 'theme', 'install', '%s' % theme['url']]
          subprocess.call(args, cwd=wordpressDir)
Example #8
0
def install_wordpress(ctx, builder, wordpressDir):
    # rewrite a temp copy of php.ini for use by wp-cli
    (builder.copy().under('{BUILD_DIR}/php/etc').where_name_is('php.ini').into(
        'TMPDIR').done())
    utils.rewrite_cfgs(os.path.join(ctx['TMPDIR'], 'php.ini'), {
        'TMPDIR': ctx['TMPDIR'],
        'HOME': ctx['BUILD_DIR']
    },
                       delim='@')
    # get path to php config we just created
    phpconfig = os.path.join(ctx['TMPDIR'], 'php.ini')
    # get path to php binary
    phpcmd = os.path.join(ctx['BUILD_DIR'], 'php', 'bin', 'php')
    # set the library path so php can find it's extension
    os.environ['LD_LIBRARY_PATH'] = os.path.join(ctx['BUILD_DIR'], 'php',
                                                 'lib')

    print 'Installing WordPress'
    setupjson = load_json(wordpressDir)
    if setupjson.has_key('wordpress_version'):
        args = [
            phpcmd, '-c', phpconfig, 'wp-cli.phar', 'core', 'download',
            '--version=%s' % setupjson['wordpress_version']
        ]
    else:
        args = [
            phpcmd, '-c', phpconfig, 'wp-cli.phar', 'core', 'download',
            '--version=latest'
        ]
    subprocess.call(args, cwd=wordpressDir)
    args = [
        phpcmd, '-c', phpconfig, 'wp-cli.phar', 'core', 'install',
        '--url=%s' % setupjson['site_info']['url'],
        '--title=%s' % setupjson['site_info']['title'],
        '--admin_user=%s' % setupjson['site_info']['admin_user'],
        '--admin_password=%s' % setupjson['site_info']['admin_password'],
        '--admin_email=%s' % setupjson['site_info']['admin_email']
    ]
    subprocess.call(args, cwd=wordpressDir)
    if setupjson.has_key('plugins') and len(setupjson['plugins']):
        for plugin in setupjson['plugins']:
            if plugin.has_key('name') and plugin.has_key('version'):
                args = [
                    phpcmd, '-c', phpconfig, 'wp-cli.phar', 'plugin',
                    'install',
                    '%s' % plugin['name'],
                    '--version=%s' % plugin['version'], '--activate'
                ]
            elif plugin.has_key('name'):
                args = [
                    phpcmd, '-c', phpconfig, 'wp-cli.phar', 'plugin',
                    'install',
                    '%s' % plugin['name'], '--activate'
                ]
            elif plugin.has_key('url'):
                args = [
                    phpcmd, '-c', phpconfig, 'wp-cli.phar', 'plugin',
                    'install',
                    '%s' % plugin['url'], '--activate'
                ]
            subprocess.call(args, cwd=wordpressDir)
    if setupjson.has_key('themes') and len(setupjson['themes']):
        for theme in setupjson['themes']:
            if theme.has_key('name') and theme.has_key('version'):
                args = [
                    phpcmd, '-c', phpconfig, 'wp-cli.phar', 'theme', 'install',
                    '%s' % theme['name'],
                    '--version=%s' % theme['version']
                ]
            elif theme.has_key('name'):
                args = [
                    phpcmd, '-c', phpconfig, 'wp-cli.phar', 'theme', 'install',
                    '%s' % theme['name']
                ]
            elif theme.has_key('url'):
                args = [
                    phpcmd, '-c', phpconfig, 'wp-cli.phar', 'theme', 'install',
                    '%s' % theme['url']
                ]
            subprocess.call(args, cwd=wordpressDir)