public function perform() { set_time_limit(0); $log = new DeploynautLogFile($this->args['logfile']); $projects = DNProject::get()->filter('Name', Convert::raw2sql($this->args['projectName'])); $project = $projects->first(); $path = $project->getLocalCVSPath(); $env = $this->args['env']; $log->write('Starting git fetch for project "' . $project->Name . '"'); // if an alternate user has been configured for clone, run the command as that user // @todo Gitonomy doesn't seem to have any way to prefix the command properly, if you // set 'sudo -u composer git' as the "command" parameter, it tries to run the whole // thing as a single command and fails $user = DNData::inst()->getGitUser(); if (!empty($user)) { $command = sprintf('cd %s && sudo -u %s git fetch -p origin +refs/heads/*:refs/heads/* --tags', $path, $user); $process = new \Symfony\Component\Process\Process($command); $process->setEnv($env); $process->setTimeout(3600); $process->run(); if (!$process->isSuccessful()) { throw new RuntimeException($process->getErrorOutput()); } } else { $repository = new Gitonomy\Git\Repository($path, array('environment_variables' => $env)); $repository->run('fetch', array('-p', 'origin', '+refs/heads/*:refs/heads/*', '--tags')); } $log->write('Git fetch is finished'); }
public static function count($contents) { $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node " . KWF_PATH . "/Kwf/Assets/Util/CssSelectorCount.js"; $cmd .= " 2>&1"; $process = new Symfony\Component\Process\Process($cmd); $process->setEnv(array('NODE_PATH' => getcwd() . '/node_modules')); $process->setInput($contents); $process->mustRun(); $out = json_decode($process->getOutput(), true); return $out['selectors']; }
public function perform() { set_time_limit(0); $path = $this->args['path']; $repo = $this->args['repo']; $env = $this->args['env']; $logfile = DEPLOYNAUT_LOG_PATH . '/clonegitrepo.log'; $fh = fopen($logfile, 'a'); if (!$fh) { throw new RuntimeException(sprintf('Can\'t open file "%s" for logging.', $logfile)); } // if an alternate user has been configured for clone, run the command as that user $user = DNData::inst()->getGitUser(); if (file_exists($path)) { $command = array(); if (!empty($user)) { $command[] = sprintf('sudo -u %s', $user); } $command[] = sprintf('rm -rf %s', $path); fwrite($fh, sprintf('[%s] Cleaning up existing repository %s', date('Y-m-d H:i:s'), $path) . PHP_EOL); fwrite($fh, sprintf('[%s] Running command: %s', date('Y-m-d H:i:s'), implode(' ', $command)) . PHP_EOL); $process = new \Symfony\Component\Process\Process(implode(' ', $command)); $process->setEnv($env); $process->setTimeout(3600); $process->run(); if (!$process->isSuccessful()) { fwrite($fh, sprintf('[%s] Error cleaning up existing repository: %s', date('Y-m-d H:i:s'), $process->getErrorOutput()) . PHP_EOL); throw new RuntimeException($process->getErrorOutput()); } } fwrite($fh, sprintf('[%s] Cloning repository %s to %s', date('Y-m-d H:i:s'), $repo, $path) . PHP_EOL); echo "[-] CloneGitRepo starting" . PHP_EOL; $command = array(); if (!empty($user)) { $command[] = sprintf('sudo -u %s', $user); } $command[] = sprintf('git clone --bare -q %s %s', $repo, $path); fwrite($fh, sprintf('[%s] Running command: %s', date('Y-m-d H:i:s'), implode(' ', $command)) . PHP_EOL); $process = new \Symfony\Component\Process\Process(implode(' ', $command)); $process->setEnv($env); $process->setTimeout(3600); $process->run(); if (!$process->isSuccessful()) { fwrite($fh, sprintf('[%s] Error cloning repository %s to %s: %s', date('Y-m-d H:i:s'), $repo, $path, $process->getErrorOutput()) . PHP_EOL); throw new RuntimeException($process->getErrorOutput()); } fwrite($fh, sprintf('[%s] Successfully cloned repository %s to %s', date('Y-m-d H:i:s'), $repo, $path) . PHP_EOL); }
public function perform() { set_time_limit(0); $path = $this->args['path']; $repo = $this->args['repo']; $env = $this->args['env']; $logfile = DEPLOYNAUT_LOG_PATH . '/clonegitrepo.log'; $fh = fopen($logfile, 'a'); if (!$fh) { throw new RuntimeException('Can\'t open file "' . $logfile . '" for logging.'); } // if an alternate user has been configured for clone, run the command as that user $user = DNData::inst()->getGitUser(); if (file_exists($path)) { if ($user) { exec(sprintf('sudo -u %s rm -rf %s', $user, $path)); } else { exec(sprintf('rm -rf %s', $path)); } } fwrite($fh, '[' . date('Y-m-d H:i:s') . '] Cloning ' . $repo . ' to ' . $path . PHP_EOL); echo "[-] CloneGitRepo starting" . PHP_EOL; // using git clone straight via system call since doing it via the // Gitonomy\Git\Admin times out. Silly. if ($user) { $command = sprintf('sudo -u %s git clone --bare -q %s %s', $user, $repo, $path); } else { $command = sprintf('git clone --bare -q %s %s', $repo, $path); } fwrite($fh, '[' . date('Y-m-d H:i:s') . '] Running command: ' . $command . PHP_EOL); $process = new \Symfony\Component\Process\Process($command); $process->setEnv($env); $process->setTimeout(3600); $process->run(); if (!$process->isSuccessful()) { throw new RuntimeException($process->getErrorOutput()); } fwrite($fh, '[' . date('Y-m-d H:i:s') . '] Cloned ' . $repo . ' to ' . $path . PHP_EOL); }
/** * Run a shell command. * * @param string $command The command to run * @param string|null $workingDir The working dir to run command in * @throws RuntimeException */ protected function runCommand($command, $workingDir = null) { if (!empty($this->user)) { $command = sprintf('sudo -u %s %s', $this->user, $command); } if ($this->log) { $this->log->write(sprintf('Running command: %s', $command)); } $process = new \Symfony\Component\Process\Process($command, $workingDir); $process->setEnv($this->project->getProcessEnv()); $process->setTimeout(1800); $process->run(); if (!$process->isSuccessful()) { throw new RuntimeException($process->getErrorOutput()); } }