diff --git a/app/Http/Livewire/Project/Application/Command.php b/app/Http/Livewire/Project/Application/Command.php index 3ee89dbdf..5fea572ee 100644 --- a/app/Http/Livewire/Project/Application/Command.php +++ b/app/Http/Livewire/Project/Application/Command.php @@ -16,31 +16,28 @@ class Command extends Component { public string $command; public string $container; - public string $dir; - public $server; + public $containers; + public $parameters; + public $resource; + public string $type; + public string $workDir = ''; + public Server $server; public $servers = []; protected $rules = [ 'server' => 'required', 'container' => 'required', 'command' => 'required', - ]; - protected $validationAttributes = [ - 'server' => 'server', - 'container' => 'container', - 'command' => 'command', + 'workDir' => 'nullable', ]; public function mount() { - $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; $containers = getCurrentApplicationContainerStatus($this->server, $this->resource->id, 0); if ($containers->count() > 0) { @@ -67,22 +64,27 @@ public function mount() } } $this->resource = $resource; - $this->status = $this->resource->status; $this->server = $this->resource->destination->server; $this->container = $this->resource->uuid; $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(); - $service_name = data_get($this->parameters, 'service_name'); - $this->serviceSubType = $this->resource->applications()->where('name', $service_name)->first(); - if (!$this->serviceSubType) { - $this->serviceSubType = $this->resource->databases()->where('name', $service_name)->first(); - } - $this->status = $this->resource->status; + $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->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->server = $this->resource->server; - $this->container = data_get($this->parameters, 'service_name') . '-' . $this->resource->uuid; - $this->containers->push($this->container); + } + if ($this->containers->count() > 1) { + $this->container = $this->containers->first(); } } @@ -90,10 +92,9 @@ public function runCommand() { $this->validate(); try { - if (!empty($this->dir)) { - $exec = "docker exec -w {$this->dir} {$this->container} {$this->command}"; - } - else { + if (!empty($this->workDir)) { + $exec = "docker exec -w {$this->workDir} {$this->container} {$this->command}"; + } else { $exec = "docker exec {$this->container} {$this->command}"; } $activity = remote_process([$exec], $this->server, ignore_errors: true); @@ -102,4 +103,8 @@ public function runCommand() return handleError($e, $this); } } -} \ No newline at end of file + public function render() + { + return view('livewire.project.shared.execute-container-command'); + } +} diff --git a/app/Http/Livewire/Project/Shared/ExecuteContainerCommand.php b/app/Http/Livewire/Project/Shared/ExecuteContainerCommand.php new file mode 100644 index 000000000..cfe149b92 --- /dev/null +++ b/app/Http/Livewire/Project/Shared/ExecuteContainerCommand.php @@ -0,0 +1,110 @@ + 'required', + 'container' => 'required', + 'command' => 'required', + 'workDir' => 'nullable', + ]; + + public function mount() + { + $this->containers = collect(); + $this->parameters = get_route_parameters(); + 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'])); + }); + } + } else if (data_get($this->parameters, 'database_uuid')) { + $this->type = 'database'; + $resource = StandalonePostgresql::where('uuid', $this->parameters['database_uuid'])->first(); + if (is_null($resource)) { + $resource = StandaloneRedis::where('uuid', $this->parameters['database_uuid'])->first(); + if (is_null($resource)) { + $resource = StandaloneMongodb::where('uuid', $this->parameters['database_uuid'])->first(); + if (is_null($resource)) { + $resource = StandaloneMysql::where('uuid', $this->parameters['database_uuid'])->first(); + if (is_null($resource)) { + $resource = StandaloneMariadb::where('uuid', $this->parameters['database_uuid'])->first(); + if (is_null($resource)) { + abort(404); + } + } + } + } + } + $this->resource = $resource; + $this->server = $this->resource->destination->server; + $this->container = $this->resource->uuid; + $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->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->server = $this->resource->server; + } + if ($this->containers->count() > 1) { + $this->container = $this->containers->first(); + } + } + + public function runCommand() + { + $this->validate(); + try { + if (!empty($this->workDir)) { + $exec = "docker exec -w {$this->workDir} {$this->container} {$this->command}"; + } else { + $exec = "docker exec {$this->container} {$this->command}"; + } + $activity = remote_process([$exec], $this->server, ignore_errors: true); + $this->emit('newMonitorActivity', $activity->id); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + public function render() + { + return view('livewire.project.shared.execute-container-command'); + } +} diff --git a/resources/views/components/applications/navbar.blade.php b/resources/views/components/applications/navbar.blade.php index 8c7da3296..628175f75 100644 --- a/resources/views/components/applications/navbar.blade.php +++ b/resources/views/components/applications/navbar.blade.php @@ -3,17 +3,17 @@ href="{{ route('project.application.configuration', $parameters) }}"> - - + + - - + +
diff --git a/resources/views/components/databases/navbar.blade.php b/resources/views/components/databases/navbar.blade.php index b8ca54c0c..ca6c09f8b 100644 --- a/resources/views/components/databases/navbar.blade.php +++ b/resources/views/components/databases/navbar.blade.php @@ -3,14 +3,14 @@ href="{{ route('project.database.configuration', $parameters) }}"> + + + - - - @if ( $database->getMorphClass() === 'App\Models\StandalonePostgresql' || $database->getMorphClass() === 'App\Models\StandaloneMongodb' || diff --git a/resources/views/components/services/navbar.blade.php b/resources/views/components/services/navbar.blade.php index 83facccec..3dc47ee89 100644 --- a/resources/views/components/services/navbar.blade.php +++ b/resources/views/components/services/navbar.blade.php @@ -38,7 +38,8 @@ class="flex items-center gap-2 cursor-pointer hover:text-white text-neutral-400" @endif @if (serviceStatus($service) === 'exited') - - - - @endif -
- - - - - @foreach ($containers as $container) - - @endforeach - - Execute Command - - -
- -
- \ No newline at end of file diff --git a/resources/views/livewire/project/service/index.blade.php b/resources/views/livewire/project/service/index.blade.php index 2b439461a..136b23b11 100644 --- a/resources/views/livewire/project/service/index.blade.php +++ b/resources/views/livewire/project/service/index.blade.php @@ -1,12 +1,16 @@
-
+
Documentation Service Stack + Execute Command Logs
+
+ +
diff --git a/resources/views/livewire/project/service/show.blade.php b/resources/views/livewire/project/service/show.blade.php index dbffe0352..f556d6df8 100644 --- a/resources/views/livewire/project/service/show.blade.php +++ b/resources/views/livewire/project/service/show.blade.php @@ -26,10 +26,6 @@ @endif - - -
@isset($serviceApplication) diff --git a/resources/views/livewire/project/shared/execute-container-command.blade.php b/resources/views/livewire/project/shared/execute-container-command.blade.php new file mode 100644 index 000000000..610132022 --- /dev/null +++ b/resources/views/livewire/project/shared/execute-container-command.blade.php @@ -0,0 +1,31 @@ +
+ @if ($type === 'application') +

Execute Command

+ + @elseif ($type === 'database') +

Execute Command

+ + @elseif ($type === 'service') +

Execute Command

+ @endif + @if (count($containers) > 0) +
+
+ + +
+ + + @foreach ($containers as $container) + + @endforeach + + Run +
+ @else +
No containers are not running.
+ @endif +
+ +
+
diff --git a/routes/web.php b/routes/web.php index a8a5baf8d..13b36c256 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6,13 +6,13 @@ use App\Http\Controllers\MagicController; use App\Http\Controllers\ProjectController; use App\Http\Livewire\Project\Application\Configuration as ApplicationConfiguration; -use App\Http\Livewire\Project\Application\Command as ApplicationCommand; use App\Http\Livewire\Boarding\Index as BoardingIndex; use App\Http\Livewire\Project\Service\Index as ServiceIndex; use App\Http\Livewire\Project\Service\Show as ServiceShow; use App\Http\Livewire\Dev\Compose as Compose; use App\Http\Livewire\Dashboard; use App\Http\Livewire\Project\CloneProject; +use App\Http\Livewire\Project\Shared\ExecuteContainerCommand; use App\Http\Livewire\Project\Shared\Logs; use App\Http\Livewire\Security\ApiTokens; use App\Http\Livewire\Server\All; @@ -122,21 +122,21 @@ )->name('project.application.deployment'); Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}/logs', Logs::class)->name('project.application.logs'); - Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}/command', ApplicationCommand::class)->name('project.application.command'); + Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}/command', ExecuteContainerCommand::class)->name('project.application.command'); // Databases Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}', [DatabaseController::class, 'configuration'])->name('project.database.configuration'); Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}/backups', [DatabaseController::class, 'backups'])->name('project.database.backups.all'); Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}/backups/{backup_uuid}', [DatabaseController::class, 'executions'])->name('project.database.backups.executions'); Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}/logs', Logs::class)->name('project.database.logs'); - Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}/command', ApplicationCommand::class)->name('project.database.command'); + Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}/command', ExecuteContainerCommand::class)->name('project.database.command'); // Services Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}', ServiceIndex::class)->name('project.service.configuration'); Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}/{service_name}', ServiceShow::class)->name('project.service.show'); Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}/{service_name}/logs', Logs::class)->name('project.service.logs'); - Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}/{service_name}/command', ApplicationCommand::class)->name('project.service.command'); + Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}/command', ExecuteContainerCommand::class)->name('project.service.command'); }); Route::middleware(['auth'])->group(function () {