diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index e135188a7..f37ee5e49 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -66,6 +66,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted private Server $mainServer; private ?ApplicationPreview $preview = null; private ?string $git_type = null; + private bool $only_this_server = false; private string $container_name; private ?string $currently_running_container_name = null; @@ -115,6 +116,7 @@ public function __construct(int $application_deployment_queue_id) $this->commit = $this->application_deployment_queue->commit; $this->force_rebuild = $this->application_deployment_queue->force_rebuild; $this->restart_only = $this->application_deployment_queue->restart_only; + $this->only_this_server = $this->application_deployment_queue->only_this_server; $this->git_type = data_get($this->application_deployment_queue, 'git_type'); @@ -887,7 +889,7 @@ private function deploy_to_additional_destinations() destination: $destination, no_questions_asked: true, ); - $this->application_deployment_queue->addLogEntry("Deploying to additional server: {$server->name}. Click here to see the deployment status: " . route('project.application.deployment.show', [ + $this->application_deployment_queue->addLogEntry("Deployment to {$server->name}. Logs: " . route('project.application.deployment.show', [ 'project_uuid' => data_get($this->application, 'environment.project.uuid'), 'application_uuid' => data_get($this->application, 'uuid'), 'deployment_uuid' => $deployment_uuid, @@ -1619,7 +1621,9 @@ private function next(string $status) return; } if ($status === ApplicationDeploymentStatus::FINISHED->value) { - $this->deploy_to_additional_destinations(); + if (!$this->only_this_server) { + $this->deploy_to_additional_destinations(); + } $this->application->environment->project->team?->notify(new DeploymentSuccess($this->application, $this->deployment_uuid, $this->preview)); } } diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index 1612e2191..fbdd555a1 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -44,17 +44,19 @@ public function uniqueId(): int public function handle() { $applications = $this->server->applications(); + $skip_these_applications = collect([]); foreach ($applications as $application) { if ($application->additional_servers->count() > 0) { - $is_main_server = $application->destination->server->id === $this->server->id; - if ($is_main_server) { - ComplexStatusCheck::run($application); - $applications = $applications->filter(function ($value, $key) use ($application) { - return $value->id !== $application->id; - }); - } + $skip_these_applications->push($application); + ComplexStatusCheck::run($application); + $applications = $applications->filter(function ($value, $key) use ($application) { + return $value->id !== $application->id; + }); } } + $applications = $applications->filter(function ($value, $key) use ($skip_these_applications) { + return !$skip_these_applications->pluck('id')->contains($value->id); + }); if (!$this->server->isFunctional()) { return 'Server is not ready.'; diff --git a/app/Livewire/Project/Application/Heading.php b/app/Livewire/Project/Application/Heading.php index 01ab13c4e..3047f9f23 100644 --- a/app/Livewire/Project/Application/Heading.php +++ b/app/Livewire/Project/Application/Heading.php @@ -33,15 +33,11 @@ public function check_status($showNotification = false) { if ($this->application->destination->server->isFunctional()) { dispatch(new ContainerStatusJob($this->application->destination->server)); - // $this->application->refresh(); - // $this->application->previews->each(function ($preview) { - // $preview->refresh(); - // }); } else { dispatch(new ServerStatusJob($this->application->destination->server)); } - if ($showNotification) $this->dispatch('success', "Application status updated."); + if ($showNotification) $this->dispatch('success', "Success", "Application status updated."); } public function force_deploy_without_cache() diff --git a/app/Livewire/Project/Database/Heading.php b/app/Livewire/Project/Database/Heading.php index 303166227..ed31f8cae 100644 --- a/app/Livewire/Project/Database/Heading.php +++ b/app/Livewire/Project/Database/Heading.php @@ -38,7 +38,7 @@ public function check_status($showNotification = false) { dispatch_sync(new ContainerStatusJob($this->database->destination->server)); $this->database->refresh(); - if ($showNotification) $this->dispatch('success', 'Database status updated.'); + if ($showNotification) $this->dispatch('success', 'Success', 'Database status updated.'); } public function mount() diff --git a/app/Livewire/Project/Shared/Destination.php b/app/Livewire/Project/Shared/Destination.php index 75a56c1a2..787b9da20 100644 --- a/app/Livewire/Project/Shared/Destination.php +++ b/app/Livewire/Project/Shared/Destination.php @@ -4,6 +4,7 @@ use App\Actions\Application\StopApplicationOneServer; use App\Events\ApplicationStatusChanged; +use App\Jobs\ContainerStatusJob; use App\Models\Server; use App\Models\StandaloneDocker; use Livewire\Component; @@ -19,7 +20,6 @@ public function getListeners() $teamId = auth()->user()->currentTeam()->id; return [ "echo-private:team.{$teamId},ApplicationStatusChanged" => 'loadData', - "loadData", ]; } public function mount() @@ -41,9 +41,17 @@ public function loadData() $this->networks = $this->networks->reject(function ($network) { return $this->resource->destination->server->id == $network->server->id; }); - $this->networks = $this->networks->reject(function ($network) { - return $this->resource->additional_servers->pluck('id')->contains($network->server->id); - }); + if ($this->resource?->additional_servers?->count() > 0) { + $this->networks = $this->networks->reject(function ($network) { + return $this->resource->additional_servers->pluck('id')->contains($network->server->id); + }); + } + } + public function stop(int $server_id) + { + $server = Server::find($server_id); + StopApplicationOneServer::run($this->resource, $server); + $this->refreshServers(); } public function redeploy(int $network_id, int $server_id) { @@ -59,6 +67,7 @@ public function redeploy(int $network_id, int $server_id) application: $this->resource, server: $server, destination: $destination, + only_this_server: true, no_questions_asked: true, ); return redirect()->route('project.application.deployment.show', [ @@ -68,11 +77,28 @@ public function redeploy(int $network_id, int $server_id) 'environment_name' => data_get($this->resource, 'environment.name'), ]); } + public function promote(int $network_id, int $server_id) + { + $main_destination = $this->resource->destination; + $this->resource->update([ + 'destination_id' => $network_id, + 'destination_type' => StandaloneDocker::class, + ]); + $this->resource->additional_networks()->detach($network_id, ['server_id' => $server_id]); + $this->resource->additional_networks()->attach($main_destination->id, ['server_id' => $main_destination->server->id]); + $this->refreshServers(); + } + public function refreshServers() + { + ContainerStatusJob::dispatchSync($this->resource->destination->server); + $this->loadData(); + $this->dispatch('refresh'); + ApplicationStatusChanged::dispatch(data_get($this->resource, 'environment.project.team.id')); + } public function addServer(int $network_id, int $server_id) { $this->resource->additional_networks()->attach($network_id, ['server_id' => $server_id]); - $this->resource->load(['additional_networks']); - $this->dispatch('loadData'); + $this->loadData(); ApplicationStatusChanged::dispatch(data_get($this->resource, 'environment.project.team.id')); } public function removeServer(int $network_id, int $server_id) @@ -84,8 +110,7 @@ public function removeServer(int $network_id, int $server_id) $server = Server::find($server_id); StopApplicationOneServer::run($this->resource, $server); $this->resource->additional_networks()->detach($network_id, ['server_id' => $server_id]); - $this->resource->load(['additional_networks']); - $this->dispatch('loadData'); + $this->loadData(); ApplicationStatusChanged::dispatch(data_get($this->resource, 'environment.project.team.id')); } } diff --git a/app/Models/Application.php b/app/Models/Application.php index b3838608f..7ebabf1b4 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -6,7 +6,6 @@ use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; -use Illuminate\Support\Collection; use Spatie\Activitylog\Models\Activity; use Illuminate\Support\Str; use RuntimeException; @@ -274,15 +273,11 @@ public function status(): Attribute foreach ($additional_servers_status as $status) { $server_status = str($status)->before(':')->value(); $server_health = str($status)->after(':')->value() ?? 'unhealthy'; - if ($server_status !== 'running') { - if ($main_server_status !== $server_status) { - $complex_status = 'degraded'; - } + if ($main_server_status !== $server_status) { + $complex_status = 'degraded'; } - if ($server_health !== 'healthy') { - if ($main_server_health !== $server_health) { - $complex_health = 'unhealthy'; - } + if ($main_server_health !== $server_health) { + $complex_health = 'unhealthy'; } } return "$complex_status:$complex_health"; diff --git a/app/View/Components/Status/Index.php b/app/View/Components/Status/Index.php index a7128c7fd..0ee009257 100644 --- a/app/View/Components/Status/Index.php +++ b/app/View/Components/Status/Index.php @@ -11,11 +11,12 @@ class Index extends Component /** * Create a new component instance. */ + public $status = "exited:unhealthy"; public function __construct( - public string $status = 'exited', - ) - { - // + public $resource = null, + public bool $showRefreshButton = true, + ) { + $this->status = $resource->status; } /** diff --git a/bootstrap/helpers/applications.php b/bootstrap/helpers/applications.php index f921c2df8..bf3f15514 100644 --- a/bootstrap/helpers/applications.php +++ b/bootstrap/helpers/applications.php @@ -8,7 +8,7 @@ use App\Models\StandaloneDocker; use Spatie\Url\Url; -function queue_application_deployment(Application $application, string $deployment_uuid, int | null $pull_request_id = 0, string $commit = 'HEAD', bool $force_rebuild = false, bool $is_webhook = false, bool $restart_only = false, ?string $git_type = null, bool $no_questions_asked = false, Server $server = null, StandaloneDocker $destination = null) +function queue_application_deployment(Application $application, string $deployment_uuid, int | null $pull_request_id = 0, string $commit = 'HEAD', bool $force_rebuild = false, bool $is_webhook = false, bool $restart_only = false, ?string $git_type = null, bool $no_questions_asked = false, Server $server = null, StandaloneDocker $destination = null, bool $only_this_server = false) { $application_id = $application->id; $deployment_link = Url::fromString($application->link() . "/deployment/{$deployment_uuid}"); @@ -37,7 +37,8 @@ function queue_application_deployment(Application $application, string $deployme 'is_webhook' => $is_webhook, 'restart_only' => $restart_only, 'commit' => $commit, - 'git_type' => $git_type + 'git_type' => $git_type, + 'only_this_server' => $only_this_server ]); if ($no_questions_asked) { diff --git a/database/migrations/2024_02_22_090900_add_only_this_server_deployment.php b/database/migrations/2024_02_22_090900_add_only_this_server_deployment.php new file mode 100644 index 000000000..8dd9e1031 --- /dev/null +++ b/database/migrations/2024_02_22_090900_add_only_this_server_deployment.php @@ -0,0 +1,28 @@ +boolean('only_this_server')->default(false); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('application_deployment_queues', function (Blueprint $table) { + $table->dropColumn('only_this_server'); + }); + } +}; diff --git a/resources/views/components/resources/breadcrumbs.blade.php b/resources/views/components/resources/breadcrumbs.blade.php index baa46fa91..6e2b234a3 100644 --- a/resources/views/components/resources/breadcrumbs.blade.php +++ b/resources/views/components/resources/breadcrumbs.blade.php @@ -41,7 +41,7 @@ @if ($resource->getMorphClass() == 'App\Models\Service') @else - + @endif diff --git a/resources/views/components/status/index.blade.php b/resources/views/components/status/index.blade.php index 12827eaca..71596b8bd 100644 --- a/resources/views/components/status/index.blade.php +++ b/resources/views/components/status/index.blade.php @@ -1,4 +1,3 @@ -@props(['status', 'showRefreshButton' => true]) @if (str($status)->startsWith('running')) @elseif(str($status)->startsWith('restarting') || @@ -6,7 +5,7 @@ str($status)->startsWith('degraded')) @else - + @endif @if (!str($status)->contains('exited') && $showRefreshButton) diff --git a/resources/views/livewire/project/application/deployment-navbar.blade.php b/resources/views/livewire/project/application/deployment-navbar.blade.php index b499b66c2..effb6b6fe 100644 --- a/resources/views/livewire/project/application/deployment-navbar.blade.php +++ b/resources/views/livewire/project/application/deployment-navbar.blade.php @@ -12,5 +12,4 @@ data_get($application_deployment_queue, 'status') === 'queued') Cancel @endif - diff --git a/resources/views/livewire/project/application/deployment/show.blade.php b/resources/views/livewire/project/application/deployment/show.blade.php index 257cf7a1a..cc31d625d 100644 --- a/resources/views/livewire/project/application/deployment/show.blade.php +++ b/resources/views/livewire/project/application/deployment/show.blade.php @@ -51,12 +51,17 @@ class="fixed top-4 right-16" x-on:click="toggleScroll">count() > 0) @foreach (decode_remote_command_output($application_deployment_queue) as $line)
$line['hidden'], 'text-red-500' => $line['type'] == 'stderr', ])>[{{ $line['timestamp'] }}] @if ($line['hidden'])
COMMAND:
{{ $line['command'] }}

OUTPUT: - @endif{{ $line['output'] }}@if ($line['hidden']) + @endif @if (str($line['output'])->contains('http://') || str($line['output'])->contains('https://')) + @php + $line['output'] = preg_replace('/(https?:\/\/[^\s]+)/', '$1', $line['output']); + @endphp {!! $line['output'] !!} + @else + {{ $line['output'] }} @endif
@endforeach diff --git a/resources/views/livewire/project/application/heading.blade.php b/resources/views/livewire/project/application/heading.blade.php index 64fc09c96..4bef4043c 100644 --- a/resources/views/livewire/project/application/heading.blade.php +++ b/resources/views/livewire/project/application/heading.blade.php @@ -1,4 +1,4 @@ -