diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index becf6387a..8ecaacc98 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -727,7 +727,7 @@ private function rolling_update() $this->write_deployment_configurations(); $this->server = $this->original_server; } - if (count($this->application->ports_mappings_array) > 0 || (bool) $this->application->settings->is_consistent_container_name_enabled || $this->application->pull_request_id !== 0) { + if (count($this->application->ports_mappings_array) > 0 || (bool) $this->application->settings->is_consistent_container_name_enabled || $this->pull_request_id !== 0) { $this->application_deployment_queue->addLogEntry("----------------------------------------"); if (count($this->application->ports_mappings_array) > 0) { $this->application_deployment_queue->addLogEntry("Application has ports mapped to the host system, rolling update is not supported."); @@ -735,7 +735,7 @@ private function rolling_update() if ((bool) $this->application->settings->is_consistent_container_name_enabled) { $this->application_deployment_queue->addLogEntry("Consistent container name feature enabled, rolling update is not supported."); } - if ($this->application->pull_request_id !== 0) { + if ($this->pull_request_id !== 0) { $this->application->settings->is_consistent_container_name_enabled = true; $this->application_deployment_queue->addLogEntry("Pull request deployment, rolling update is not supported."); } @@ -1215,7 +1215,7 @@ private function generate_compose_file() // ]; // } - if ($this->application->pull_request_id === 0) { + if ($this->pull_request_id === 0) { if ((bool)$this->application->settings->is_consistent_container_name_enabled) { $custom_compose = convert_docker_run_to_compose($this->application->custom_docker_run_options); if (count($custom_compose) > 0) { diff --git a/app/Livewire/Project/Shared/ExecuteContainerCommand.php b/app/Livewire/Project/Shared/ExecuteContainerCommand.php index a33716e72..7af7576bd 100644 --- a/app/Livewire/Project/Shared/ExecuteContainerCommand.php +++ b/app/Livewire/Project/Shared/ExecuteContainerCommand.php @@ -10,29 +10,21 @@ use App\Models\StandaloneMysql; use App\Models\StandalonePostgresql; use App\Models\StandaloneRedis; +use Illuminate\Support\Collection; use Livewire\Component; class ExecuteContainerCommand extends Component { public string $command; public string $container; - public $containers; + public Collection $containers; public $parameters; public $resource; public string $type; public string $workDir = ''; public Server $server; - public $servers = []; - public function getListeners() - { - return [ - "serviceStatusChanged", - ]; - } - public function serviceStatusChanged() - { - $this->getContainers(); - } + public Collection $servers; + protected $rules = [ 'server' => 'required', 'container' => 'required', @@ -43,20 +35,18 @@ public function serviceStatusChanged() public function mount() { $this->parameters = get_route_parameters(); - $this->getContainers(); - } - public function getContainers() - { $this->containers = collect(); + $this->servers = collect(); if (data_get($this->parameters, 'application_uuid')) { $this->type = 'application'; $this->resource = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail(); - $this->server = $this->resource->destination->server; - $containers = getCurrentApplicationContainerStatus($this->server, $this->resource->id, 0); - if ($containers->count() > 0) { - $containers->each(function ($container) { - $this->containers->push(str_replace('/', '', $container['Names'])); - }); + if ($this->resource->destination->server->isFunctional()) { + $this->servers = $this->servers->push($this->resource->destination->server); + } + foreach ($this->resource->additional_servers as $server) { + if ($server->isFunctional()) { + $this->servers = $this->servers->push($server); + } } } else if (data_get($this->parameters, 'database_uuid')) { $this->type = 'database'; @@ -77,47 +67,85 @@ public function getContainers() } } $this->resource = $resource; - $this->server = $this->resource->destination->server; + if ($this->resource->destination->server->isFunctional()) { + $this->servers = $this->servers->push($this->resource->destination->server); + } $this->container = $this->resource->uuid; - // if (!str(data_get($this,'resource.status'))->startsWith('exited')) { - $this->containers->push($this->container); - // } + $this->containers->push($this->container); } else if (data_get($this->parameters, 'service_uuid')) { $this->type = 'service'; $this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail(); $this->resource->applications()->get()->each(function ($application) { - // if (str(data_get($application, 'status'))->contains('running')) { - $this->containers->push(data_get($application, 'name') . '-' . data_get($this->resource, 'uuid')); - // } + $this->containers->push(data_get($application, 'name') . '-' . data_get($this->resource, 'uuid')); }); $this->resource->databases()->get()->each(function ($database) { - // if (str(data_get($database, 'status'))->contains('running')) { - $this->containers->push(data_get($database, 'name') . '-' . data_get($this->resource, 'uuid')); - // } + $this->containers->push(data_get($database, 'name') . '-' . data_get($this->resource, 'uuid')); }); - - $this->server = $this->resource->server; + if ($this->resource->server->isFunctional()) { + $this->servers = $this->servers->push($this->resource->server); + } } if ($this->containers->count() > 0) { $this->container = $this->containers->first(); } } + public function loadContainers() + { + foreach ($this->servers as $server) { + if (data_get($this->parameters, 'application_uuid')) { + if ($server->isSwarm()) { + $containers = collect([ + [ + 'Names' => $this->resource->uuid . '_' . $this->resource->uuid, + ] + ]); + } else { + $containers = getCurrentApplicationContainerStatus($server, $this->resource->id, includePullrequests: true); + } + foreach ($containers as $container) { + $payload = [ + 'server' => $server, + 'container' => $container, + ]; + $this->containers = $this->containers->push($payload); + } + } + } + if ($this->containers->count() > 0) { + if (data_get($this->parameters, 'application_uuid')) { + $this->container = data_get($this->containers->first(), 'container.Names'); + } elseif (data_get($this->parameters, 'database_uuid')) { + $this->container = $this->containers->first(); + } elseif (data_get($this->parameters, 'service_uuid')) { + $this->container = $this->containers->first(); + } + } + } public function runCommand() { - $this->validate(); try { - if ($this->server->isForceDisabled()) { + if (data_get($this->parameters, 'application_uuid')) { + $container = $this->containers->where('container.Names', $this->container)->first(); + $container_name = data_get($container, 'container.Names'); + if (is_null($container)) { + throw new \RuntimeException('Container not found.'); + } + $server = data_get($container, 'server'); + } else { + $container_name = $this->container; + $server = $this->servers->first(); + } + if ($server->isForceDisabled()) { throw new \RuntimeException('Server is disabled.'); } - // Wrap command to prevent escaped execution in the host. $cmd = 'sh -c "if [ -f ~/.profile ]; then . ~/.profile; fi; ' . str_replace('"', '\"', $this->command) . '"'; if (!empty($this->workDir)) { - $exec = "docker exec -w {$this->workDir} {$this->container} {$cmd}"; + $exec = "docker exec -w {$this->workDir} {$container_name} {$cmd}"; } else { - $exec = "docker exec {$this->container} {$cmd}"; + $exec = "docker exec {$container_name} {$cmd}"; } - $activity = remote_process([$exec], $this->server, ignore_errors: true); + $activity = remote_process([$exec], $server, ignore_errors: true); $this->dispatch('activityMonitor', $activity->id); } catch (\Throwable $e) { return handleError($e, $this); diff --git a/app/Livewire/Project/Shared/Logs.php b/app/Livewire/Project/Shared/Logs.php index 3b9a121b8..3070e6dcd 100644 --- a/app/Livewire/Project/Shared/Logs.php +++ b/app/Livewire/Project/Shared/Logs.php @@ -10,50 +10,57 @@ use App\Models\StandaloneMysql; use App\Models\StandalonePostgresql; use App\Models\StandaloneRedis; +use Illuminate\Support\Collection; use Livewire\Component; class Logs extends Component { public ?string $type = null; public Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb|StandaloneMysql|StandaloneMariadb $resource; - public Server $server; + public Collection $servers; + public Collection $containers; public $container = []; - public $containers; public $parameters; public $query; public $status; public $serviceSubType; - public function mount() + public function loadContainers($server_id) { - $this->containers = collect(); - $this->parameters = get_route_parameters(); - $this->query = request()->query(); - if (data_get($this->parameters, 'application_uuid')) { - $this->type = 'application'; - $this->resource = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail(); - $this->status = $this->resource->status; - $this->server = $this->resource->destination->server; - if ($this->server->isSwarm()) { + try { + $server = $this->servers->firstWhere('id', $server_id); + if ($server->isSwarm()) { $containers = collect([ [ 'Names' => $this->resource->uuid . '_' . $this->resource->uuid, ] ]); } else { - $containers = getCurrentApplicationContainerStatus($this->server, $this->resource->id, includePullrequests: true); + $containers = getCurrentApplicationContainerStatus($server, $this->resource->id, includePullrequests: true); } - if ($containers->count() > 0) { - $containers->each(function ($container) { - $this->containers->push(str_replace('/', '', $container['Names'])); - }); + $server->containers = $containers; + } catch (\Exception $e) { + return handleError($e, $this); + } + } + public function mount() + { + $this->containers = collect(); + $this->servers = collect(); + $this->parameters = get_route_parameters(); + $this->query = request()->query(); + if (data_get($this->parameters, 'application_uuid')) { + $this->type = 'application'; + $this->resource = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail(); + $this->status = $this->resource->status; + if ($this->resource->destination->server->isFunctional()) { + $this->servers = $this->servers->push($this->resource->destination->server); } - $this->containers = $this->containers->sortByDesc(function ($container) { - if (str_contains($container, '-pr-')) { - return explode('-pr-', $container)[1]; + foreach ($this->resource->additional_servers as $server) { + if ($server->isFunctional()) { + $this->servers = $this->servers->push($server); } - return $container; - }); + } } else if (data_get($this->parameters, 'database_uuid')) { $this->type = 'database'; $resource = StandalonePostgresql::where('uuid', $this->parameters['database_uuid'])->first(); @@ -74,7 +81,9 @@ public function mount() } $this->resource = $resource; $this->status = $this->resource->status; - $this->server = $this->resource->destination->server; + if ($this->resource->destination->server->isFunctional()) { + $this->servers = $this->servers->push($this->resource->destination->server); + } $this->container = $this->resource->uuid; $this->containers->push($this->container); } else if (data_get($this->parameters, 'service_uuid')) { @@ -87,7 +96,9 @@ public function mount() $this->containers->push(data_get($database, 'name') . '-' . data_get($this->resource, 'uuid')); }); - $this->server = $this->resource->server; + if ($this->resource->server->isFunctional()) { + $this->servers = $this->servers->push($this->resource->server); + } } } diff --git a/config/sentry.php b/config/sentry.php index 503c729b4..1b96a2a02 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.230', + 'release' => '4.0.0-beta.231', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 52b6fa587..53d87bbd5 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Source @endif - Servers + @if (str($application->status)->contains('degraded')) + + + + + + @endif - Scheduled Tasks diff --git a/resources/views/livewire/project/shared/execute-container-command.blade.php b/resources/views/livewire/project/shared/execute-container-command.blade.php index 89e32ae7a..b21ef92cf 100644 --- a/resources/views/livewire/project/shared/execute-container-command.blade.php +++ b/resources/views/livewire/project/shared/execute-container-command.blade.php @@ -12,23 +12,44 @@ @elseif ($type === 'service')

Execute Command

@endif - @if (count($containers) > 0) -
-
- - -
- - - @foreach ($containers as $container) - - @endforeach - - Run -
- @else -
No containers are not running.
- @endif +
+
+ Loading containers... +
+
+ @if (count($containers) > 0) +
+
+ + +
+ + + @if (data_get($this->parameters, 'application_uuid')) + @foreach ($containers as $container) + + @endforeach + @elseif(data_get($this->parameters, 'service_uuid')) + @foreach ($containers as $container) + + @endforeach + @else + + @endif + + Run +
+ @else +
No containers are not running.
+ @endif +
+
diff --git a/resources/views/livewire/project/shared/get-logs.blade.php b/resources/views/livewire/project/shared/get-logs.blade.php index fc1e346cc..3728ca9b6 100644 --- a/resources/views/livewire/project/shared/get-logs.blade.php +++ b/resources/views/livewire/project/shared/get-logs.blade.php @@ -1,7 +1,12 @@
-

{{ str($container)->beforeLast('-')->headline() }}

+ @if ($resource->type() === 'application') +

{{ $container }}

+ @else +

{{ str($container)->beforeLast('-')->headline() }}

+ @endif +
Server: {{ $server->name }}
@if ($pull_request)
({{ $pull_request }})
@endif diff --git a/resources/views/livewire/project/shared/logs.blade.php b/resources/views/livewire/project/shared/logs.blade.php index 3d011e1e8..a505361dd 100644 --- a/resources/views/livewire/project/shared/logs.blade.php +++ b/resources/views/livewire/project/shared/logs.blade.php @@ -3,14 +3,20 @@

Logs

- @forelse ($containers as $container) - @if ($loop->first) -

Logs

- @endif - - @empty -
No containers are not running.
- @endforelse +

Logs

+
+ Loading containers... +
+ @foreach ($servers as $server) +

+
+ @forelse (data_get($server,'containers',[]) as $container) + + @empty +
No containers are not running on server: {{$server->name}}
+ @endforelse +
+ @endforeach
@elseif ($type === 'database')

Logs

@@ -20,9 +26,9 @@ @if ($loop->first)

Logs

@endif - + @empty -
No containers are not running.
+
No containers are not running.
@endforelse
@elseif ($type === 'service') @@ -31,9 +37,9 @@ @if ($loop->first)

Logs

@endif - + @empty -
No containers are not running.
+
No containers are not running.
@endforelse
@endif diff --git a/versions.json b/versions.json index b42f4128c..ad884473a 100644 --- a/versions.json +++ b/versions.json @@ -4,7 +4,7 @@ "version": "3.12.36" }, "v4": { - "version": "4.0.0-beta.230" + "version": "4.0.0-beta.231" } } }