def _compile(self, install): # modify php.ini to add `geoip.custom_directory` self.load_config() self._php_ini.append_lines( 'geoip.custom_directory=@{HOME}/php/geoipdb/dbs') self._php_ini.save(self._php_ini_path) # download geoip dbs geoipdbs = os.path.join( self._ctx['BUILD_DIR'], 'php', 'geoipdb', 'dbs') utils.safe_makedirs(geoipdbs) if self._should_download(): print 'Downloading Geoip Databases.' stream_output(sys.stdout, self._build_download_cmd(), shell=True) self._link_geoip_dat() else: print 'Copying Geoip Databases from App.' app_geoipdbs = self._ctx.get(self.GEOIP_LOCATION_KEY, None) if app_geoipdbs: app_geoipdbs_path = os.path.join(self._ctx['BUILD_DIR'], app_geoipdbs) if not os.path.exists(app_geoipdbs_path): app_geoipdbs_path = os.path.join(self._ctx['BUILD_DIR'], 'htdocs', app_geoipdbs) shutil.rmtree(geoipdbs) shutil.move(app_geoipdbs_path, geoipdbs)
def run(self, *args): try: cmd = [self._php_path, self._composer_path] cmd.extend(args) self._log.debug("Running command [%s]", ' '.join(cmd)) stream_output(sys.stdout, ' '.join(cmd), env=self._build_composer_environment(), cwd=self._ctx['BUILD_DIR'], shell=True) except: print "-----> Composer command failed" raise
def _github_oauth_token_is_valid(self, candidate_oauth_token): stringio_writer = StringIO.StringIO() curl_command = 'curl -H "Authorization: token %s" https://api.github.com/rate_limit' % candidate_oauth_token stream_output(stringio_writer, curl_command, env=os.environ, cwd=self._ctx['BUILD_DIR'], shell=True) github_response = stringio_writer.getvalue() github_response_json = json.loads(github_response) return 'resources' in github_response_json
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 _runCmd(self, environ, currWorkDir, cmd, displayRunLog=False): stringioWriter = StringIO.StringIO() try: stream_output(stringioWriter, ' '.join(cmd), env=environ, cwd=currWorkDir, shell=True) cmdOutput = stringioWriter.getvalue() if displayRunLog: self._logMsg(cmdOutput) except: cmdOutput = stringioWriter.getvalue() print '-----> Command failed' print cmdOutput raise return cmdOutput
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 _github_rate_exceeded(self, token_is_valid): stringio_writer = StringIO.StringIO() if token_is_valid: candidate_oauth_token = os.getenv('COMPOSER_GITHUB_OAUTH_TOKEN') curl_command = 'curl -H "Authorization: token %s" ' \ 'https://api.github.com/rate_limit' % candidate_oauth_token else: curl_command = 'curl https://api.github.com/rate_limit' stream_output(stringio_writer, curl_command, env=os.environ, cwd=self._ctx['BUILD_DIR'], shell=True) github_response = stringio_writer.getvalue() github_response_json = json.loads(github_response) rate = github_response_json['rate'] num_remaining = rate['remaining'] return num_remaining <= 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 self.composer_strategy.write_config(self._builder) # Run from /tmp/staged/app try: phpPath = self.binary_path() composerPath = os.path.join(self._ctx['BUILD_DIR'], 'php', 'bin', 'composer.phar') if os.getenv('COMPOSER_GITHUB_OAUTH_TOKEN', False): github_oauth_token = os.getenv('COMPOSER_GITHUB_OAUTH_TOKEN') if self._github_oauth_token_is_valid(github_oauth_token): print( '-----> Using custom GitHub OAuth token in $COMPOSER_GITHUB_OAUTH_TOKEN' ) composer_oauth_config_command = [ phpPath, composerPath, 'config', '-g', 'github-oauth.github.com', '"%s"' % github_oauth_token ] output = stream_output( sys.stdout, ' '.join(composer_oauth_config_command), env=self._build_composer_environment(), cwd=self._ctx['BUILD_DIR'], shell=True) composer_install_command = [ phpPath, composerPath, 'install', '--no-progress' ] composer_install_command.extend( self._ctx['COMPOSER_INSTALL_OPTIONS']) self._log.debug("Running [%s]", ' '.join(composer_install_command)) self._log.debug( "ENV IS: %s", '\n'.join([ "%s=%s (%s)" % (key, val, type(val)) for ( key, val) in self._build_composer_environment().iteritems() ])) output = stream_output(sys.stdout, ' '.join(composer_install_command), env=self._build_composer_environment(), cwd=self._ctx['BUILD_DIR'], shell=True) _log.debug('composer output [%s]', output) except: print "-----> Composer command failed" _log.exception("Composer failed") raise
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 self.composer_strategy.write_config(self._builder) # Run from /tmp/staged/app try: phpPath = self.binary_path() composerPath = os.path.join(self._ctx['BUILD_DIR'], 'php', 'bin', 'composer.phar') if os.getenv('COMPOSER_GITHUB_OAUTH_TOKEN', False): github_oauth_token = os.getenv('COMPOSER_GITHUB_OAUTH_TOKEN') if self._github_oauth_token_is_valid(github_oauth_token): print('-----> Using custom GitHub OAuth token in $COMPOSER_GITHUB_OAUTH_TOKEN') composer_oauth_config_command = [phpPath, composerPath, 'config', '-g', 'github-oauth.github.com', '"%s"' % github_oauth_token] output = stream_output(sys.stdout, ' '.join(composer_oauth_config_command), env=self._build_composer_environment(), cwd=self._ctx['BUILD_DIR'], shell=True) composer_install_command = [phpPath, composerPath, 'install', '--no-progress'] composer_install_command.extend(self._ctx['COMPOSER_INSTALL_OPTIONS']) self._log.debug("Running [%s]", ' '.join(composer_install_command)) self._log.debug("ENV IS: %s", '\n'.join(["%s=%s (%s)" % (key, val, type(val)) for (key, val) in self._build_composer_environment().iteritems()])) output = stream_output(sys.stdout, ' '.join(composer_install_command), env=self._build_composer_environment(), cwd=self._ctx['BUILD_DIR'], shell=True) _log.debug('composer output [%s]', output) except: print "-----> Composer command failed" _log.exception("Composer failed") raise