コード例 #1
0
 /**
  * Execute the job.
  * @throws \RuntimeException
  * @dispatches UpdateGitReferences
  */
 public function handle()
 {
     $private_key = tempnam(storage_path('app/'), 'sshkey');
     file_put_contents($private_key, $this->project->private_key);
     $wrapper = with(new ScriptParser())->parseFile('tools.SSHWrapperScript', ['private_key' => $private_key]);
     $wrapper_file = tempnam(storage_path('app/'), 'gitssh');
     file_put_contents($wrapper_file, $wrapper);
     $process = new Process('tools.MirrorGitRepository', ['wrapper_file' => $wrapper_file, 'mirror_path' => $this->project->mirrorPath(), 'repository' => $this->project->repository]);
     $process->run();
     unlink($wrapper_file);
     unlink($private_key);
     if (!$process->isSuccessful()) {
         throw new \RuntimeException('Could not mirror repository - ' . $process->getErrorOutput());
     }
     $this->project->last_mirrored = date('Y-m-d H:i:s');
     $this->project->save();
     $this->dispatch(new UpdateGitReferences($this->project));
 }
コード例 #2
0
 /**
  * Execute the command.
  */
 public function handle()
 {
     $this->server->status = Server::TESTING;
     $this->server->save();
     $key = tempnam(storage_path('app/'), 'sshkey');
     file_put_contents($key, $this->server->project->private_key);
     try {
         $process = new Process('TestServerConnection', ['project_path' => $this->server->clean_path, 'test_file' => time() . '_testing_deployer.txt', 'test_directory' => time() . '_testing_deployer_dir']);
         $process->setServer($this->server, $key)->run();
         if (!$process->isSuccessful()) {
             $this->server->status = Server::FAILED;
         } else {
             $this->server->status = Server::SUCCESSFUL;
         }
     } catch (\Exception $error) {
         $this->server->status = Server::FAILED;
     }
     $this->server->save();
     unlink($key);
 }
コード例 #3
0
 /**
  * Execute the job.
  */
 public function handle()
 {
     $mirror_dir = $this->project->mirrorPath();
     $this->project->refs()->delete();
     foreach (['tag', 'branch'] as $ref) {
         $process = new Process('tools.ListGitReferences', ['mirror_path' => $mirror_dir, 'git_reference' => $ref]);
         $process->run();
         if ($process->isSuccessful()) {
             foreach (explode(PHP_EOL, trim($process->getOutput())) as $reference) {
                 $reference = trim($reference);
                 if (empty($reference)) {
                     continue;
                 }
                 if (substr($reference, 0, 1) === '*') {
                     $reference = trim(substr($reference, 1));
                 }
                 Ref::create(['name' => $reference, 'project_id' => $this->project->id, 'is_tag' => $ref === 'tag']);
             }
         }
     }
 }
コード例 #4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $current_mirrors = [];
     Project::where('is_template', false)->chunk(10, function ($projects) use(&$current_mirrors) {
         foreach ($projects as $project) {
             $current_mirrors[] = $project->mirrorPath();
         }
     });
     $current_mirrors = collect($current_mirrors);
     $all_mirrors = collect(glob(storage_path('app/mirrors/') . '*.git'));
     // Compare the 2 collections get a list of mirrors which are no longer in use
     $orphan_mirrors = $all_mirrors->diff($current_mirrors);
     $this->info('Found ' . $orphan_mirrors->count() . ' orphaned mirrors');
     // Now loop through the mirrors and delete them from storage
     foreach ($orphan_mirrors as $mirror_dir) {
         $process = new Process('tools.RemoveMirrorDirectory', ['mirror_path' => $mirror_dir]);
         $process->run();
         if ($process->isSuccessful()) {
             $this->info('Deleted ' . basename($mirror_dir));
         } else {
             $this->info('Failed to delete ' . basename($mirror_dir));
         }
     }
 }
コード例 #5
0
ファイル: DeployProject.php プロジェクト: JamesForks/deployer
 /**
  * Sends a file to a remote server.
  *
  * @param string $local_file
  * @param string $remote_file
  * @param ServerLog $log
  *
  * @throws \RuntimeException
  */
 private function sendFile($local_file, $remote_file, ServerLog $log)
 {
     $process = new Process('deploy.SendFileToServer', ['port' => $log->server->port, 'private_key' => $this->private_key, 'local_file' => $local_file, 'remote_file' => $remote_file, 'username' => $log->server->user, 'ip_address' => $log->server->ip_address]);
     $output = '';
     $process->run(function ($type, $output_line) use(&$output, &$log) {
         if ($type === \Symfony\Component\Process\Process::ERR) {
             $output .= $this->logError($output_line);
         } else {
             // Switching sent/received around
             $output_line = str_replace('received', 'xxx', $output_line);
             $output_line = str_replace('sent', 'received', $output_line);
             $output_line = str_replace('xxx', 'sent', $output_line);
             $output .= $this->logSuccess($output_line);
         }
         $log->output = $output;
         $log->save();
     });
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
 }
コード例 #6
0
ファイル: Project.php プロジェクト: JamesForks/deployer
 /**
  * Generates an SSH key and sets the private/public key properties.
  */
 protected function regeneratePublicKey()
 {
     $key = tempnam(storage_path('app/'), 'sshkey');
     file_put_contents($key, $this->private_key);
     $process = new Process('tools.RegeneratePublicSSHKey', ['key_file' => $key]);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     $this->attributes['public_key'] = file_get_contents($key . '.pub');
     unlink($key);
     unlink($key . '.pub');
 }