/** * Execute task and return report info * * @return \Deployer\Task\Min */ public function execute() { $info = ''; $dir = \Deployer::applyGlobalParams($this->param('dir')); $finder = new Finder(); $iterator = $finder->files(); $overallDecrease = 0; foreach ($this->param('name') as $name) { $iterator->name(\Deployer::applyGlobalParams($name)); } $files = $iterator->in($dir); foreach ($files as $file) { $fileName = str_replace('/', DIRECTORY_SEPARATOR, $file); list($decreasePrecent, $decreaseBytes) = $this->_min($fileName); $overallDecrease += $decreaseBytes; $info .= sprintf('%s file decreased at %01.2f%% (%s)', \Deployer::censor($fileName), $decreasePrecent, \Deployer::size($decreaseBytes)) . PHP_EOL; } $message = sprintf('%d files minifyed at %s', sizeof($files), \Deployer::size($overallDecrease)); \Deployer::messageInfo($message); $info .= $message . PHP_EOL; if (!empty($info)) { return $this->info($info); } return $this; }
/** @return Deployer */ private function createDeployer($config) { $config = array_change_key_case($config, CASE_LOWER) + ['local' => '', 'passivemode' => TRUE, 'ignore' => '', 'allowdelete' => TRUE, 'purge' => '', 'before' => '', 'after' => '', 'preprocess' => TRUE]; if (empty($config['remote']) || !parse_url($config['remote'])) { throw new \Exception("Missing or invalid 'remote' URL in config."); } $server = parse_url($config['remote'], PHP_URL_SCHEME) === 'sftp' ? new SshServer($config['remote']) : new FtpServer($config['remote'], (bool) $config['passivemode']); if (!preg_match('#/|\\\\|[a-z]:#iA', $config['local'])) { if ($config['local'] && getcwd() !== dirname($this->configFile)) { $this->logger->log('WARNING: the "local" path is now relative to the directory where ' . basename($this->configFile) . ' is placed', 'red'); } $config['local'] = dirname($this->configFile) . '/' . $config['local']; } $deployment = new Deployer($server, $config['local'], $this->logger); if ($config['preprocess']) { $deployment->preprocessMasks = $config['preprocess'] == 1 ? ['*.js', '*.css'] : self::toArray($config['preprocess']); // intentionally == $preprocessor = new Preprocessor($this->logger); $deployment->addFilter('js', [$preprocessor, 'expandApacheImports']); $deployment->addFilter('js', [$preprocessor, 'compressJs'], TRUE); $deployment->addFilter('css', [$preprocessor, 'expandApacheImports']); $deployment->addFilter('css', [$preprocessor, 'expandCssImports']); $deployment->addFilter('css', [$preprocessor, 'compressCss'], TRUE); } $deployment->ignoreMasks = array_merge(['*.bak', '.svn', '.git*', 'Thumbs.db', '.DS_Store'], self::toArray($config['ignore'])); $deployment->deploymentFile = empty($config['deploymentfile']) ? $deployment->deploymentFile : $config['deploymentfile']; $deployment->allowDelete = $config['allowdelete']; $deployment->toPurge = self::toArray($config['purge'], TRUE); $deployment->runBefore = self::toArray($config['before'], TRUE); $deployment->runAfter = self::toArray($config['after'], TRUE); $deployment->testMode = !empty($config['test']) || $this->mode === 'test'; return $deployment; }
/** * Execute task and return report info * * @return \Deployer\Task */ public function execute() { $zipDir = \Deployer::applyGlobalParams($this->param('dir')); $zipFile = \Deployer::applyGlobalParams($this->param('file')); if (is_file($zipFile)) { unlink($zipFile); } if (!is_dir($zipDir)) { throw new \Deployer\TaskException('"dir" must be a valid directory'); } $zip = new \ZipArchive(); if (!$zip->open($zipFile, \ZIPARCHIVE::CREATE)) { throw new \Deployer\TaskException('can\'t create zip file'); } $dirs = \Deployer::sortByDepth(\Deployer::dirs($zipDir, SORT_ASC)); foreach ($dirs as $dir) { $newDir = $this->_localPath($zipDir, $dir); $zip->addEmptyDir($newDir); } $files = \Deployer::files($zipDir); foreach ($files as $file) { $newFile = $this->_localPath($zipDir, $file); $zip->addFile($file, $newFile); } $zip->close(); if (is_file($zipFile)) { return $this->info(sprintf('file created; size: %s', \Deployer::size(filezize($zipFile)))); } return $this; }
/** * Execute task and return report info * * @return \Deployer\Task */ public function execute() { foreach (array('dir', 'result') as $param) { ${$param} = \Deployer::applyGlobalParams($this->param($param)); } $content = ''; $finder = new Finder(); $iterator = $finder->files(); $allFiles = 0; foreach ($this->param('names') as $name) { $files = $iterator->name(\Deployer::applyGlobalParams($name))->in($dir); foreach ($files as $file) { if ($this->param('debug')) { $content .= PHP_EOL . sprintf('/* %s */', $file) . PHP_EOL; } $content .= file_get_contents($file) . PHP_EOL; if ($this->param('delete')) { unlink($file); } $allFiles++; } } if (is_file($result)) { unlink($result); } file_put_contents($result, $content); $info = sprintf('%d files merged; result file size: %s', $allFiles, \Deployer::size(filesize($result))); \Deployer::messageInfo($info); return $this->info($info); }
/** * Execute task and return report info * * @return \Deployer\Task */ public function execute() { $info = ''; $dirsCopied = $filesCopied = 0; $realFrom = realpath($this->_processPathParam($this->param('from'))) . DIRECTORY_SEPARATOR; $realTo = $this->_processPathParam($this->param('to')); if (!file_exists($realFrom)) { \Deployer::criticalError(sprintf('"%s" not found.', $this->_processPathParam($this->param('from')))); } if (!file_exists($realTo) && $this->param('create')) { @mkdir($realTo); if (!is_dir($realTo)) { \Deployer::criticalError(sprintf('Something went wrong. Can not create directory "%s".', $this->_processPathParam($this->param('from')))); } $info .= sprintf('Directory "%s" created.', $realTo) . PHP_EOL; } if (is_file($realFrom)) { @copy($realFrom, $realTo); if (!is_file($realTo) || filesize($realFrom) != filesize($realTo)) { \Deployer::criticalError(sprintf('Can not copy "%s" => "%s".', $realFrom, $realTo)); } $info .= sprintf('Copied "%s" => "$s".', $realFrom, $realTo) . PHP_EOL; $filesCopied = 1; } else { $files = \Deployer::files($realFrom, $this->param('names'), $this->param('notnames'), SORT_ASC); $dirs = \Deployer::dirs($realFrom, $this->param('names'), $this->param('notnames'), SORT_ASC); foreach ($dirs as $dir) { $destDir = str_replace($realFrom, $realTo, $dir); if (file_exists($destDir)) { \Deployer::criticalError(sprintf('Can not copy dir "%s" => "%s". Destination directory exists.', $dir, $destDir)); } @mkdir($destDir); if (!is_dir($destDir)) { \Deployer::criticalError(sprintf('Something went wrong. Can not copy dir "%s" => "%s".', $dir, $destDir)); } $info .= sprintf('Directory copied "%s" => "%s".', $dir, $destDir) . PHP_EOL; } foreach ($files as $file) { $destFile = str_replace($realFrom, $realTo, $file); if (file_exists($destFile)) { \Deployer::criticalError(sprintf('Can not copy file "%s" => "%s". Destination file exists.', $file, $destFile)); } @copy($file, $destFile); if (!is_file($destFile) || filesize($file) != filesize($destFile)) { \Deployer::criticalError(sprintf('Something went wrong. Can not copy file "%s" => "%s".', $file, $destFile)); } $info .= sprintf('File copied "%s" => "%s".', $file, $destFile) . PHP_EOL; $dirsCopied = sizeof($dirs); $filesCopied = sizeof($files); } } $message = sprintf('Copied %d dirs and %d files.', $dirsCopied, $filesCopied); \Deployer::messageInfo($message); $info .= $message . PHP_EOL; if (!empty($info)) { return $this->info($info); } return $this; }
/** * Execute task and return report info * * @return \Deployer\Task */ public function execute() { $info = ''; foreach ((array) $this->param('cmd') as $cmd) { $command = \Deployer::applyGlobalParams($cmd); $result = $result = shell_exec($command); $info .= '$ ' . $command . PHP_EOL . $result . PHP_EOL . PHP_EOL; } return $this->info($info); }
/** * Execute task and return report info * * @return \Deployer\Task */ public function execute() { $info = ''; $realDir = $this->_processPathParam($this->param('dir')); if (!is_dir($realDir)) { if ($this->param('create')) { @mkdir($realDir); if (!is_dir($realDir)) { \Deployer::criticalError(sprintf('Something went wrong. Can not create directory "%s".', $realDir)); } $info = sprintf('Created directory %s.', $realDir); \Deployer::messageInfo($info); return $this->info($info . PHP_EOL); } \Deployer::criticalError(sprintf('"%s" is not a directory.', $realDir)); } if (!is_writable($realDir)) { \Deployer::criticalError(sprintf('Directory "%s" must be writable.', $realDir)); } $files = \Deployer::files($realDir, $this->param('names'), $this->param('notnames'), SORT_DESC); $dirs = \Deployer::dirs($realDir, $this->param('names'), $this->param('notnames'), SORT_DESC); foreach ($files as $file) { @unlink($file); if (is_file($file)) { \Deployer::criticalError(sprintf('Something went wrong. Can not delete file "%s".', $file)); } $info .= sprintf('File "%s" deleted.', $file) . PHP_EOL; } foreach ($dirs as $dir) { @rmdir($dir); if (is_dir($dir)) { \Deployer::criticalError(sprintf('Something went wrong. Can not remove directory "%s".', $dir)); } $info .= sprintf('Directory "%s" removed.', $dir) . PHP_EOL; } $dirsRemoved = sizeof($dirs); $filesRemoved = sizeof($files); if ($this->param('remove') && !$this->param('create')) { @rmdir($realDir); if (is_dir($realDir)) { \Deployer::criticalError(sprintf('Something went wrong. Can not remove directory "%s".', $file)); } $info .= sprintf('Directory "%s" removed.', $realDir) . PHP_EOL; $dirsRemoved++; } $message = sprintf('Removed %d dirs and %d files.', $dirsRemoved, sizeof($files)); \Deployer::messageInfo($message); $info .= $message . PHP_EOL; if (!empty($info)) { return $this->info($info); } return $this; }
/** * Execute task and return report info * * @return \Deployer\Task */ public function execute() { foreach ($this->params() as $param => $value) { $this->_params[$param] = \Deployer::applyGlobalParams($value); } $ssh = new \Net_SSH2($this->param('host'), $this->param('port')); if (!$ssh->login($this->param('username'), $this->param('password'))) { throw new \Deployer\TaskException('Can\'t connect to remote host'); } $scp = new \Net_SCP($ssh); $scp->put($this->param('dest'), file_get_contents($this->param('file'))); $info = sprintf('Filesize: %d bytes', filesize($this->param('file'))); return $this->info($info); }
/** * Execute task and return report info * * @return \Deployer\Task */ public function execute() { $file = \Deployer::applyGlobalParams($this->param('file')); if (!is_file($file)) { throw new \Deployer\TaskException(sprintf('file "%s" not found', $file)); } if (!is_readable($file)) { throw new \Deployer\TaskException(sprintf('file "%s" must be readable', $file)); } if (!is_writable($file)) { throw new \Deployer\TaskException(sprintf('file "%s" must be writable', $file)); } $contents = file_get_contents($file); file_put_contents($file, str_replace(':version', $this->_version(), $contents)); return $this; }
/** * Execute task and return report info * * @return \Deployer\Task */ public function execute() { $dir = \Deployer::applyGlobalParams($this->param('dir')); $allFiles = 0; foreach ($this->param('names') as $name) { $files = \Deployer::files($dir, \Deployer::applyGlobalParams($name)); foreach ($files as $file) { if (is_file($file)) { $mask = str_replace('*', null, $name); rename($file, str_replace($mask, null, $file)); $allFiles++; } } } $info = sprintf('%d files renamed', $allFiles); \Deployer::messageInfo($info); return $this->info($info); }
/** * Execute task and return report info * * @return \Deployer\Task */ public function execute() { $info = ''; foreach ($this->params() as $param => $value) { $this->_params[$param] = \Deployer::applyGlobalParams($value); } $ssh = new \Net_SSH2($this->param('host'), $this->param('port')); if (!$ssh->login($this->param('username'), $this->param('password'))) { throw new \Deployer\TaskException('Can\'t connect to remote host'); } foreach ((array) $this->param('cmd') as $cmd) { $command = 'cd ' . $this->param('directory') . ' && ' . $cmd; $command = \Deployer::applyGlobalParams($command); $result = $ssh->exec($command); $info .= '$ ' . $command . PHP_EOL . $result . PHP_EOL; } return $this->info($info); }
/** * Sends report * * @return \Deployer'\Logger\Provider\Smtp */ public function send() { $path = \Deployer::applyGlobalParams($this->param('path')); $path = str_replace('/', DIRECTORY_SEPARATOR, $path); try { if (is_file($path)) { unlink($path); } file_put_contents($path, $this->data()); $report = sprintf('report file saved: %s', $path); } catch (\Exception $e) { throw new \Deployer\ReportProviderException($e->getMessage()); } if (!empty($report)) { return $this->report($report); } return $this; }
/** * Обработка одного шага. * * @throw RollbackException * @param array $step */ function processStep($step) { if (!count($step)) { return; } switch ($cmd = array_shift($step)) { case 'delete': $this->delete($step); break; case 'move': break; case 'undeploy': Deployer::undeploy(Dir::get($step[0], true)); break; default: throw new RollbackException('Unknown command ' . $cmd); } return true; }
/** * Sends report * * @return \Deployer'\Logger\Provider\Smtp */ public function send() { foreach (array('host', 'port', 'encryption', 'username', 'password', 'subject', 'from') as $param) { $this->_params[$param] = \Deployer::applyGlobalParams($this->_params[$param]); } try { $transport = \Swift_SmtpTransport::newInstance($this->param('host'), $this->param('port'), $this->param('encryption'))->setUsername($this->param('username'))->setPassword($this->param('password')); $mailer = \Swift_Mailer::newInstance($transport); $message = \Swift_Message::newInstance()->setSubject($this->param('subject'))->setFrom($this->param('from'))->addPart($this->data(), $this->mime()); foreach ($this->param('to') as $to) { $message->setTo(\Deployer::applyGlobalParams($to)); } $report = sptintf('email sent to %d recipients: %s', sizeof($this->param('to')), implode(', ', $this->param('to'))); } catch (\Exception $e) { throw new \Deployer\ReportProviderException($e->getMessage()); } if (!$mailer->send($message)) { throw new \Deployer\ReportProviderException('mail not sent'); } if (!empty($report)) { return $this->report($report); } return $this; }
* * @var string */ define('ROOT', __DIR__ . DIRECTORY_SEPARATOR); require_once ROOT . 'Deployer.php'; mb_internal_encoding('UTF-8'); Deployer::registerAutoload(); // Show version info if (isset($argv[1]) && $argv[1] == '--version') { printHeader(); \Deployer\CLI::writeln(array(array('Version: ' . Deployer::VERSION . ', '))); return; } // Run deployer if (sizeof($argv) == 3 && $argv[1] == '-f') { Deployer::factory($argv[2])->execute()->report(); return; } // Show help information printHeader(); \Deployer\CLI::writeln(); \Deployer\CLI::writeln('Usage:'); \Deployer\CLI::writeln(' php deployer.phar -f /path/to/file.json'); /** * Prints Deployer header to Command Line * * @return void */ function printHeader() { \Deployer\CLI::writeln(array(array('Deployer', \Deployer\CLI::FG_GREEN), array(': Command Line tool for remote deploying. ')));
ini_set('memory_limit', '1024M'); ini_set('max_execution_time', '600'); set_time_limit(0); define('MAX_QUERY_ROWS', 100); define('MAX_DELETE_RECORDS', 1000); define('DEPLOY_LOG_FILE', 'oem-import.log'); $currentDir = dirname(__FILE__); $rootDir = dirname(dirname($currentDir)) . '/'; require $rootDir . 'Vic.php'; $debugSQLDump = isset($_GET['debug_sqldump']) && $_GET['debug_sqldump']; $debugImitateQuery = isset($_GET['debug_imitateQuery']) && $_GET['debug_imitateQuery']; $debugDumpSrcData = isset($_GET['debug_dumpSrcData']) && $_GET['debug_dumpSrcData']; $debugDumpColAssignment = isset($_GET['debug_cols']) && $_GET['debug_cols']; require_once $currentDir . '/functions.php'; require_once $currentDir . '/Deployer.php'; $deployer = new Deployer(); $deployer->initLog($rootDir . 'var/log/' . DEPLOY_LOG_FILE); require_once $currentDir . '/creds.php'; if ($deployer->initDb($dbhost, $dbUser, $dbPass, $dbName)) { $deployer->logMessage("DB init successful\n"); } else { die('DB init not successful'); } $params = $_GET; $fileName = $rootDir . ltrim($params['file'], ' /'); $rowsInsertedTotal = 0; $rowsTotal = 0; $rowsProcessed = 0; $rowsProcessedTotal = 0; $dataString = ''; $deployer->logMessage("Processing {$fileName}");
/** * Processes path param value * * @param string $paramValue * @return string */ protected function _processPathParam($paramValue) { return str_replace('/', DIRECTORY_SEPARATOR, \Deployer::applyGlobalParams($paramValue)); }
<?php // Require the deployer class require_once 'php-deployer.php'; $config = array('remote' => 'https://github.com/Swiper-CCCVI/php-github-deploy.git', 'target' => '/var/www/default', 'branch' => 'master', 'temp' => '/tmp/deploy', 'secret' => 'yoursecretaccesstoken', 'exclude' => '.exclude'); // Initialize the deployer $deployer = new Deployer($config); // Deploy the deployer $deployer->deploy(); // Log the deployer output $deployer->log_output('/var/log/deploy.log'); // Echo the deployer output $deployer->echo_output();
<?php require_once "DeploymentDAO.php"; require_once DEPLOYMENT_SCRIPTS . "/Applications.php"; // If this script is being called from the command line, // go ahead and try to deploy using the command line // arguments. if ("cli" == php_sapi_name()) { set_include_path(get_include_path() . PATH_SEPARATOR . "lib/phpseclib0"); $deployer = new Deployer(); if (count($argv) < 4) { echo "Usage: php Deployer.php APP environment [deployed by]\n"; exit; } if (!array_key_exists($argv[1], $application_configs)) { echo "Invalid application.\n"; exit; } $application = $application_configs[$argv[1]]; $deployer->deploy($application, $argv[2], $argv[3]); } class Deployer { var $dao; public function __construct($dao = null) { if (null == $dao) { $this->dao = new DeploymentDAO(); } else { $this->dao = $dao; }
$app->post('/deploy/{service}', function (Application $app, Request $request, $service) { if (isset($app['config'][$service])) { $config = $app['config'][$service]; $secret = $request->get("secret"); if ($secret != $config['secret']) { return new Response("Forbidden", 403, array('Content-Type' => 'text/plain')); } $deployer = new Deployer($service, $config); $stream = function () use($deployer, $request) { $deployer->deploy($request); }; return $app->stream($stream, 200, array('Content-Type' => 'text/plain')); } return "ERROR: missing service: " . $service; }); $app->post('/rollback/{service}', function (Application $app, Request $request, $service) { if (isset($app['config'][$service])) { $config = $app['config'][$service]; $secret = $request->get("secret"); if ($secret != $config['secret']) { return new Response("Forbidden", 403, array('Content-Type' => 'text/plain')); } $deployer = new Deployer($service, $config); $deployer->recursive_unlink($config['current_path']); if (!@rename($config['old_path'], $config['current_path'])) { $deployer->recurse_copy($config['old_path'], $config['current_path']); } return "Done!"; } }); $app->run();
/** * Send deployment report to dropbox account * * @return \Deployer */ public function report() { $reports = array(); $allReports = sizeof($this->_report); if ($allReports > 0) { self::messageHeader('Sending reports'); } foreach ($this->_report as $report) { $provider = $report['provider']; $format = isset($report['format']) ? $report['format'] : 'txt'; if (!isset($reports[$format])) { list($reports[$format]['mime'], $reports[$format]['data']) = $this->_logger->report($format); $reprts[$format]['data'] = \Deployer::censor($reports[$format]['data']); } $message = \Deployer\Report::instance($provider)->params($report)->mime($reports[$format]['mime'])->data($reports[$format]['data'])->send()->report(); \Deployer\CLI::writeLn(sprintf(' * %s', $message)); } if ($allReports > 0) { \Deployer\CLI::writeLn(); } return $this; }
/** * Удаление пакета */ static function uninstall($package) { $nvr = PackageManager::parseNRV($package); // проверка обратных зависимостей $res = Deps::isNoNeeded($nvr, $unstatisfied); if (count($res) == 0) { return IO::out('Packages to uninstall not found', IO::MESSAGE_FAIL); } if ($res === false) { io::out('Unable uninstall package ~WHITE~' . $nvr['name'] . '~~~ because', IO::MESSAGE_FAIL); foreach ($unstatisfied as $p => $d) { io::out('Package ' . $p . ' require ' . implode(', ', array_keys($d))); } return false; } io::out('Packages to be removed: ', false); foreach ($res as $p) { io::out($p->name . '(' . $p->version . ') ', false); } io::out(); if (IO::NO == io::dialog('Continue?', IO::YES | IO::NO, IO::NO)) { return 1; } foreach ($res as $p) { io::out('~WHITE~Undeploying ' . $p->name . '(' . $p->version . '):~~~'); $r = Deployer::undeploy(Deployer::getPackageRollbackDir($p)); if ($r || IO::OK != IO::dialog('Some part of rollback failed. Remove anyway?', IO::YES | IO::NO, IO::YES)) { Deployer::getPackageRollbackDir($p)->delete(); $p->file->delete(); PackageManager::get()->packagesSequence->removePackage($p->name, $p->version); } } }
* file that was distributed with this source code. */ namespace Deployer; desc('Preparing server for deploy'); task('deploy:prepare', function () { // Check if shell is POSIX-compliant try { cd(''); // To run command as raw. $result = run('echo $0')->toString(); if ($result == 'stdin: is not a tty') { throw new \RuntimeException("Looks like ssh inside another ssh.\n" . "Help: http://goo.gl/gsdLt9"); } } catch (\RuntimeException $e) { $formatter = Deployer::get()->getHelper('formatter'); $errorMessage = ["Shell on your server is not POSIX-compliant. Please change to sh, bash or similar.", "Usually, you can change your shell to bash by running: chsh -s /bin/bash"]; write($formatter->formatBlock($errorMessage, 'error', true)); throw $e; } run('if [ ! -d {{deploy_path}} ]; then mkdir -p {{deploy_path}}; fi'); // Check for existing /current directory (not symlink) $result = run('if [ ! -L {{deploy_path}}/current ] && [ -d {{deploy_path}}/current ]; then echo true; fi')->toBool(); if ($result) { throw new \RuntimeException('There already is a directory (not symlink) named "current" in ' . get('deploy_path') . '. Remove this directory so it can be replaced with a symlink for atomic deployments.'); } // Create metadata .dep dir. run("cd {{deploy_path}} && if [ ! -d .dep ]; then mkdir .dep; fi"); // Create releases dir. run("cd {{deploy_path}} && if [ ! -d releases ]; then mkdir releases; fi"); // Create shared dir.
public function initLog($fileName) { self::$_isCLIMode = php_sapi_name() == 'cli'; date_default_timezone_set('UTC'); $this->_logFileName = $fileName; $dirName = dirname($fileName); if (!file_exists($dirName)) { mkdir($dirName, 0755, true); } $this->_logFileName = $fileName; $this->logMessage('Deployment started, logging at ' . $fileName); }
public function initLog($fileName) { self::$_isCLIMode = php_sapi_name() == 'cli'; date_default_timezone_set('UTC'); $this->_logFileName = $fileName; $this->logMessage('Deployment started'); }
<?php ini_set('memory_limit', '1024M'); ini_set('max_execution_time', '600'); set_time_limit(0); define('MAX_QUERY_ROWS', 100); define('DEPLOY_LOG_FILE', 'import.log'); $rootDir = dirname(dirname(dirname(__FILE__))) . '/'; require $rootDir . 'Vic.php'; $debugMode = isset($_GET['debug']); require_once 'Deployer.php'; $deployer = new Deployer(); $deployer->initLog($rootDir . 'var/log/' . DEPLOY_LOG_FILE); require_once 'creds.php'; @(include_once 'credslocal.php'); // to override remote settings with the local ones if ($debugMode) { echo "HOST: {$dbhost}.<br/>USER: {$dbUser}<br/>DBNAME: {$dbName}<br/>"; } if ($deployer->initDb($dbhost, $dbUser, $dbPass, $dbName)) { $deployer->logMessage('DB init successful'); } else { $deployer->logMessage('DB init not successful'); die; } $tableFields = array('sku', 'd_punlim', 'd_trocky', 'd_wpower', 'd_polaris', 'd_canam', 'd_fox', 'd_hhouse', 'd_honda', 'd_kawasaki', 'd_seadoo', 'd_suzuki', 'd_yamaha', 'd_troylee', 'd_oakley', 'd_motonation', 'd_leatt', 'd_bellhelm'); $sourceDir = $rootDir . 'var/import/pulliver/sku/source'; $files = array(); if ($handle = opendir($sourceDir)) { while ($file = readdir($handle)) { $pathinfo = pathinfo($file);
<?php require_once "config.php"; require_once DEPLOYMENT_SCRIPTS . "/Applications.php"; require_once "Deployer.php"; require_once "DeploymentDAO.php"; // This page is only accessible via POST. if (!strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' && empty($_POST)) { header("Location: index.php"); exit; } $deployer = new Deployer(); $deploy_to = preg_replace("/push to /", "", $_POST['push_environment']); $application = $application_configs[$_POST['app']]; $deployment = $deployer->deploy($application, $deploy_to, $_SERVER['PHP_AUTH_USER'], $_POST['comment']); if (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { echo json_encode(array("result" => "success")); } else { header("Location: index.php"); }
/** @return Deployer */ private function createDeployer($config) { if (empty($config['remote']) || !($urlParts = parse_url($config['remote'])) || !isset($urlParts['scheme'], $urlParts['host'])) { throw new \Exception("Missing or invalid 'remote' URL in config."); } if (isset($config['user'])) { $urlParts['user'] = urlencode($config['user']); } if (isset($config['password'])) { $urlParts['pass'] = urlencode($config['password']); } $server = $urlParts['scheme'] === 'sftp' ? new SshServer($urlParts) : new FtpServer($urlParts, (bool) $config['passivemode']); if (!preg_match('#/|\\\\|[a-z]:#iA', $config['local'])) { if ($config['local'] && getcwd() !== dirname($this->configFile)) { $this->logger->log('WARNING: the "local" path is now relative to the directory where ' . basename($this->configFile) . ' is placed', 'red'); } $config['local'] = dirname($this->configFile) . '/' . $config['local']; } $deployment = new Deployer($server, $config['local'], $this->logger); if ($config['preprocess']) { $deployment->preprocessMasks = $config['preprocess'] == 1 ? ['*.js', '*.css'] : self::toArray($config['preprocess']); // intentionally == $preprocessor = new Preprocessor($this->logger); $deployment->addFilter('js', [$preprocessor, 'expandApacheImports']); $deployment->addFilter('js', [$preprocessor, 'compressJs'], TRUE); $deployment->addFilter('css', [$preprocessor, 'expandApacheImports']); $deployment->addFilter('css', [$preprocessor, 'expandCssImports']); $deployment->addFilter('css', [$preprocessor, 'compressCss'], TRUE); } $deployment->ignoreMasks = array_merge($this->ignoreMasks, self::toArray($config['ignore'])); $deployment->deploymentFile = empty($config['deploymentfile']) ? $deployment->deploymentFile : $config['deploymentfile']; $deployment->allowDelete = $config['allowdelete']; $deployment->toPurge = self::toArray($config['purge'], TRUE); $deployment->runBefore = self::toArray($config['before'], TRUE); $deployment->runAfterUpload = self::toArray($config['afterupload'], TRUE); $deployment->runAfter = self::toArray($config['after'], TRUE); $deployment->testMode = !empty($config['test']) || $this->mode === 'test'; return $deployment; }
<?php ini_set('memory_limit', '1024M'); ini_set('max_execution_time', '600'); set_time_limit(0); define('MAX_QUERY_ROWS', 100); define('DEPLOY_LOG_FILE', 'oem-import.log'); $currentDir = dirname(__FILE__); $rootDir = dirname(dirname($currentDir)) . '/'; require $rootDir . 'Vic.php'; $sqlDump = isset($_GET['sqldump']) && $_GET['sqldump']; require_once $currentDir . '/Deployer.php'; $deployer = new Deployer(); $deployer->initLog($rootDir . 'var/log/' . DEPLOY_LOG_FILE); require_once $currentDir . '/creds.php'; if ($deployer->initDb($dbhost, $dbUser, $dbPass, $dbName)) { $deployer->logMessage('DB init successful'); } else { die('DB init not successful'); } $files = array(); $importDir = $rootDir . 'var/import/pulliver/oem/'; if ($handle = opendir($importDir)) { while ($file = readdir($handle)) { $pathinfo = pathinfo($file); if ('csv' == @$pathinfo['extension']) { $files[] = $file; } } closedir($handle); } else {
/** * Размещение пакета * * @throws Exception if one of deploy task throws an exception */ function deploy() { // распаковть в buildpad $bp = PackageManager::getBuildpadDir()->getDir($this->name . '_' . $this->version); PackageManager::getRollback()->push('delete', $bp); Packer::unpack($this->file, $bp); // Вырезать нужный кусок их Package.xml $rp = new DOMXPath($this->xml); $nodes = $rp->query('//deploy'); if ($nodes->length == 0) { return io::out('Nothing to deploy') | 0; } $tasks = $nodes->item(0)->childNodes; // создать deployer $d = new Deployer($bp); $d->setTaskList($tasks); $d->executeTasks(); // удалить директорию в билдпаде $bp->delete(); }