From 4c43fd168398433ae4456d76bed1b083e8ab5053 Mon Sep 17 00:00:00 2001 From: notCharles Date: Sun, 19 May 2024 20:55:37 -0400 Subject: [PATCH 1/3] Add docker_labels --- .../ServerResource/Pages/CreateServer.php | 27 +++++++--- .../ServerResource/Pages/EditServer.php | 27 +++++++--- app/Models/Server.php | 1 + app/Services/Eggs/EggConfigurationService.php | 2 +- .../ServerConfigurationStructureService.php | 50 ++----------------- ...5_20_002841_add_docker_container_label.php | 28 +++++++++++ 6 files changed, 73 insertions(+), 62 deletions(-) create mode 100644 database/migrations/2024_05_20_002841_add_docker_container_label.php diff --git a/app/Filament/Resources/ServerResource/Pages/CreateServer.php b/app/Filament/Resources/ServerResource/Pages/CreateServer.php index c03de3fce..c93efd379 100644 --- a/app/Filament/Resources/ServerResource/Pages/CreateServer.php +++ b/app/Filament/Resources/ServerResource/Pages/CreateServer.php @@ -329,10 +329,10 @@ class CreateServer extends CreateRecord }) ->selectablePlaceholder(false) ->columnSpan([ - 'default' => 2, - 'sm' => 2, - 'md' => 2, - 'lg' => 3, + 'default' => 1, + 'sm' => 1, + 'md' => 1, + 'lg' => 2, ]), Forms\Components\TextInput::make('image') @@ -352,10 +352,21 @@ class CreateServer extends CreateRecord }) ->placeholder('Enter a custom Image') ->columnSpan([ - 'default' => 2, - 'sm' => 2, - 'md' => 2, - 'lg' => 3, + 'default' => 1, + 'sm' => 1, + 'md' => 1, + 'lg' => 2, + ]), + + Forms\Components\TagsInput::make('docker_labels') + ->label('Docker Labels') + ->live() + ->placeholder('Enter custom Docker container labels') + ->columnSpan([ + 'default' => 1, + 'sm' => 1, + 'md' => 1, + 'lg' => 2, ]), Forms\Components\Textarea::make('startup') diff --git a/app/Filament/Resources/ServerResource/Pages/EditServer.php b/app/Filament/Resources/ServerResource/Pages/EditServer.php index 7438782b2..0abc740b2 100644 --- a/app/Filament/Resources/ServerResource/Pages/EditServer.php +++ b/app/Filament/Resources/ServerResource/Pages/EditServer.php @@ -171,10 +171,10 @@ class EditServer extends EditRecord }) ->selectablePlaceholder(false) ->columnSpan([ - 'default' => 2, - 'sm' => 2, - 'md' => 2, - 'lg' => 3, + 'default' => 1, + 'sm' => 1, + 'md' => 1, + 'lg' => 2, ]), Forms\Components\TextInput::make('image') @@ -194,10 +194,21 @@ class EditServer extends EditRecord }) ->placeholder('Enter a custom Image') ->columnSpan([ - 'default' => 2, - 'sm' => 2, - 'md' => 2, - 'lg' => 3, + 'default' => 1, + 'sm' => 1, + 'md' => 1, + 'lg' => 2, + ]), + + Forms\Components\TagsInput::make('docker_labels') + ->label('Docker Labels') + ->live() + ->placeholder('Enter custom Docker container labels') + ->columnSpan([ + 'default' => 1, + 'sm' => 1, + 'md' => 1, + 'lg' => 2, ]), Forms\Components\Textarea::make('startup') diff --git a/app/Models/Server.php b/app/Models/Server.php index 2a60c3822..3c4657343 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -184,6 +184,7 @@ class Server extends Model self::UPDATED_AT => 'datetime', 'deleted_at' => 'datetime', 'installed_at' => 'datetime', + 'docker_labels' => 'array', ]; } diff --git a/app/Services/Eggs/EggConfigurationService.php b/app/Services/Eggs/EggConfigurationService.php index 5ae5b6518..5280688ee 100644 --- a/app/Services/Eggs/EggConfigurationService.php +++ b/app/Services/Eggs/EggConfigurationService.php @@ -81,7 +81,7 @@ class EggConfigurationService { // Get the legacy configuration structure for the server so that we // can property map the egg placeholders to values. - $structure = $this->configurationStructureService->handle($server, [], true); + $structure = $this->configurationStructureService->handle($server); $response = []; // Normalize the output of the configuration for the new Daemon to more diff --git a/app/Services/Servers/ServerConfigurationStructureService.php b/app/Services/Servers/ServerConfigurationStructureService.php index 535f4b439..75fae45e0 100644 --- a/app/Services/Servers/ServerConfigurationStructureService.php +++ b/app/Services/Servers/ServerConfigurationStructureService.php @@ -20,7 +20,7 @@ class ServerConfigurationStructureService * DO NOT MODIFY THIS FUNCTION. This powers legacy code handling for the new daemon * daemon, if you modify the structure eggs will break unexpectedly. */ - public function handle(Server $server, array $override = [], bool $legacy = false): array + public function handle(Server $server, array $override = []): array { $clone = $server; // If any overrides have been set on this call make sure to update them on the @@ -32,15 +32,13 @@ class ServerConfigurationStructureService } } - return $legacy - ? $this->returnLegacyFormat($clone) - : $this->returnCurrentFormat($clone); + return $this->returnFormat($clone); } /** - * Returns the new data format used for the daemon. + * Returns the data format used for the daemon. */ - protected function returnCurrentFormat(Server $server): array + protected function returnFormat(Server $server): array { return [ 'uuid' => $server->uuid, @@ -59,13 +57,12 @@ class ServerConfigurationStructureService 'cpu_limit' => $server->cpu, 'threads' => $server->threads, 'disk_space' => $server->disk, - // This field is deprecated — use "oom_killer". - 'oom_disabled' => !$server->oom_killer, 'oom_killer' => $server->oom_killer, ], 'container' => [ 'image' => $server->image, 'requires_rebuild' => false, + 'labels' => $server->docker_labels, ], 'allocations' => [ 'force_outgoing_ip' => $server->egg->force_outgoing_ip, @@ -88,41 +85,4 @@ class ServerConfigurationStructureService ], ]; } - - /** - * Returns the legacy server data format to continue support for old egg configurations - * that have not yet been updated. - * - * @deprecated - */ - protected function returnLegacyFormat(Server $server): array - { - return [ - 'uuid' => $server->uuid, - 'build' => [ - 'default' => [ - 'ip' => $server->allocation->ip, - 'port' => $server->allocation->port, - ], - 'ports' => $server->allocations->groupBy('ip')->map(function ($item) { - return $item->pluck('port'); - })->toArray(), - 'env' => $this->environment->handle($server), - 'oom_disabled' => !$server->oom_killer, - 'memory' => (int) $server->memory, - 'swap' => (int) $server->swap, - 'io' => (int) $server->io, - 'cpu' => (int) $server->cpu, - 'threads' => $server->threads, - 'disk' => (int) $server->disk, - 'image' => $server->image, - ], - 'service' => [ - 'egg' => $server->egg->uuid, - 'skip_scripts' => $server->skip_scripts, - ], - 'rebuild' => false, - 'suspended' => $server->isSuspended() ? 1 : 0, - ]; - } } diff --git a/database/migrations/2024_05_20_002841_add_docker_container_label.php b/database/migrations/2024_05_20_002841_add_docker_container_label.php new file mode 100644 index 000000000..eea5f02b4 --- /dev/null +++ b/database/migrations/2024_05_20_002841_add_docker_container_label.php @@ -0,0 +1,28 @@ +text('docker_labels')->default('[]'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn('docker_labels'); + }); + } +}; From 03cbdd5bddb76a872669bd29971316402d5c3e25 Mon Sep 17 00:00:00 2001 From: notCharles Date: Sun, 19 May 2024 21:15:43 -0400 Subject: [PATCH 2/3] update edit/create pages --- .../ServerResource/Pages/CreateServer.php | 451 +++++++++--------- .../ServerResource/Pages/EditServer.php | 435 +++++++++-------- 2 files changed, 455 insertions(+), 431 deletions(-) diff --git a/app/Filament/Resources/ServerResource/Pages/CreateServer.php b/app/Filament/Resources/ServerResource/Pages/CreateServer.php index c93efd379..b40b54a14 100644 --- a/app/Filament/Resources/ServerResource/Pages/CreateServer.php +++ b/app/Filament/Resources/ServerResource/Pages/CreateServer.php @@ -309,66 +309,6 @@ class CreateServer extends CreateRecord ->inline() ->required(), - Forms\Components\Select::make('select_image') - ->label('Docker Image Name') - ->prefixIcon('tabler-brand-docker') - ->live() - ->afterStateUpdated(fn (Forms\Set $set, $state) => $set('image', $state)) - ->options(function ($state, Forms\Get $get, Forms\Set $set) { - $egg = Egg::query()->find($get('egg_id')); - $images = $egg->docker_images ?? []; - - $currentImage = $get('image'); - if (!$currentImage && $images) { - $defaultImage = collect($images)->first(); - $set('image', $defaultImage); - $set('select_image', $defaultImage); - } - - return array_flip($images) + ['ghcr.io/custom-image' => 'Custom Image']; - }) - ->selectablePlaceholder(false) - ->columnSpan([ - 'default' => 1, - 'sm' => 1, - 'md' => 1, - 'lg' => 2, - ]), - - Forms\Components\TextInput::make('image') - ->label('Docker Image') - ->prefixIcon('tabler-brand-docker') - ->live() - ->debounce(500) - ->afterStateUpdated(function ($state, Forms\Get $get, Forms\Set $set) { - $egg = Egg::query()->find($get('egg_id')); - $images = $egg->docker_images ?? []; - - if (in_array($state, $images)) { - $set('select_image', $state); - } else { - $set('select_image', 'ghcr.io/custom-image'); - } - }) - ->placeholder('Enter a custom Image') - ->columnSpan([ - 'default' => 1, - 'sm' => 1, - 'md' => 1, - 'lg' => 2, - ]), - - Forms\Components\TagsInput::make('docker_labels') - ->label('Docker Labels') - ->live() - ->placeholder('Enter custom Docker container labels') - ->columnSpan([ - 'default' => 1, - 'sm' => 1, - 'md' => 1, - 'lg' => 2, - ]), - Forms\Components\Textarea::make('startup') ->hintIcon('tabler-code') ->label('Startup Command') @@ -463,7 +403,7 @@ class CreateServer extends CreateRecord ->columnSpan(2), ]), - Forms\Components\Section::make('Resource Management') + Forms\Components\Section::make('Environment Management') ->collapsed() ->icon('tabler-server-cog') ->iconColor('primary') @@ -475,175 +415,190 @@ class CreateServer extends CreateRecord ]) ->columnSpanFull() ->schema([ - Forms\Components\Grid::make() - ->columns(4) - ->columnSpanFull() + Forms\Components\Fieldset::make('Resource Limits') + ->columnSpan([ + 'default' => 2, + 'sm' => 4, + 'md' => 4, + 'lg' => 6, + ]) + ->columns([ + 'default' => 1, + 'sm' => 2, + 'md' => 3, + 'lg' => 3, + ]) ->schema([ - Forms\Components\ToggleButtons::make('unlimited_mem') - ->label('Memory')->inlineLabel()->inline() - ->default(true) - ->afterStateUpdated(fn (Forms\Set $set) => $set('memory', 0)) - ->live() - ->options([ - true => 'Unlimited', - false => 'Limited', - ]) - ->colors([ - true => 'primary', - false => 'warning', - ]) - ->columnSpan(2), + Forms\Components\Grid::make() + ->columns(4) + ->columnSpanFull() + ->schema([ + Forms\Components\ToggleButtons::make('unlimited_mem') + ->label('Memory')->inlineLabel()->inline() + ->default(true) + ->afterStateUpdated(fn (Forms\Set $set) => $set('memory', 0)) + ->live() + ->options([ + true => 'Unlimited', + false => 'Limited', + ]) + ->colors([ + true => 'primary', + false => 'warning', + ]) + ->columnSpan(2), - Forms\Components\TextInput::make('memory') - ->dehydratedWhenHidden() - ->hidden(fn (Forms\Get $get) => $get('unlimited_mem')) - ->label('Memory Limit')->inlineLabel() - ->suffix('MiB') - ->default(0) - ->required() - ->columnSpan(2) - ->numeric() - ->minValue(0), - ]), - - Forms\Components\Grid::make() - ->columns(4) - ->columnSpanFull() - ->schema([ - Forms\Components\ToggleButtons::make('unlimited_disk') - ->label('Disk Space')->inlineLabel()->inline() - ->default(true) - ->live() - ->afterStateUpdated(fn (Forms\Set $set) => $set('disk', 0)) - ->options([ - true => 'Unlimited', - false => 'Limited', - ]) - ->colors([ - true => 'primary', - false => 'warning', - ]) - ->columnSpan(2), - - Forms\Components\TextInput::make('disk') - ->dehydratedWhenHidden() - ->hidden(fn (Forms\Get $get) => $get('unlimited_disk')) - ->label('Disk Space Limit')->inlineLabel() - ->suffix('MiB') - ->default(0) - ->required() - ->columnSpan(2) - ->numeric() - ->minValue(0), - ]), - - Forms\Components\Grid::make() - ->columns(4) - ->columnSpanFull() - ->schema([ - Forms\Components\ToggleButtons::make('unlimited_cpu') - ->label('CPU')->inlineLabel()->inline() - ->default(true) - ->afterStateUpdated(fn (Forms\Set $set) => $set('cpu', 0)) - ->live() - ->options([ - true => 'Unlimited', - false => 'Limited', - ]) - ->colors([ - true => 'primary', - false => 'warning', - ]) - ->columnSpan(2), - - Forms\Components\TextInput::make('cpu') - ->dehydratedWhenHidden() - ->hidden(fn (Forms\Get $get) => $get('unlimited_cpu')) - ->label('CPU Limit')->inlineLabel() - ->suffix('%') - ->default(0) - ->required() - ->columnSpan(2) - ->numeric() - ->minValue(0) - ->helperText('100% equals one logical thread'), - ]), - - Forms\Components\Grid::make() - ->columns(4) - ->columnSpanFull() - ->schema([ - Forms\Components\ToggleButtons::make('swap_support') - ->live() - ->label('Enable Swap Memory') - ->inlineLabel() - ->inline() - ->columnSpan(2) - ->default('disabled') - ->afterStateUpdated(function ($state, Forms\Set $set) { - $value = match ($state) { - 'unlimited' => -1, - 'disabled' => 0, - 'limited' => 128, - }; - - $set('swap', $value); - }) - ->options([ - 'unlimited' => 'Unlimited', - 'limited' => 'Limited', - 'disabled' => 'Disabled', - ]) - ->colors([ - 'unlimited' => 'primary', - 'limited' => 'warning', - 'disabled' => 'danger', + Forms\Components\TextInput::make('memory') + ->dehydratedWhenHidden() + ->hidden(fn (Forms\Get $get) => $get('unlimited_mem')) + ->label('Memory Limit')->inlineLabel() + ->suffix('MiB') + ->default(0) + ->required() + ->columnSpan(2) + ->numeric() + ->minValue(0), ]), - Forms\Components\TextInput::make('swap') - ->dehydratedWhenHidden() - ->hidden(fn (Forms\Get $get) => match ($get('swap_support')) { - 'disabled', 'unlimited' => true, - 'limited' => false, - }) - ->label('Swap Memory') - ->default(0) - ->suffix('MiB') - ->minValue(-1) - ->columnSpan(2) - ->inlineLabel() - ->required() - ->integer(), - ]), + Forms\Components\Grid::make() + ->columns(4) + ->columnSpanFull() + ->schema([ + Forms\Components\ToggleButtons::make('unlimited_disk') + ->label('Disk Space')->inlineLabel()->inline() + ->default(true) + ->live() + ->afterStateUpdated(fn (Forms\Set $set) => $set('disk', 0)) + ->options([ + true => 'Unlimited', + false => 'Limited', + ]) + ->colors([ + true => 'primary', + false => 'warning', + ]) + ->columnSpan(2), - Forms\Components\Hidden::make('io') - ->helperText('The IO performance relative to other running containers') - ->label('Block IO Proportion') - ->default(500), - - Forms\Components\Grid::make() - ->columns(4) - ->columnSpanFull() - ->schema([ - Forms\Components\ToggleButtons::make('oom_killer') - ->label('OOM Killer') - ->inlineLabel()->inline() - ->default(false) - ->columnSpan(2) - ->options([ - false => 'Disabled', - true => 'Enabled', - ]) - ->colors([ - false => 'success', - true => 'danger', + Forms\Components\TextInput::make('disk') + ->dehydratedWhenHidden() + ->hidden(fn (Forms\Get $get) => $get('unlimited_disk')) + ->label('Disk Space Limit')->inlineLabel() + ->suffix('MiB') + ->default(0) + ->required() + ->columnSpan(2) + ->numeric() + ->minValue(0), ]), - Forms\Components\TextInput::make('oom_disabled_hidden') - ->hidden(), + Forms\Components\Grid::make() + ->columns(4) + ->columnSpanFull() + ->schema([ + Forms\Components\ToggleButtons::make('unlimited_cpu') + ->label('CPU')->inlineLabel()->inline() + ->default(true) + ->afterStateUpdated(fn (Forms\Set $set) => $set('cpu', 0)) + ->live() + ->options([ + true => 'Unlimited', + false => 'Limited', + ]) + ->colors([ + true => 'primary', + false => 'warning', + ]) + ->columnSpan(2), + + Forms\Components\TextInput::make('cpu') + ->dehydratedWhenHidden() + ->hidden(fn (Forms\Get $get) => $get('unlimited_cpu')) + ->label('CPU Limit')->inlineLabel() + ->suffix('%') + ->default(0) + ->required() + ->columnSpan(2) + ->numeric() + ->minValue(0) + ->helperText('100% equals one CPU core.'), + ]), + + Forms\Components\Grid::make() + ->columns(4) + ->columnSpanFull() + ->schema([ + Forms\Components\ToggleButtons::make('swap_support') + ->live() + ->label('Enable Swap Memory') + ->inlineLabel() + ->inline() + ->columnSpan(2) + ->default('disabled') + ->afterStateUpdated(function ($state, Forms\Set $set) { + $value = match ($state) { + 'unlimited' => -1, + 'disabled' => 0, + 'limited' => 128, + }; + + $set('swap', $value); + }) + ->options([ + 'unlimited' => 'Unlimited', + 'limited' => 'Limited', + 'disabled' => 'Disabled', + ]) + ->colors([ + 'unlimited' => 'primary', + 'limited' => 'warning', + 'disabled' => 'danger', + ]), + + Forms\Components\TextInput::make('swap') + ->dehydratedWhenHidden() + ->hidden(fn (Forms\Get $get) => match ($get('swap_support')) { + 'disabled', 'unlimited' => true, + 'limited' => false, + }) + ->label('Swap Memory') + ->default(0) + ->suffix('MiB') + ->minValue(-1) + ->columnSpan(2) + ->inlineLabel() + ->required() + ->integer(), + ]), + + Forms\Components\Hidden::make('io') + ->helperText('The IO performance relative to other running containers') + ->label('Block IO Proportion') + ->default(500), + + Forms\Components\Grid::make() + ->columns(4) + ->columnSpanFull() + ->schema([ + Forms\Components\ToggleButtons::make('oom_killer') + ->label('OOM Killer') + ->inlineLabel()->inline() + ->default(false) + ->columnSpan(2) + ->options([ + false => 'Disabled', + true => 'Enabled', + ]) + ->colors([ + false => 'success', + true => 'danger', + ]), + + Forms\Components\TextInput::make('oom_disabled_hidden') + ->hidden(), + ]), ]), - Forms\Components\Fieldset::make('Application Feature Limits') + Forms\Components\Fieldset::make('Feature Limits') ->inlineLabel() ->columnSpan([ 'default' => 2, @@ -674,6 +629,60 @@ class CreateServer extends CreateRecord ->numeric() ->default(0), ]), + Forms\Components\Fieldset::make('Docker Settings') + ->columnSpan([ + 'default' => 2, + 'sm' => 4, + 'md' => 4, + 'lg' => 6, + ]) + ->columns([ + 'default' => 1, + 'sm' => 2, + 'md' => 3, + 'lg' => 3, + ]) + ->schema([ + Forms\Components\Select::make('select_image') + ->label('Image Name') + ->afterStateUpdated(fn (Forms\Set $set, $state) => $set('image', $state)) + ->options(function ($state, Forms\Get $get, Forms\Set $set) { + $egg = Egg::query()->find($get('egg_id')); + $images = $egg->docker_images ?? []; + + $currentImage = $get('image'); + if (!$currentImage && $images) { + $defaultImage = collect($images)->first(); + $set('image', $defaultImage); + $set('select_image', $defaultImage); + } + + return array_flip($images) + ['ghcr.io/custom-image' => 'Custom Image']; + }) + ->selectablePlaceholder(false) + ->columnSpan(1), + + Forms\Components\TextInput::make('image') + ->label('Image') + ->debounce(500) + ->afterStateUpdated(function ($state, Forms\Get $get, Forms\Set $set) { + $egg = Egg::query()->find($get('egg_id')); + $images = $egg->docker_images ?? []; + + if (in_array($state, $images)) { + $set('select_image', $state); + } else { + $set('select_image', 'ghcr.io/custom-image'); + } + }) + ->placeholder('Enter a custom Image') + ->columnSpan(1), + + Forms\Components\TagsInput::make('docker_labels') + ->label('Labels') + ->placeholder('Enter custom Docker container labels') + ->columnSpan(1), + ]), ]), ]); } diff --git a/app/Filament/Resources/ServerResource/Pages/EditServer.php b/app/Filament/Resources/ServerResource/Pages/EditServer.php index 0abc740b2..56a245291 100644 --- a/app/Filament/Resources/ServerResource/Pages/EditServer.php +++ b/app/Filament/Resources/ServerResource/Pages/EditServer.php @@ -157,60 +157,6 @@ class EditServer extends EditRecord ]) ->required(), - Forms\Components\Select::make('select_image') - ->label('Docker Image Name') - ->prefixIcon('tabler-brand-docker') - ->live() - ->afterStateUpdated(fn (Forms\Set $set, $state) => $set('image', $state)) - ->formatStateUsing(fn (Forms\Get $get) => $get('image')) - ->options(function ($state, Forms\Get $get) { - $egg = Egg::query()->find($get('egg_id')); - $images = $egg->docker_images ?? []; - - return ['ghcr.io/custom-image' => 'Custom Image'] + array_flip($images); - }) - ->selectablePlaceholder(false) - ->columnSpan([ - 'default' => 1, - 'sm' => 1, - 'md' => 1, - 'lg' => 2, - ]), - - Forms\Components\TextInput::make('image') - ->label('Docker Image') - ->prefixIcon('tabler-brand-docker') - ->live() - ->debounce(500) - ->afterStateUpdated(function ($state, Forms\Get $get, Forms\Set $set) { - $egg = Egg::query()->find($get('egg_id')); - $images = $egg->docker_images ?? []; - - if (in_array($state, $images)) { - $set('select_image', $state); - } else { - $set('select_image', 'ghcr.io/custom-image'); - } - }) - ->placeholder('Enter a custom Image') - ->columnSpan([ - 'default' => 1, - 'sm' => 1, - 'md' => 1, - 'lg' => 2, - ]), - - Forms\Components\TagsInput::make('docker_labels') - ->label('Docker Labels') - ->live() - ->placeholder('Enter custom Docker container labels') - ->columnSpan([ - 'default' => 1, - 'sm' => 1, - 'md' => 1, - 'lg' => 2, - ]), - Forms\Components\Textarea::make('startup') ->hintIcon('tabler-code') ->label('Startup Command') @@ -298,7 +244,7 @@ class EditServer extends EditRecord ->columnSpan(2), ]), - Forms\Components\Section::make('Resource Management') + Forms\Components\Section::make('Environment Management') ->collapsed() ->icon('tabler-server-cog') ->iconColor('primary') @@ -310,170 +256,185 @@ class EditServer extends EditRecord ]) ->columnSpanFull() ->schema([ - Forms\Components\Grid::make() - ->columns(4) - ->columnSpanFull() + Forms\Components\Fieldset::make('Resource Limits') + ->columnSpan([ + 'default' => 2, + 'sm' => 4, + 'md' => 4, + 'lg' => 6, + ]) + ->columns([ + 'default' => 1, + 'sm' => 2, + 'md' => 3, + 'lg' => 3, + ]) ->schema([ - Forms\Components\ToggleButtons::make('unlimited_mem') - ->label('Memory')->inlineLabel()->inline() - ->afterStateUpdated(fn (Forms\Set $set) => $set('memory', 0)) - ->formatStateUsing(fn (Forms\Get $get) => $get('memory') == 0) - ->live() - ->options([ - true => 'Unlimited', - false => 'Limited', - ]) - ->colors([ - true => 'primary', - false => 'warning', - ]) - ->columnSpan(2), + Forms\Components\Grid::make() + ->columns(4) + ->columnSpanFull() + ->schema([ + Forms\Components\ToggleButtons::make('unlimited_mem') + ->label('Memory')->inlineLabel()->inline() + ->afterStateUpdated(fn (Forms\Set $set) => $set('memory', 0)) + ->formatStateUsing(fn (Forms\Get $get) => $get('memory') == 0) + ->live() + ->options([ + true => 'Unlimited', + false => 'Limited', + ]) + ->colors([ + true => 'primary', + false => 'warning', + ]) + ->columnSpan(2), - Forms\Components\TextInput::make('memory') - ->dehydratedWhenHidden() - ->hidden(fn (Forms\Get $get) => $get('unlimited_mem')) - ->label('Memory Limit')->inlineLabel() - ->suffix('MiB') - ->required() - ->columnSpan(2) - ->numeric() - ->minValue(0), - ]), - - Forms\Components\Grid::make() - ->columns(4) - ->columnSpanFull() - ->schema([ - Forms\Components\ToggleButtons::make('unlimited_disk') - ->label('Disk Space')->inlineLabel()->inline() - ->live() - ->afterStateUpdated(fn (Forms\Set $set) => $set('disk', 0)) - ->formatStateUsing(fn (Forms\Get $get) => $get('disk') == 0) - ->options([ - true => 'Unlimited', - false => 'Limited', - ]) - ->colors([ - true => 'primary', - false => 'warning', - ]) - ->columnSpan(2), - - Forms\Components\TextInput::make('disk') - ->dehydratedWhenHidden() - ->hidden(fn (Forms\Get $get) => $get('unlimited_disk')) - ->label('Disk Space Limit')->inlineLabel() - ->suffix('MiB') - ->required() - ->columnSpan(2) - ->numeric() - ->minValue(0), - ]), - - Forms\Components\Grid::make() - ->columns(4) - ->columnSpanFull() - ->schema([ - Forms\Components\ToggleButtons::make('unlimited_cpu') - ->label('CPU')->inlineLabel()->inline() - ->afterStateUpdated(fn (Forms\Set $set) => $set('cpu', 0)) - ->formatStateUsing(fn (Forms\Get $get) => $get('cpu') == 0) - ->live() - ->options([ - true => 'Unlimited', - false => 'Limited', - ]) - ->colors([ - true => 'primary', - false => 'warning', - ]) - ->columnSpan(2), - - Forms\Components\TextInput::make('cpu') - ->dehydratedWhenHidden() - ->hidden(fn (Forms\Get $get) => $get('unlimited_cpu')) - ->label('CPU Limit')->inlineLabel() - ->suffix('%') - ->required() - ->columnSpan(2) - ->numeric() - ->minValue(0), - ]), - - Forms\Components\Grid::make() - ->columns(4) - ->columnSpanFull() - ->schema([ - Forms\Components\ToggleButtons::make('swap_support') - ->live() - ->label('Enable Swap Memory')->inlineLabel()->inline() - ->columnSpan(2) - ->afterStateUpdated(function ($state, Forms\Set $set) { - $value = match ($state) { - 'unlimited' => -1, - 'disabled' => 0, - 'limited' => 128, - }; - - $set('swap', $value); - }) - ->formatStateUsing(function (Forms\Get $get) { - return match (true) { - $get('swap') > 0 => 'limited', - $get('swap') == 0 => 'disabled', - $get('swap') < 0 => 'unlimited', - }; - }) - ->options([ - 'unlimited' => 'Unlimited', - 'limited' => 'Limited', - 'disabled' => 'Disabled', - ]) - ->colors([ - 'unlimited' => 'primary', - 'limited' => 'warning', - 'disabled' => 'danger', + Forms\Components\TextInput::make('memory') + ->dehydratedWhenHidden() + ->hidden(fn (Forms\Get $get) => $get('unlimited_mem')) + ->label('Memory Limit')->inlineLabel() + ->suffix('MiB') + ->required() + ->columnSpan(2) + ->numeric() + ->minValue(0), ]), - Forms\Components\TextInput::make('swap') - ->dehydratedWhenHidden() - ->hidden(fn (Forms\Get $get) => match ($get('swap_support')) { - 'disabled', 'unlimited', true => true, - 'limited', false => false, - }) - ->label('Swap Memory')->inlineLabel() - ->suffix('MiB') - ->minValue(-1) - ->columnSpan(2) - ->required() - ->integer(), - ]), + Forms\Components\Grid::make() + ->columns(4) + ->columnSpanFull() + ->schema([ + Forms\Components\ToggleButtons::make('unlimited_disk') + ->label('Disk Space')->inlineLabel()->inline() + ->live() + ->afterStateUpdated(fn (Forms\Set $set) => $set('disk', 0)) + ->formatStateUsing(fn (Forms\Get $get) => $get('disk') == 0) + ->options([ + true => 'Unlimited', + false => 'Limited', + ]) + ->colors([ + true => 'primary', + false => 'warning', + ]) + ->columnSpan(2), - Forms\Components\Hidden::make('io') - ->helperText('The IO performance relative to other running containers') - ->label('Block IO Proportion'), - - Forms\Components\Grid::make() - ->columns(4) - ->columnSpanFull() - ->schema([ - Forms\Components\ToggleButtons::make('oom_killer') - ->label('OOM Killer')->inlineLabel()->inline() - ->columnSpan(2) - ->options([ - false => 'Disabled', - true => 'Enabled', - ]) - ->colors([ - false => 'success', - true => 'danger', + Forms\Components\TextInput::make('disk') + ->dehydratedWhenHidden() + ->hidden(fn (Forms\Get $get) => $get('unlimited_disk')) + ->label('Disk Space Limit')->inlineLabel() + ->suffix('MiB') + ->required() + ->columnSpan(2) + ->numeric() + ->minValue(0), ]), - Forms\Components\TextInput::make('oom_disabled_hidden') - ->hidden(), + Forms\Components\Grid::make() + ->columns(4) + ->columnSpanFull() + ->schema([ + Forms\Components\ToggleButtons::make('unlimited_cpu') + ->label('CPU')->inlineLabel()->inline() + ->afterStateUpdated(fn (Forms\Set $set) => $set('cpu', 0)) + ->formatStateUsing(fn (Forms\Get $get) => $get('cpu') == 0) + ->live() + ->options([ + true => 'Unlimited', + false => 'Limited', + ]) + ->colors([ + true => 'primary', + false => 'warning', + ]) + ->columnSpan(2), + + Forms\Components\TextInput::make('cpu') + ->dehydratedWhenHidden() + ->hidden(fn (Forms\Get $get) => $get('unlimited_cpu')) + ->label('CPU Limit')->inlineLabel() + ->suffix('%') + ->required() + ->columnSpan(2) + ->numeric() + ->minValue(0), + ]), + + Forms\Components\Grid::make() + ->columns(4) + ->columnSpanFull() + ->schema([ + Forms\Components\ToggleButtons::make('swap_support') + ->live() + ->label('Enable Swap Memory')->inlineLabel()->inline() + ->columnSpan(2) + ->afterStateUpdated(function ($state, Forms\Set $set) { + $value = match ($state) { + 'unlimited' => -1, + 'disabled' => 0, + 'limited' => 128, + }; + + $set('swap', $value); + }) + ->formatStateUsing(function (Forms\Get $get) { + return match (true) { + $get('swap') > 0 => 'limited', + $get('swap') == 0 => 'disabled', + $get('swap') < 0 => 'unlimited', + }; + }) + ->options([ + 'unlimited' => 'Unlimited', + 'limited' => 'Limited', + 'disabled' => 'Disabled', + ]) + ->colors([ + 'unlimited' => 'primary', + 'limited' => 'warning', + 'disabled' => 'danger', + ]), + + Forms\Components\TextInput::make('swap') + ->dehydratedWhenHidden() + ->hidden(fn (Forms\Get $get) => match ($get('swap_support')) { + 'disabled', 'unlimited', true => true, + 'limited', false => false, + }) + ->label('Swap Memory')->inlineLabel() + ->suffix('MiB') + ->minValue(-1) + ->columnSpan(2) + ->required() + ->integer(), + ]), + + Forms\Components\Hidden::make('io') + ->helperText('The IO performance relative to other running containers') + ->label('Block IO Proportion'), + + Forms\Components\Grid::make() + ->columns(4) + ->columnSpanFull() + ->schema([ + Forms\Components\ToggleButtons::make('oom_killer') + ->label('OOM Killer')->inlineLabel()->inline() + ->columnSpan(2) + ->options([ + false => 'Disabled', + true => 'Enabled', + ]) + ->colors([ + false => 'success', + true => 'danger', + ]), + + Forms\Components\TextInput::make('oom_disabled_hidden') + ->hidden(), + ]), ]), - Forms\Components\Fieldset::make('Application Feature Limits') + Forms\Components\Fieldset::make('Feature Limits') ->inlineLabel() ->columnSpan([ 'default' => 2, @@ -501,6 +462,60 @@ class EditServer extends EditRecord ->required() ->numeric(), ]), + Forms\Components\Fieldset::make('Docker Settings') + ->columnSpan([ + 'default' => 2, + 'sm' => 4, + 'md' => 4, + 'lg' => 6, + ]) + ->columns([ + 'default' => 1, + 'sm' => 2, + 'md' => 3, + 'lg' => 3, + ]) + ->schema([ + Forms\Components\Select::make('select_image') + ->label('Image Name') + ->afterStateUpdated(fn (Forms\Set $set, $state) => $set('image', $state)) + ->options(function ($state, Forms\Get $get, Forms\Set $set) { + $egg = Egg::query()->find($get('egg_id')); + $images = $egg->docker_images ?? []; + + $currentImage = $get('image'); + if (!$currentImage && $images) { + $defaultImage = collect($images)->first(); + $set('image', $defaultImage); + $set('select_image', $defaultImage); + } + + return array_flip($images) + ['ghcr.io/custom-image' => 'Custom Image']; + }) + ->selectablePlaceholder(false) + ->columnSpan(1), + + Forms\Components\TextInput::make('image') + ->label('Image') + ->debounce(500) + ->afterStateUpdated(function ($state, Forms\Get $get, Forms\Set $set) { + $egg = Egg::query()->find($get('egg_id')); + $images = $egg->docker_images ?? []; + + if (in_array($state, $images)) { + $set('select_image', $state); + } else { + $set('select_image', 'ghcr.io/custom-image'); + } + }) + ->placeholder('Enter a custom Image') + ->columnSpan(1), + + Forms\Components\TagsInput::make('docker_labels') + ->label('Labels') + ->placeholder('Enter custom Docker container labels') + ->columnSpan(1), + ]), ]), ]); } From 859a721e17396470a57c94c78bd22377d9f8d50f Mon Sep 17 00:00:00 2001 From: notCharles Date: Sun, 19 May 2024 21:30:25 -0400 Subject: [PATCH 3/3] mysql vs sqlite... --- .../migrations/2024_05_20_002841_add_docker_container_label.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2024_05_20_002841_add_docker_container_label.php b/database/migrations/2024_05_20_002841_add_docker_container_label.php index eea5f02b4..f331e2ada 100644 --- a/database/migrations/2024_05_20_002841_add_docker_container_label.php +++ b/database/migrations/2024_05_20_002841_add_docker_container_label.php @@ -12,7 +12,7 @@ return new class extends Migration public function up(): void { Schema::table('servers', function (Blueprint $table) { - $table->text('docker_labels')->default('[]'); + $table->text('docker_labels')->nullable(); }); }