Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into Feat-Client-Side
Browse files Browse the repository at this point in the history
  • Loading branch information
Poseidon281 committed May 19, 2024
2 parents bd1037a + b1f99ca commit 9122c2b
Show file tree
Hide file tree
Showing 19 changed files with 510 additions and 65 deletions.
29 changes: 15 additions & 14 deletions app/Console/Commands/Environment/AppSettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class AppSettingsCommand extends Command
];

public const QUEUE_DRIVERS = [
'sync' => 'Synchronous (recommended)',
'database' => 'Database',
'database' => 'Database (recommended)',
'redis' => 'Redis',
'sync' => 'Synchronous',
];

protected $description = 'Configure basic environment settings for the Panel.';
Expand Down Expand Up @@ -103,7 +103,13 @@ public function handle(): int
$this->variables['SESSION_SECURE_COOKIE'] = 'true';
}

$this->checkForRedis();
$redisUsed = count(collect($this->variables)->filter(function ($item) {
return $item === 'redis';
})) !== 0;

if ($redisUsed) {
$this->requestRedisSettings();
}

$path = base_path('.env');
if (!file_exists($path)) {
Expand All @@ -116,25 +122,20 @@ public function handle(): int
Artisan::call('key:generate');
}

if ($this->variables['QUEUE_CONNECTION'] !== 'sync') {
Artisan::call('p:environment:queue-service', $redisUsed ? ['--use-redis'] : []);
}

$this->info($this->console->output());

return 0;
}

/**
* Check if redis is selected, if so, request connection details and verify them.
* Request connection details and verify them.
*/
private function checkForRedis()
private function requestRedisSettings(): void
{
$items = collect($this->variables)->filter(function ($item) {
return $item === 'redis';
});

// Redis was not selected, no need to continue.
if (count($items) === 0) {
return;
}

$this->output->note(__('commands.appsettings.redis.note'));
$this->variables['REDIS_HOST'] = $this->option('redis-host') ?? $this->ask(
'Redis Host',
Expand Down
76 changes: 76 additions & 0 deletions app/Console/Commands/Environment/QueueWorkerServiceCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace App\Console\Commands\Environment;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Process;

class QueueWorkerServiceCommand extends Command
{
protected $description = 'Create the service for the queue worker.';

protected $signature = 'p:environment:queue-service
{--service-name= : Name of the queue worker service.}
{--user= : The user that PHP runs under.}
{--group= : The group that PHP runs under.}
{--use-redis : Whether redis is used.}';

public function handle(): void
{
$serviceName = $this->option('service-name') ?? $this->ask('Service name', 'pelican-queue');
$path = '/etc/systemd/system/' . $serviceName . '.service';

if ($this->input->isInteractive()) {
if (file_exists($path) && !$this->confirm('The service file already exists. Do you want to overwrite it?')) {
return;
}

$user = $this->option('user') ?? $this->ask('User', 'www-data');
$group = $this->option('group') ?? $this->ask('Group', 'www-data');

$afterRedis = $this->option('use-redis') ? '\nAfter=redis-server.service' : '';
} else {
$user = 'www-data';
$group = 'www-data';

$afterRedis = '';
}

$basePath = base_path();

$success = File::put($path, "# Pelican Queue File
# ----------------------------------
[Unit]
Description=Pelican Queue Service$afterRedis
[Service]
User=$user
Group=$group
Restart=always
ExecStart=/usr/bin/php $basePath/artisan queue:work --queue=high,standard,low --tries=3
StartLimitInterval=180
StartLimitBurst=30
RestartSec=5s
[Install]
WantedBy=multi-user.target
");

if (!$success) {
$this->error('Error creating service file');

return;
}

$result = Process::run("systemctl enable --now $serviceName.service");
if ($result->failed()) {
$this->error('Error enabling service: ' . $result->errorOutput());

return;
}

$this->line('Queue worker service file created successfully.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class DatabasesRelationManager extends RelationManager
{
protected static string $relationship = 'databases';

protected $listeners = ['refresh' => 'refreshForm'];

public function form(Form $form): Form
{
return $form
Expand All @@ -28,7 +26,7 @@ public function form(Form $form): Form
Action::make('rotate')
->icon('tabler-refresh')
->requiresConfirmation()
->action(fn (DatabasePasswordService $service, Database $database) => $service->handle($database))
->action(fn (DatabasePasswordService $service, Database $database, $set, $get) => $this->rotatePassword($service, $database, $set, $get))
)
->formatStateUsing(fn (Database $database) => decrypt($database->password)),
Forms\Components\TextInput::make('remote')->label('Connections From'),
Expand Down Expand Up @@ -60,4 +58,13 @@ public function table(Table $table): Table
//Tables\Actions\EditAction::make(),
]);
}

protected function rotatePassword(DatabasePasswordService $service, Database $database, $set, $get): void
{
$newPassword = $service->handle($database);
$jdbcString = 'jdbc:mysql://' . $get('username') . ':' . urlencode($newPassword) . '@' . $database->host->host . ':' . $database->host->port . '/' . $get('database');

$set('password', $newPassword);
$set('JDBC', $jdbcString);
}
}
4 changes: 2 additions & 2 deletions app/Filament/Admin/Resources/EggResource/Pages/EditEgg.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public function form(Form $form): Form
Forms\Components\TextInput::make('name')
->required()
->maxLength(191)
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 1])
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 2, 'lg' => 1])
->helperText('A simple, human-readable name to use as an identifier for this Egg.'),
Forms\Components\TextInput::make('uuid')
->label('Egg UUID')
->disabled()
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 2, 'lg' => 2])
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 2])
->helperText('This is the globally unique identifier for this Egg which Wings uses as an identifier.'),
Forms\Components\TextInput::make('id')
->label('Egg ID')
Expand Down
20 changes: 1 addition & 19 deletions app/Filament/Admin/Resources/EggResource/Pages/ListEggs.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,13 @@ public function table(Table $table): Table
->searchable(),
Tables\Columns\TextColumn::make('name')
->icon('tabler-egg')
->description(fn ($record): ?string => $record->description)
->description(fn ($record): ?string => (strlen($record->description) > 120) ? substr($record->description, 0, 120).'...' : $record->description)
->wrap()
->searchable(),
Tables\Columns\TextColumn::make('author')
->hidden()
->searchable(),
Tables\Columns\TextColumn::make('servers_count')
->counts('servers')
->icon('tabler-server')
->label('Servers'),
Tables\Columns\TextColumn::make('script_container')
->searchable()
->hidden(),
Tables\Columns\TextColumn::make('copyFrom.name')
->hidden()
->sortable(),
Tables\Columns\TextColumn::make('script_entry')
->hidden()
->searchable(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Expand All @@ -63,9 +48,6 @@ public function table(Table $table): Table
// TODO uses old admin panel export service
->url(fn (Egg $egg): string => route('admin.eggs.export', ['egg' => $egg])),
])
->headerActions([
//
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Expand Down
56 changes: 31 additions & 25 deletions app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,37 @@ public function form(Forms\Form $form): Forms\Form
->default(fn () => request()->isSecure() ? 'https' : 'http'), ]),

Tabs\Tab::make('Advanced Settings')
->columns(['default' => 1, 'sm' => 1, 'md' => 4, 'lg' => 6])
->icon('tabler-server-cog')
->schema([
Forms\Components\TextInput::make('id')
->label('Node ID')
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 2, 'lg' => 1])
->disabled(),
Forms\Components\TextInput::make('uuid')
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 2, 'lg' => 2])
->label('Node UUID')
->hintAction(CopyAction::make())
->columnSpan(2)
->disabled(),
Forms\Components\TagsInput::make('tags')
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 2, 'lg' => 2])
->label('Tags')
->disabled()
->placeholder('Not Implemented')
->hintIcon('tabler-question-mark')
->hintIconTooltip('Not Implemented')
->columnSpan(1),
->hintIconTooltip('Not Implemented'),
Forms\Components\TextInput::make('upload_size')
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 2, 'lg' => 1])
->label('Upload Limit')
->hintIcon('tabler-question-mark')
->hintIconTooltip('Enter the maximum size of files that can be uploaded through the web-based file manager.')
->numeric()->required()
->minValue(1)
->maxValue(1024)
->suffix('MiB'),
Forms\Components\ToggleButtons::make('public')
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 3])
->label('Automatic Allocation')->inline()
->columnSpan(1)
->options([
true => 'Yes',
false => 'No',
Expand All @@ -215,29 +226,20 @@ public function form(Forms\Form $form): Forms\Form
false => 'danger',
]),
Forms\Components\ToggleButtons::make('maintenance_mode')
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 3])
->label('Maintenance Mode')->inline()
->columnSpan(1)
->hinticon('tabler-question-mark')
->hintIconTooltip("If the node is marked 'Under Maintenance' users won't be able to access servers that are on this node.")
->options([
true => 'Enable',
false => 'Disable',
true => 'Enable',
])
->colors([
true => 'danger',
false => 'success',
true => 'danger',
]),
Forms\Components\TextInput::make('upload_size')
->label('Upload Limit')
->hintIcon('tabler-question-mark')
->hintIconTooltip('Enter the maximum size of files that can be uploaded through the web-based file manager.')
->columnStart(4)->columnSpan(1)
->numeric()->required()
->minValue(1)
->maxValue(1024)
->suffix('MiB'),
Forms\Components\Grid::make()
->columns(6)
->columns(['default' => 1, 'sm' => 1, 'md' => 3, 'lg' => 6])
->columnSpanFull()
->schema([
Forms\Components\ToggleButtons::make('unlimited_mem')
Expand All @@ -254,14 +256,14 @@ public function form(Forms\Form $form): Forms\Form
true => 'primary',
false => 'warning',
])
->columnSpan(2),
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 2]),
Forms\Components\TextInput::make('memory')
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_mem'))
->label('Memory Limit')->inlineLabel()
->suffix('MiB')
->required()
->columnSpan(2)
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 2])
->numeric()
->minValue(0),
Forms\Components\TextInput::make('memory_overallocate')
Expand All @@ -271,15 +273,14 @@ public function form(Forms\Form $form): Forms\Form
->hidden(fn (Forms\Get $get) => $get('unlimited_mem'))
->hintIcon('tabler-question-mark')
->hintIconTooltip('The % allowable to go over the set limit.')
->columnSpan(2)
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 2])
->numeric()
->minValue(-1)
->maxValue(100)
->suffix('%'),
]),
Forms\Components\Grid::make()
->columns(6)
->columnSpanFull()
->columns(['default' => 1, 'sm' => 1, 'md' => 3, 'lg' => 6])
->schema([
Forms\Components\ToggleButtons::make('unlimited_disk')
->label('Disk')->inlineLabel()->inline()
Expand All @@ -295,14 +296,14 @@ public function form(Forms\Form $form): Forms\Form
true => 'primary',
false => 'warning',
])
->columnSpan(2),
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 2]),
Forms\Components\TextInput::make('disk')
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_disk'))
->label('Disk Limit')->inlineLabel()
->suffix('MiB')
->required()
->columnSpan(2)
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 2])
->numeric()
->minValue(0),
Forms\Components\TextInput::make('disk_overallocate')
Expand All @@ -311,7 +312,7 @@ public function form(Forms\Form $form): Forms\Form
->label('Overallocate')->inlineLabel()
->hintIcon('tabler-question-mark')
->hintIconTooltip('The % allowable to go over the set limit.')
->columnSpan(2)
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 2])
->required()
->numeric()
->minValue(-1)
Expand Down Expand Up @@ -368,4 +369,9 @@ protected function getFooterWidgets(): array
NodeMemoryChart::class,
];
}

protected function afterSave(): void
{
$this->fillForm();
}
}
Loading

0 comments on commit 9122c2b

Please sign in to comment.