Inheritance: extends REBELinBLUE\Deployer\ProjectRelation, implements Robbo\Presenter\PresentableInterface, use trait Illuminate\Database\Eloquent\SoftDeletes, use trait REBELinBLUE\Deployer\Traits\BroadcastChanges
    public function run()
    {
        DB::table('projects')->delete();
        Project::create(['name' => 'Deployer', 'hash' => str_random(60), 'repository' => 'https://github.com/REBELinBLUE/deployer.git', 'url' => 'http://deployer.app', 'group_id' => 2, 'private_key' => '-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAmrMjtajVvmd99T8xwUNrIFbrzSmZ6VCM89hfm4Ut9atv29gG
l2HFPJY7VtslXDJVL67w5EUMspy82tkAX7F03iaarSsbo6nC16UTfbfNTi44Snm0
T/5RMavSOnOMRJ8BQcfzqge4oIQzVGXOs0YvNFdSt4paBp9dssKS+7yP/hDvgAVz
+LE3IcIeO26aXATcuB4zq3vjaqSzWZGdNhOJZ4EmjgmOq9+k3SAmooHkF+p/14MJ
tq0ZK9KjSGbHfyKMi2EuvwllFCY19eqsV7dcMDIsMKUW2diFC52dJSO+EF47nA/j
sNDisFsIC7DeeVVBl1TpaV9RidqeZmdx+mF9AQIDAQABAoIBAH4qhYAdTx03eGGw
hVqSKmc4nJ05RX4kJKCmoerLZh1LETJh75Y8tchg2cpPdhvILPNzoKD6s41kCR4P
BqAEsUSQhWufka4bwH1w8wGACp+tUFllAqqOxhdVg2IKZKZ+a18DvPS50ViQGPDH
CxnorozoftyTqDJofNlSmN9X/LN+RZ1zRJRaPkBvSkYOCT4gnJLmHLGN7eJsHQeR
EJe83E4VPZ+2faBHEigXAHc4rh63iRxmmqqlcrItXzONZZUOjXwBNqZs4aVl+DZd
1pPiB9nOT9zLiy9ZwHZfIRIF3LkWAVsIkzOPDw9wLNgzI60uiLlYY1ODua8maqDP
m5eOT7ECgYEAzbVdEVngZd/jRlAo/LOLyy6NbZP4fli26hZjJBAJ8HhI93JEcxts
l/1E3rUME2a+F8CQ5FlGP02k66sB5lhzCg81Ym4fxbIP1n09IPmaRz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n/Xgwm2rRkr0qNIZsd/IoyLYS6/CWUUJjX16qxXt1wwMiwwpRbZ2IULnZ0lI74QXjucD+Ow0OKw' . 'WwgLsN55VUGXVOlpX1GJ2p5mZ3H6YX0B deploy@deployer', 'last_run' => null, 'build_url' => 'http://ci.rebelinblue.com/build-status/image/3?branch=master', 'allow_other_branch' => true, 'include_dev' => false]);
    }
 public function run()
 {
     $laravel = Project::create(['name' => 'Laravel', 'is_template' => true, 'group_id' => 1]);
     Project::create(['name' => 'Wordpress', 'is_template' => true, 'group_id' => 1]);
     Command::create(['name' => 'Down', 'script' => 'php artisan down', 'project_id' => $laravel->id, 'user' => 'deploy', 'step' => Command::BEFORE_ACTIVATE]);
     Command::create(['name' => 'Run Migrations', 'script' => 'php artisan migrate --force', 'project_id' => $laravel->id, 'user' => 'deploy', 'step' => Command::BEFORE_ACTIVATE]);
     Command::create(['name' => 'Up', 'script' => 'php artisan up', 'project_id' => $laravel->id, 'user' => 'deploy', 'step' => Command::BEFORE_ACTIVATE]);
 }
 /**
  * Execute the command.
  */
 public function handle()
 {
     $emails = $this->project->notifyEmails;
     if ($emails->count() > 0) {
         $status = strtolower($this->project->getPresenter()->readable_status);
         $subject = Lang::get('notifyEmails.subject', ['status' => $status, 'project' => $this->project->name]);
         $deploymentArr = $this->deployment->toArray();
         $deploymentArr['commitURL'] = $this->deployment->commit_url;
         $deploymentArr['shortCommit'] = $this->deployment->short_commit;
         $data = ['project' => $this->project->toArray(), 'deployment' => $deploymentArr];
         Mail::queueOn('deployer-low', 'emails.deployed', $data, function (Message $message) use($emails, $subject) {
             foreach ($emails as $email) {
                 $message->to($email->email, $email->name);
             }
             $message->subject($subject);
         });
     }
 }
 /**
  * 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));
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  *
  * @dispatches UpdateGitMirror
  */
 public function handle()
 {
     $last_mirrored_since = Carbon::now()->subMinutes(self::UPDATE_FREQUENCY_MINUTES);
     $todo = self::UPDATES_TO_QUEUE;
     Project::where('last_mirrored', '<', $last_mirrored_since)->chunk($todo, function ($projects) {
         foreach ($projects as $project) {
             $this->dispatch(new UpdateGitMirror($project));
         }
     });
 }
 /**
  * Execute the command.
  */
 public function handle()
 {
     $template = Template::findOrFail($this->template_id);
     foreach ($template->commands as $command) {
         $data = $command->toArray();
         $this->project->commands()->create($data);
     }
     foreach ($template->variables as $variable) {
         $data = $variable->toArray();
         $this->project->variables()->create($data);
     }
     foreach ($template->sharedFiles as $file) {
         $data = $file->toArray();
         $this->project->sharedFiles()->create($data);
     }
     foreach ($template->configFiles as $file) {
         $data = $file->toArray();
         $this->project->configFiles()->create($data);
     }
 }
 /**
  * Cleans up any stalled deployments in the database.
  *
  * @tpdp Maybe readd pending to the queue if possible?
  * @return void
  */
 public function cleanupDeployments()
 {
     // Mark any pending steps as cancelled
     ServerLog::where('status', '=', ServerLog::PENDING)->update(['status' => ServerLog::CANCELLED]);
     // Mark any running steps as failed
     ServerLog::where('status', '=', ServerLog::RUNNING)->update(['status' => ServerLog::FAILED]);
     // Mark any running/pending deployments as failed
     Deployment::whereIn('status', [Deployment::DEPLOYING, Deployment::PENDING])->update(['status' => Deployment::FAILED]);
     // Mark any deploying/pending projects as failed
     Project::whereIn('status', [Project::DEPLOYING, Project::PENDING])->update(['status' => Project::FAILED]);
 }
 /**
  * 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']);
             }
         }
     }
 }
Exemple #9
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $template = Project::findOrFail($this->template_id);
     foreach ($template->commands as $command) {
         $data = $command->toArray();
         $data['project_id'] = $this->project->id;
         Command::create($data);
     }
     foreach ($template->sharedFiles as $file) {
         $data = $file->toArray();
         $data['project_id'] = $this->project->id;
         SharedFile::create($data);
     }
     foreach ($template->projectFiles as $file) {
         $data = $file->toArray();
         $data['project_id'] = $this->project->id;
         ProjectFile::create($data);
     }
 }
 /**
  * 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));
         }
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     foreach ($this->relations as $relation) {
         $className = "REBELinBLUE\\Deployer\\{$relation}";
         $instance = new $className();
         $table = $instance->getTable();
         // Add the target fields to the tables
         Schema::table($table, function (Blueprint $table) {
             $table->integer('target_id')->nullable();
             $table->string('target_type')->nullable();
         });
         if (config('database.default') !== 'sqlite') {
             $drop = config('database.default') === 'mysql' ? 'FOREIGN KEY' : 'CONSTRAINT';
             DB::statement("ALTER TABLE {$table} DROP {$drop} {$table}_project_id_foreign");
         }
     }
     // Now find the existing templates in the project template and move them to templates table
     $templates = [];
     foreach (Project::where('is_template', true)->get() as $project) {
         $data = $project->toArray();
         unset($data['id']);
         $templates[$project->id] = Template::create($data);
     }
     // Now loop through the relations and set the target details
     foreach ($this->relations as $relation) {
         $className = "REBELinBLUE\\Deployer\\{$relation}";
         $instance = new $className();
         foreach ($instance->all() as $row) {
             $row->target_id = $row->project_id;
             $row->target_type = 'project';
             if (isset($templates[$row->project_id])) {
                 $row->target_id = $templates[$row->project_id]->id;
                 $row->target_type = 'template';
             }
             $row->save();
         }
     }
     // Remove any deleted non templates from group 1 to group 2
     $project = new Project();
     $project->where('is_template', false)->where('group_id', 1)->withTrashed()->update(['group_id' => 2]);
     // Remove the left over fake templates and the containing group
     Project::where('is_template', true)->forceDelete();
     Group::find(1)->forceDelete();
     // Remove the unneeded project ID column
     foreach ($this->relations as $relation) {
         $className = "REBELinBLUE\\Deployer\\{$relation}";
         $instance = new $className();
         $table = $instance->getTable();
         // You can't drop a column in SQLite
         if (config('database.default') !== 'sqlite') {
             DB::statement("ALTER TABLE {$table} DROP COLUMN project_id");
         }
         if (config('database.default') === 'mysql') {
             DB::statement("ALTER TABLE {$table} MODIFY target_id INT(11) NOT NULL");
             DB::statement("ALTER TABLE {$table} MODIFY target_type VARCHAR(255) NOT NULL");
         } elseif (config('database.default') === 'pgsql') {
             DB::statement("ALTER TABLE {$table} ALTER COLUMN target_id SET NOT NULL");
             DB::statement("ALTER TABLE {$table} ALTER COLUMN target_type SET NOT NULL");
         }
     }
 }