deployment = $this->application->deployments()->create([ 'status' => DeploymentStatus::PENDING, ]); foreach ($this->application->instances as $instance) { $step = $this->deployment->steps()->create([ 'name' => "Deploy to {$instance->server->name}", 'order' => $instance->id, 'status' => DeploymentStatus::PENDING, 'script' => $this->getDeploymentScript($instance), 'secrets' => [], ]); $step->dispatchJob(); } } protected function getDeploymentScript($instance): string { return "#!/bin/bash\n" . "cd /opt/apps/{$this->application->name}-{$instance->id}\n" . "git fetch origin\n" . "git checkout {$instance->branch}\n" . "git pull origin {$instance->branch}\n"; } public function failed(\Throwable $exception): void { if (isset($this->deployment)) { $this->deployment->update([ 'status' => DeploymentStatus::FAILED, ]); } } }